You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Dominik Bruhn <do...@dbruhn.de> on 2006/04/15 02:15:31 UTC

BBCode Parser

Hy,
I know its not a velocity-specific question, but perhaps someone knows a 
solution.

Perhaps you know BBCode: These is a Markup-Language used in 
Web-Bulletin-Boards like PHPBB or VBulletin. BB-Codes makes it possible to 
format the text by the user in easy ways while perserving the security for 
the administrators (no JavaScript, no IFrames, only permitted Tags). For 
example you get the String "[b]This is Bold [i] and this is italic and 
bold[/i][/b]". Now I need a piece of java which converts these Strings into 
HTML again, in case of this example to a string like "<b>This is Bold <i> and 
this is italic </i></b>". There are some difficult tags like 
[url="http://google.com"]Search Engine[/url] which should be converted to "<a 
href="http://google.com" target="_blank">Search Engine</a>".

I know you could realize this easily by using Regular-Expressions, but this is 
not enough: You have to check that every tag opened is closed again, 
otherwise you get ugly HTML or the User is able to format more than his code 
because there is no closing Tag.

I know the solution for these problems is to split up the string into a tree, 
then check it and merge the tree to the output-string again. Thats how the 
mentioned PHP-Boards do it. I could now realize this code in Java which costs 
me many time. Thats why I ask here: Is there someone who knows a 
BBCode-Parser written in Java?

Thanks
TO

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: BBCode Parser

Posted by shawn mcdermott <sg...@gmail.com>.
On 4/14/06, Dominik Bruhn <do...@dbruhn.de> wrote:
>
> Hy,
> I know its not a velocity-specific question, but perhaps someone knows a
> solution.
>
> Perhaps you know BBCode: These is a Markup-Language used in
> Web-Bulletin-Boards like PHPBB or VBulletin. BB-Codes makes it possible to
> format the text by the user in easy ways while perserving the security for
> the administrators (no JavaScript, no IFrames, only permitted Tags). For
> example you get the String "[b]This is Bold [i] and this is italic and
> bold[/i][/b]". Now I need a piece of java which converts these Strings
> into
> HTML again, in case of this example to a string like "<b>This is Bold <i>
> and
> this is italic </i></b>". There are some difficult tags like
> [url="http://google.com"]Search Engine[/url] which should be converted to
> "<a
> href="http://google.com" target="_blank">Search Engine</a>".
>
> I know you could realize this easily by using Regular-Expressions, but
> this is
> not enough: You have to check that every tag opened is closed again,
> otherwise you get ugly HTML or the User is able to format more than his
> code
> because there is no closing Tag.
>
> I know the solution for these problems is to split up the string into a
> tree,
> then check it and merge the tree to the output-string again. Thats how the
> mentioned PHP-Boards do it. I could now realize this code in Java which
> costs
> me many time. Thats why I ask here: Is there someone who knows a
> BBCode-Parser written in Java?
>
> Thanks
> TO


check
http://www.koders.com/java/fid026F81DAE7C88C51203F24179E95959F0DBA4E6D.aspx?s=ToTextRenderer

it is part of the jboss project.  may help.

--
Regards,
Shawn