Converting source code to XHTML
This is a tool I use for all my posts: a small JavaScript that converts source code to HTML. And I will use the code itself as demo.
The HTML elements
A textarea to paste the source code, a button to do the conversion and another textarea to gather the result is all we need:
<strong>Source</strong> <a href="#demo" onclick="Mme.demo();return false;">Demo</a>
<textarea id="source" rows="10" cols="60"></textarea>
<p class="buttons" style="margin-bottom:0"><button onclick="Mme.toHtml('source','result','preview')">Convert</button></p>
<strong>Result</strong>
<p><textarea id="result" rows="10" cols="60"></textarea></p>
<strong>Preview</strong>
<p class="code" id="preview"></p>
The demo
The code replaces all >, < and & with the escaped equivalents. Also, in order to preserve the newlines and indenting, it replaces tabs with non breaking spaces and newlines with 'br' tags.
Source Demo code Result PreviewI almost forgot the code behind this. If all went well, it's in the preview above this paragraph.
Comments
07/12/2006 23:42:12, Robin Wills
Great Blog Michel. I literally read it from start to finish. I find it slightly depressing how easy you seem to find it ;-) Keep up the good work. Rob.
13/12/2006 17:45:54, Michel Van der Meiren
Thanks. Often nice and simple solutions are only found after a lot of hard work and frustration. I should stress this more. But I want to proove with this blog that programming web applications with Domino is well worth wile and a lot of fun :-)
To add a comment, log in or register as new user. It's free and safe.