Skip to main content


Showing posts from April, 2016

Escaping code to be displayed in HTML/XHTML

One of the most tedious things about blogging about Software Development is escaping your code so it can be displayed on your blog. This is especially true when it comes to XHTML (Blogger) as the parser might throw an exception and not display any of the page. One solution is to surround the code with <pre></pre> tags to alert the parser that the code is pre-formatted. However, this alone isn't simply enough especially when it comes to XHTML. So are we left to manually go through the code and escape every character that needs to be? No, I've developed a script that will handle this task.

What does it mean to escape a character?     There are certain characters that cannot be used in an HTML/XHTML document as they already have a distinct purpose. For instance, the less than (<) and greater than (>) symbols are used to denote the start and end of a tag respectively (<body>). Therefore when we use them within our text, the parser believes they are the…