tags:

views:

288

answers:

3

I use the <pre> tag in my blog to post code. I know I have to change < to &lt; and > to &gt;. 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
+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
Thanks. What is the semantic purpose of <pre>?
mangledorf
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
+1  A: 

Using the pre tag you don't have to escape anything.

Corehpf
@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