I have a page with some very basic examples that use HTML/CSS/JavaScript. I’d like to be able to post the code for these examples as text on my website. I’ve tried using the the pre and code elements to wrap the block of text that represents the code.
Here is the site: https://mywebspace.wisc.edu/jkinzel/examples/
The last small problem is that in certain instances, the < and > are being encoded as > and <. You see in the second example’s code (under the JavaScript and CSS headings) that this is case, but only on certain occasions. Other times they are properly displayed as < and > (which is what I want).
Anyone have any ideas as to why this happens sometimes and not others?
From my comment above:
It’s a result of the text being encoded twice; that is, it’s encoded once to turn the < and > characters into HTML entities, and then those are encoded again, which makes them stop working. That is,
<turns into&lt;when it’s encoded twice.More detail: The most important characters to encode in order to show HTML as it looks in source form are “<” and “&”; generally people encode “>” too, though usually it’s not a problem. (Actually, “&” by itself is also usually not a problem, but whatever.) HTML entities look like “&foo;”, where “foo” is some key. Thus, when you encode text, you end up with “&foo;” all over the place. When you encode again, the “&” at the beginning of those little strings is re-encoded as “&”.