Reputation: 1258
I am trying to write a programming tutorial for the C programming language. I want to show a code example that imports. I have used the <code>
tag to denote code, however HTML treats the import statements in the code itself as tags due to the <> characters.
HTML Fragment
<code>
#include <stdlib.h>
#include <stdio.h>
</code>
Image From Editor
Upvotes: 0
Views: 75
Reputation: 13739
HTML is only one version available, there is XML. Why is this important? If you're writing a tutorial write it with the highest accuracy first. You can easily degrade XML down to HTML without problems however the vast majority of instances HTML can not be upgraded to XML without numerous fixes.
There are two separate parsers for HTML and XML. One could say that the XML parser is much stricter however that would imply that HTML parsers are strict in any sense.
Do not use named entities, they break XML parsers.
"But XML is not HTML5!"
HTML and XML have parsers and standards. I've written an entire platform that utilizes the XML parsers of browsers and exceeds HTML5 standards. Using the HTML parser one will not be aware of issues like missing quotes on attributes. I witnessed someone lose three days trying to determine why Safari would not render part of a page correctly. Had they used the XML parser they could have recovered and remained productive in less than a minute!
&
<
>
Keep in mind that browsers are not worth testing, rendering engines are worth testing.
Upvotes: 0
Reputation: 3241
Wrapping any code inside <code>
or <pre>
doesn't prevent the Browser from reading the angle brackets. You'll need to escape them with HTML Entities:
<code>
#include <stdlib.h>
<br>
#include <stdio.h>
</code>
Note: There's an obsolete <xmp>
element that automatically renders the contents without interpreting as HTML. It's not advisable to use it because Browser support is not guaranteed.
Upvotes: 0
Reputation: 2552
You will need to use the HTML character entities, for example >
for >
and <
for <
. Here is a reference chart for most of them: https://dev.w3.org/html5/html-author/charref
Upvotes: 1