< has special meaning in markdown?

前端 未结 1 1135
北海茫月
北海茫月 2021-01-24 06:09

tmp.md:

Choices for blank 91:       __A__:  pa>pb      __B__:  papb

Choices for blank 92:       __A__:  pa<         


        
相关标签:
1条回答
  • 2021-01-24 06:39

    As the rules state:

    For any markup that is not covered by Markdown’s syntax, you simply use HTML itself. There’s no need to preface it or delimit it to indicate that you’re switching from Markdown to HTML; you just use the tags.

    Therefore, Markdown passes < and > through unaltered. However, as those characters are HTML tag deliminators, your browser will interpret anything between a < and a > as an HTML tag and it will not display it. Of course, if you never open a tag (with <), then a closing tag (>) will be ignored by the browser. Therefore, when using a < as a plain text character, it is best to use the HTML entity to ensure the browser sees it as such: &lt; (hint: Less Than => &lt; => <)

    So, to use your example input:

    Choices for blank 91:       __A__:  pa>pb      __B__:  pa&lt;pb      __C__: pa==pb      __D__: pa&lt;>pb
    
    Choices for blank 92:       __A__:  pa&lt;>pb      __B__:  pa&lt;pb      __C__:  pa>pb      __D__: pa==pb
    

    The output would look like this:

    Choices for blank 91: A: pa>pb B: pa<pb C: pa==pb D: pa<>pb

    Choices for blank 92: A: pa<>pb B: pa<pb C: pa>pb D: pa==pb

    Note that this is the behavior of your browser. There is nothing Markdown could do to change that unless it did not allow/support using raw HTML within Markdown documents.

    Of course, typing &lt; each time you want a < character is less than ideal. Generally, text which contains such characters could be classified as "code". Therefore it is usually best to just wrap it in a code span (when it is embedded in text) or a code block (when all the code consists of a block of one or more lines).

    For example, this paragraph contains `<>` characters.
    

    The above Markdown will result in the following HTML being generated:

    <p>For example, this paragraph contains <code>&lt;&gt;</code> characters.</p>
    

    Notice that the angle brackets were converted to &lt;&gt; for you (and wrapped in <code> tags). And the browser will render that as:

    For example, this paragraph contains <> characters.

    0 讨论(0)
提交回复
热议问题