Tags: beefsack.com
beefsack on 2009-05-07 04:03:45
I spent this morning writing a simple parser for BBCode style tags on beefsack.com. The reason for this is I wanted to add the ability to post monospace properly formatted code in my blog posts, and wanted to do it without writing a Dojo Editor plugin which wouldn't be flexible enough for me.
I found some great proposed components on the way for Zend, being Zend_Markup which seems to be maturing well, and Zend_Syntax_Highlight, which unfortunately hasn't been updated for a while.
Zend_Markup is meant to "provide an extensible way to tokenize and render lightweight markup languages, like BBcode and Textile." Ideally, I would want my Dojo Editor box to output BBCode instead of HTML, and have a parser convert it as needed. This would be particularly handy for me when I write the forums for this site as I want to use BBCode for that as is the standard for most forums around.
I noticed in the code for Zend_Markup they seem to use the PHP function highlight_string if it is passed PHP as a lang attribute. I feel that if a component like Zend_Syntax_Highlight was completed, it could make Zend_Markup very powerful on coding related sites and forums, being able to pass different lang attributes depending on the code that is inside the lang tags. Anyway, I've written a simple parser to detect BBCode style code tags so I'm able to post code on the blog. Here's what it looks like:
I found some great proposed components on the way for Zend, being Zend_Markup which seems to be maturing well, and Zend_Syntax_Highlight, which unfortunately hasn't been updated for a while.
Zend_Markup is meant to "provide an extensible way to tokenize and render lightweight markup languages, like BBcode and Textile." Ideally, I would want my Dojo Editor box to output BBCode instead of HTML, and have a parser convert it as needed. This would be particularly handy for me when I write the forums for this site as I want to use BBCode for that as is the standard for most forums around.
I noticed in the code for Zend_Markup they seem to use the PHP function highlight_string if it is passed PHP as a lang attribute. I feel that if a component like Zend_Syntax_Highlight was completed, it could make Zend_Markup very powerful on coding related sites and forums, being able to pass different lang attributes depending on the code that is inside the lang tags. Anyway, I've written a simple parser to detect BBCode style code tags so I'm able to post code on the blog. Here's what it looks like:
<?php
function thisIsAFunction() {
for ($i = 1; $i < 10; $i++) {
echo "Something $i";
}
}
?>
Which will work in the meantime until Zend_Markup is in an official release.