It seems displaying code on the web involves:
- Encoding HTML entities
- Formatting
A most basic workflow would thus seemingly be:
Have a code snippet such as:
<html> I'm a full page html snippet <html>
.Encode it (using one of the many sites found by google) to e.g.:
<html> I'm a full page html snippet </html>
Add it to the pages html such as follows:
<code><pre> <html> I'm a full page html snippet </html> </pre></code>
While this works, it is extremely manual, and loses WYSIWYG for me the author when I'm writing code snippets.
(EDITED for clarity:)
What I would simply like is something like this:
<body>
<encodedhtml (src="")>
I come from somewhere sensible: Inline or a seperate file. All my <, >, ", ', chars are displayed. I am raw html.
<encodedhtml>
</body>
Additional notes:
- I think ERB would work, but I'm using Node & Angular - I'd rather not.
- Jade is far to much of a deviation from normal html for my purposes (to heavyweight), I can't find a node templating engine that isn't. Also have to be careful angular and a templating engine syntax wouldn't clash (as with Handlebars).
- I could use angular/javascript to pull in the snippets with ajax from the server side, and inject them in the DOM but this just seems wrong. Am I wrong?
- This post sort of half explains why javascript without ajax is not going to work.
- I hear rumours of using
<script>
or<textarea>
tags, but I also read you can't syntax highlight a textarea tag. Could I put it in the HTML, hide it, then get it's content with javascript and re-display it? Is that too messy? I can't find examples. - Highlightjs and Code-Prettify both take encoded HTML: This seems to be the pattern with syntax highlighters for fundemental reasons.