|
PreAndTextarea
Technical details about <pre> and <textarea>.
Technical details about <pre> and <textarea>Problem descriptionThe fundamental problem with using <pre> is inability to easily copy and paste code into it. In particular this applies to XML/HTML. The problem with <pre> is that browsers parse HTML inside it where as in <textarea> they do not. For example: <pre><b>Hello</b></pre> Will render as Hello, where as <textarea><b>Hello</b></textarea> will render as <b>Hello</b>. If you try to get HTML from <pre> using innerHTML property, it's not going to look anything like what you have originally in the HTML file. With <textarea> however, a property value would return your HTML exactly the same way as you have provided it. ConclusionThis brings me to the final point. With <textarea> you can copy and paste source code without any alterations. With <pre> you have to make sure your source code won't be recognized as HTML, which means you have to replace every opening triangular bracket < with it's HTML encoded version <. This is enough to make <pre> work fine. |

Is there any way to embed HTML that should be parsed inside a <pre> tag that gets altered with syntaxHighlighter? Specifically, I'd like to embed span tags that mark up newly added code to highlight the difference between two code blocks, but syntaxHighlighter is matching the class attribute and making the literal HTML render. Thanks!
You also need to replace & with & for XML/XHTML compatibility. Escaping " -> " is also good.
Ciao!
Since pre is the only way to go if you want the code to be somewhat readable in various rss-feed tools (I tested with Bloglines) I made a little javascript "widget" for these replacements to take place. I made a blogpost about it on my blog at http://deapondotnet.blogspot.com/2008/05/lite-fix-med-syntaxhighlighter.htmlhttp://deapondotnet.blogspot.com. It's in swedish but I think you'll get the idea from the code i published. Feel free to use it.
Oh, here is a link directly to the blogpost: http://deapondotnet.blogspot.com/2008/05/lite-fix-med-syntaxhighlighter.html
Also note that if you use <textarea> then it won't come through to your RSS reader