BBCode Python Module II
It’s good to see a few people using my BBCode module. I have since made some small fixes and added a feature. I’ve added a PygmentsCodeTag that uses the excellent Pygments module to syntax highlight code within a [code][/code] tag. It supports all the languages that Pygments supports, simply specify the language in the tag (i.e. [code python][/code]). You can still use the code tag that generates <pre></pre>, if you have another syntax highlighting solution.
I have also simplified usage a little. Previously you had to add tags individually to the markup object, which was only a cut and paste from the sample code - but I don’t like boiler-plate code when it can be moved to a function. So I added a Create function that creates a markup object with all the tags. Here’s an example of how to use it, see the code for details.
import postmarkup markup = postmarkup.Create() bbcode = "[b] Hello, World! [/b]" print markup.render_to_html(bbcode)
Being a lazy programmer I also implemented the __call__ function in the postmarkup object and had it call render_to_html, so the last line can be written as print markup(bbcode).
Something I forgot to mention in the earlier post is that in addition to this form [url http://www.willmcgugan.com], postmarkup also supports the more usual BBCode syntax of [url="http://www.willmcgugan.com"]. I prefer the former, because it’s easier to type and I think it looks better.
You can download postmarkup.zip from the usual place. The zip also contains code.css, which you will need if you use the Pygments code tag. I will eventualy put this and my other Python projects on Sourceforge or Google code when I have the time. But I’ve got another more urgent project I’ll be working on.
May 26th, 2007 at 5:55 pm
Cool module.
Why do you have 2 different “wiki” tags, though? Is there any way you can select either? It seems to me like the reference.com takes presence over wikipedia’s.
May 26th, 2007 at 6:06 pm
Oh, also, can you add an [img]-tag?
May 27th, 2007 at 1:51 pm
Module doesn’t deal well with unicode. If you do a [google Jesper Nøhr]google[/google], it will croak. urllib.quote_plus dies on trying to quote the ‘ø’.
The fix is to explicitly cast the ’search’-var to a string;
return link % quote_plus(str(search)) # On line 273
May 31st, 2007 at 11:09 pm
There’s a new version with these issues fixed. :-)
October 2nd, 2007 at 9:17 pm
Nice work on this — I think we’re going to put this into use to save some dev time of our own :)
October 2nd, 2007 at 10:45 pm
Glad you like it!
The latest version is on Google code:
http://code.google.com/p/postmarkup/
November 29th, 2007 at 8:10 pm
Really nice. Thank you.
Found a little bug though: If you input a single “[” it throws an error.
In my case it broke when somebody used the smilie “:-[”.
November 29th, 2007 at 10:17 pm
Thanks for the bug report. I’ve checked in a fix to SVN. I’ll release a new version soon.