jss367
jss367

Reputation: 5381

How do I type html in a markdown file without it rendering?

I want to type the following sentence in a markdown file: she says <h1> is large. I can do it in StackOverflow with three backticks around h1, but this doesn't work for a .md file. I've also tried a single backtick, single quote, double quote, hashtags, spacing, <code>h1</code> and everything else I could think of. Is there a way to do this?

Upvotes: 31

Views: 16936

Answers (3)

Hrishikesh Kadam
Hrishikesh Kadam

Reputation: 37332

A backslash (\) can be used to escape < and >.

Ex: she says <h1> is large

P.S. See this answer's source by clicking Edit.

Upvotes: 5

nkconnor
nkconnor

Reputation: 682

Generally, you can surround the code in single backticks to automatically escape the characters. Otherwise just use the HTML escapes for < &lt;and > &gt;.

i.e.

she says &lt;h1&gt; is large or she says `<h1>` is large

Upvotes: 17

Haldean Brown
Haldean Brown

Reputation: 12711

You can escape the < characters by replacing them with &lt;, which is the HTML escape sequence for <. You're sentence would then be:

she says &lt;h1> is large

As a side note, the original Markdown "spec" has the following to say:

However, inside Markdown code spans and blocks, angle brackets and ampersands are always encoded automatically. This makes it easy to use Markdown to write about HTML code. (As opposed to raw HTML, which is a terrible format for writing about HTML syntax, because every single < and & in your example code needs to be escaped.)

...which means that, if you're still getting tags when putting them in backticks, whatever renderer you're using isn't "compliant" (to the extent that one can be compliant with that document), and you might want to file a bug.

Upvotes: 30

Related Questions