Examples of displaying sample code
When putting sample code on an HTML page, there are several ways to
do it. There are pros and cons to each approach. That the method
supports markup could be a pro or a con depending on whether you
want to mark up your code, or show the markup itself. (eg. I want to
show <b>bold</b> and not bold, or vice versa.)
- Pros: supported
- Cons: Spaces are not preserved. others cons, see the code
Here is some code.
Line break and spacing must be coded. with <br />. < less than. & ampersand are escaped.
Anything that looks like a <tag> must be escaped.
Tags are rendered.
- pros: line breaks and spaces are preserved
- cons: see the first paragraph about showing markup.
Code using PRE needs escaped < > &
line breaks and spacing are preserved. I can still escape </pre>
Pre still marks up tags
with xmp, I can put anything including < & and >.
Line breaks and spacing are preserved.
tags are not rendered.
& entities are not recognized.
The only thing I cannot type or display is
- Pros: everything (except </xmp>) is copied verbatim with
no escaping of anything.
- cons: officially not supported, but de-facto completely supported.
- Pros: line breaks and spaces are preserved. Entities may or
may not be preserved.
- cons: a normal refresh will not change the contents of the
textarea box when the source is updated.