RuBB

BBCode gem for Ruby.

RuBB parses BBCode by generating a parse tree, so it is able to handle nested BBCode tags properly.

Install

gem install rubb

Usage

RuBB.to_html('[b]hello[/b]')

'[b]hello[/b]'.bb_to_html

BBCode Tags

RuBB supports the following BBCode tags:

[h1]text/[/h1] => <h1>text</h1>
[h2]text/[/h2] => <h2>text</h2>
[h3]text/[/h3] => <h3>text</h3>
[h4]text/[/h4] => <h4>text</h4>
[h5]text/[/h5] => <h5>text</h5>
[h6]text/[/h6] => <h6>text</h6>

[b]text[/b] => <strong>text</strong>
[i]text[/i] => <em>text</em>
[u]text[/u] => <ins>text</ins>
[s]text[/s] => <del>text</del>

[size=10]text[/size]        => <span style="font-size: 10px;">text</span>
[color=#ff0000]text[/color] => <span style="color: #ff0000;">text</span>

[left]text[/left]     => <div style="text-align: left;">text</div>
[center]text[/center] => <div style="text-align: center;">text</div>
[right]text[/right]   => <div style="text-align: right;">text</div>

[quote]text[/quote]         => <blockquote><p>text</p></blockquote>
[quote=someone]text[/quote] => <blockquote><dl><dt>someone</dt><dd><p>text</p></dd></dl></blockquote>

[url]http://github.com/petejkim/rubb/[/url]      => <a href="http://github.com/petejkim/rubb/">http://github.com/petejkim/rubb/</a>
[url=http://github.com/petejkim/rubb/]RuBB[/url] => <a href="http://github.com/petejkim/rubb/">RuBB</a>

[email][email protected][/email]            => <a href="mailto:[email protected]">[email protected]</a>
[[email protected]]Test Email[/email] => <a href="mailto:[email protected]">Test Email</a>

[img]http://test.com/test.jpg[/img]         => <img src="http://test.com/test.jpg" alt="" />
[img=640x480]http://test.com/test.jpg[/img] => <img src="http://test.com/test.jpg" style="width: 640px; height: 480px;" alt="" />

[ul][li]text[/li][/ul] => <ul><li>text</li></ul>
[ol][li]text[/li][/ol] => <ol><li>text</li></ol>

[code]text[/code] => <pre>text</pre>

[table][tr][th]text[/th][/tr][tr][td]text[/td][/tr][/table] => <table><tr><th>text</th></tr><tr><td>text</td></tr></table>

Copyright © 2010 Peter Jihoon Kim. See LICENSE for details.