1.0.2 • Published 8 years ago

epochtalk-bbcode-parser v1.0.2

Weekly downloads
52
License
ISC
Repository
github
Last release
8 years ago

bbcode-parser

Epochtalk BBCode Parser built specifically for Bitcointalk's BBCode (SMF Based)

This is based on the work of:
Extendible BBCode Parser v1.0.0
By Patrick Gillespie (patorjk@gmail.com)
Website: http://patorjk.com/

This is a bbcode parser that has been specifically built to read and parse the BBCode tags that come from the bitcointalk forum. Their BBCode is based off of SMF BBCode but with some modifications. It has also been modified to be used as a node module rather than a browser based library. It has also been further modified so that styles can be properly parsed by AngularJS.

The parsed output is, for the most part, standard HTML with a few changes to allow the HTML to be properly parsed by AngularJS using the custom style-fix directive. Since all style attributes are stripped out by AngularJS, special 'bbcode-' prefixed classes have been added to all HTML tags that also have style attributes. These prefix classes are used as 'style hints' for the style-fix directive which turn the prefixed classes into an ng-style attribute.

Parsing example

[color=red]test[/color]

is parsed to:

<span class="bbcode-color-red" style="color:red">test</span>

which the style-fix directive parses into:

<span ng-style="{ 'color': 'red' }">test</span>

The final result being (after AngularJS compiles and parses this):

<span ng-style="{ 'color': 'red' }" style="color:red">test</span>

Special attention has been given to ensure that any input is properly escaped and sanitized by both the BBCode parser, then the style-fix directive, and finally by AngularJS (ng-style) itself before being shown to the user.

Attention to Time:

All time/date output has been modified so that the unix time is what is placed in the output. It has also been prefixed with 'ept-date=' so that the auto-date directive can find the time/date and display it as local time.

For Example:

[time]1234567900[/time]

is parsed to:

ept-date=1234567900

which the auto-date directive parses into:

January 14, 1970, 8:56:07 PM

Tags Not Supported:

BBCode TagNotes
fontWon't even be parsed

Tags Supported:

BBCode TagParsed ResultNotes
anchor={text}<span id="post_{text}"><span>Anchor will appear as "post_{text}"
abbr={text}<abbr title={text}></abbr>
acronym={text}<acronym title={text}></acronym>
b<b></b>
bbcodeThis is a noop
black<span class="bbcode-color-black" style="color: black;"></span>
blue<span class="bbcode-color-blue" style="color: blue;"></span>
br<br />Closing tag is required
btc<span class="BTC">BTC</span>
center<div align="center"></div>
code<code></code>
color={XXXXXX}<span class="bbcode-color-{XXXXXX}" style="color: {XXXXXX}"></span>RGB value
color={#XXXXXX}<span class="bbcode-color-{_XXXXXX}" style="color: {#XXXXXX}"></span>RGB Value with #
color={Color Name}<span class="bbcode-color-{Color Name}" style="color: {Color Name}"></span>Color Names allowed shown below
email={Email Address}<a href="mailto: {Email Address}" target="_blank"></a>
email{email}/email<a href="mailto: {Email Address}" target="_blank"></a>
ftp={FTP URL}<a href="{FTP URL}" target="_blank"></a>
ftp{FTP URL}/ftp<a href="{FTP URL}" target="_blank"></a>
glow={XXXXXX}<span class="bbcode-bgcolor-{XXXXXX}" style="background-color:{XXXXXX}"></span>
glow={#XXXXXX}<span class="bbcode-bgcolor-{#XXXXXX}" style="background-color:{#XXXXXX}"></span>
glow={Color Name}<span class="bbcode-bgcolor-{Color Name}" style="background-color:{Color Name}"></span>Color Names allowed shown below
green<span class="bbcode-color-green" style="color: green;"></span>
hr<hr />Closing tag is required
htmlThis is a noop
i<i></i>
img alt={String} width={Number} height={Number} {URL} /img<img src="{URL}" alt={String} width={Number} height={Number}></img>alt, width, and height are all optional
iurl={URL}<a href="{URL}" />{URL} is always link text, 1
iurl{URL}/iurl<a href="{URL}" />{URL} is always link text, 1
left<div class="bbcode-text-left" style="text-align: left;"></div>
li<li></li>parent can only be list, ol, ul
list {List Type}<ul class="bbcode-list-{List Type}" style="list-style-type:{List Type}"></ul>List Type is optional, List Types allowed shown below, children can only be li
ltr<div dir="ltr"></div>
me={author}<div class="bbcode-color-red" style="color: red;">* {author} </div>
move<div></div>deprecated tag, does nothing
noparsedoes not parse inner contents
nobbcdoes not parse inner contents
ol<ol></ol>children can only be li
pre<pre></pre>
php<pre></pre>not really useful anymore
quote<div class="quoteHeader">Quote</div><div class="quote"></div>
quote={author}<div class="quoteHeader">Quote From: {author}</div><div class="quote"></div>
quote author={author}<div class="quoteHeader">Quote From: {author}</div><div class="quote"></div>
quote author={author} link={link} date={Number}<div class="quoteHeader"><a href="{link}">Quote from: {author} on ept-date={Number}</a></div><div class="quote"></div>{Number} as milliseconds from epoch
right<div class="bbcode-text-right" style="text-align: right;"></span>
red<span class="bbcode-color-red" style="color: red;"></span>
rtl<div dir="rtl"></div>
s<del></del>
shadow={color},{direction},{blur}<span class="bbcode-shadow-{color}{direction}{blur}" style="text-shadow: {color}{direction}{blur}"></span>2 check bottom of grid
size={size}<span class="bbcode-size-{size}" style="font-size:{size} !important; line-height: 1.3em;"></span>3 check bottom of grid
spoiler<span class="spoiler"></span>
sub<sub></sub>
sup<sup></sup>
tt<tt></tt>
time{time}/timeept-date={time}4 check bottom of grid
table<table></table>Children can only be tbody, thead, tfoot, tr
tbody<tbody></tbody>Parent can only be table, children can only be tr
thead<thead></thead>Parent can only be table, children can only be tr
tfoot<tfoot></tfoot>Parent can only be table, children can only be tr
td<td valign="top"></td>Parent can only be tr
th<th></th>Parent can only be tr
tr<tr></tr>Parent can only be table, tbody, tfoot, thead. Children can only be td, th
u<u></u>
ul<ul></ul>Children can only be li
url={URL}{content}/url<a href="{URL}" target="_blank"></a>{content} is link text
url{URL}/url<a href="{URL}" target="_blank"></a>{URL} is always link text
white<span class="bbcode-color-white" style="color: white;">

1: Meant for urls that stay within the domain and thus will not open the link in another tab.
2: color and direction are required but blur is optional. {color} is treated the same way as in the color. {direction} can be represented as either 'left, right, top, bottom' or as a number. {blur} must be a number
3: {size} can be either an number followed by either px or pt. Or it can be one of the following: smaller, small, large, larger, x-large, x-larger
4: {time} can be either a number (milliseconds since epoch), or a datetime string that can be parsed by JavaScript's Date object.

Color Names supported for the above color based tags

Color Names
redgreenblueorange
yellowpinkblackwhite
beigebrowngreygray
silverpurplemaroonlime
limegreenolivenavyteal
aqua

List Types supported for the above list tag

List Types
nonedisccirclesquare
decimaldecimal-leading-zerolower-romanupper-roman
lower-alphaupper-alphalower-greeklower-latin
upper-latinhebrewarmeniangeorgian
cjk-ideographichiraganakatakanahiragana-iroha
katakana-iroha
1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

9 years ago