Recent Topics

1 May 30, 2006 23:02    

Hi, I need to add some code snippets into my blog, something like..

if ( num <= 10 ) { }

but the < cancels out the code tags and I get this error:

Parser error: not well-formed (invalid token) near if ( num < = 10 ) { }</code></

How can I use this?

Thanks

2 May 31, 2006 08:00

Unfortunately, the <code> tag (besides designating - correctly - that what follows is "code") does nothing, in and of itself, in XHTML.

The problem is that the program (b2evolution) sees the "<" and thinks to itself ... "aha ... a tag is coming up" and tries to do whatever is in the tag.

IF you want to display a code snippet (as text) in your blog and not have the program try to INTERPRET it, then you need to convert certain characters (>, <, namely) to entity values.

"<" should be written as &lt;
">" should be writeen as &gt;

For your example, your code snippet (in the post) should look like:

if ( num &lt;= 10 ) { }

, which the html-checker should then "pass", without difficulty.

Hope this helps.

Note: A tool I used to use to convert snippets of code to display-ready code, can be found at Dan Cederholm's site ... it's called [url=http://www.simplebits.com/cgi-bin/simplecode.pl]SimpleCode[/url] ... just paste in your bits of code you want to display, hit "process" and it spits out converted, display-ready code, inside of <code> tags.

3 Jun 01, 2006 00:20

stk wrote:

Note: A tool I used to use to convert snippets of code to display-ready code, can be found at Dan Cederholm's site ... it's called [url=http://www.simplebits.com/cgi-bin/simplecode.pl]SimpleCode[/url] ... just paste in your bits of code you want to display, hit "process" and it spits out converted, display-ready code, inside of <code> tags.

Hey cool! That's the code I tweaked into my hackin* so long ago. The site used to be html & javascript, and disappeared for the longest time. The only reason I had it was because I snagged a local copy. Nice to see it's back online!

Oh and you don't really need to make >s be &gt;s because b2evo, as you pointed out, only gets excited when it thinks a tag is about to open. Also if you're pasting in code with a blank line you'll need to put a &nbsp; on it so the formatting you apply to the <code> tag will jump the gap. I've no idea why that it. It just is.

--------------------

* hackin: a freshly minted word to identify a plugin that required hacking. For example everything everyone ever did for every version prior to 1.6 ;)


Form is loading...