I use the <pre> tag in my blog to post code. I know I have to change < to < and > to >. Are any other characters I need to escape for correct html?
+1
A:
< and > are the only characters that must be escaped. All others are allowed.
John Millikin
2009-08-13 16:38:54
+2
A:
For posting code within your markup, I suggest using the <code> tag. It works the same way as pre but would be considered semantically correct.
Otherwise, <code> and <pre> only need the angle brackets encoded.
JMP
2009-08-13 16:42:00
Thanks. What is the semantic purpose of <pre>?
mangledorf
2009-08-13 17:00:24
The original intent of pre was to grant space within the markup to preserve characters that otherwise wouldn't display (ie: tabs, line breaks, multiple spaces, etc) on a non-editable surface (you could do the same with textarea, but textarea can be edited).Also, there were times in the old days that tabular data would be displayed using pre.
JMP
2009-08-13 17:18:41
@Corehpf: You may mean something different when you say *you don't have to escape anything*. But when I tested `<pre><span style="color:Red;">Test</span></pre>`, it displayed the word 'Test' in red. I think the intent was to display the literal string `<span style="color:Red;">Test</span>`. That can be achieved by *escaping* the left angle bracket on the enclosed markup: `<span style="color:Red;">Test</span>`
Grant Wagner
2009-08-13 21:35:00