Text_Highlighter - a small bug and two more renderers
| From: | Stoyan Stefanov | Date: | Sat, 30 Apr 2005 05:29:41 +0000 |
| Subject: | Text_Highlighter - a small bug and two more renderers | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-37457@lists.php.net to get a copy of this message | ||
Hi guys, Andrey,
First off, thanks for the great highlighter package!
At this SitePoint article
(http://www.sitepoint.com/article/highlight-source-code-php) I joke
about new future renderers and iPod being a supported renderer, so it
got me thinking. "iPod notes" support some basic HTML tags - b, i, u
and a. So I wrote a new HTML renderer that works with basic html tags
and not <span>+ styles like the existing renderer. So somebody can
highlight some code, copy it as one or more iPod notes and read it
while travelling and listening to ... hmm ... "How to dismantle an
atomic bomb" :)
The other thing is that I have some sort of a BB-code passion, so I
wrote another renderer that can produce code highlighted as BB code so
it can be pasted in forums and such. For example
[color=Blue]array[/color] and so on.
Here are the two renderers, let me know what you think:
http://www.w3clubs.com/Text_Highlighter/BB.php
http://www.w3clubs.com/Text_Highlighter/HTMLTags.php
Maybe they can be added to the package.
I found a small bug while working on this and it's that preprocess()
methods in the renderers are never called, so for example the
'tabsize' options are never respected. My guess is that the best place
to call preprocess() will be in the Text_Highlighter::highlight()
method, like:
function highlight($str)
{
......
$this->_renderer->reset();
$this->_str = $this->_renderer->preprocess($str);
while ($token = $this->_getToken()) {
$this->_renderer->acceptToken($token[0], $token[1]);
}
$this->_renderer->finalize();
return $this->_renderer->getOutput();
}
Kind regards,
Stoyan
p.s. I'll make sure I post the bug in the bugtracker when I have a
chance (and it's not fixed by then ;) )