BBCode parser for Node written for Epochtalk. Based on SMF's flavor of BBCode.
npm install epochtalk-bbcode-parserbbcode-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.
[color=red]test[/color]
`
is parsed to:
` HTML
test
`
which the style-fix directive parses into:
`
test
`
The final result being (after AngularJS compiles and parses this):
`
test
`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.
$3
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 Tag|Notes
----------|-----
[font][/font]|Won't even be parsedTags Supported:
BBCode Tag|Parsed Result|Notes
----------|-------------|-----
[anchor={text}][/anchor]| `` | _Anchor will appear as_ "post_{text}"
[abbr={text}][/abbr]|``|
[acronym={text}][/acronym]|``|
[b][/b]|``|
[bbcode][/bbcode]| | This is a noop
[black][/black]|``|
[blue][/blue]|``|
[br][/br]| `
`|Closing tag is required
[btc][/btc]|`BTC`|
[center][/center]|``|
[code][/code]|``|
[color={XXXXXX}][/color]|``| RGB value
[color={#XXXXXX}][/color]|``|RGB Value with #
[color={Color Name}][/color]|``|Color Names allowed shown below
[email={Email Address}][/email]|``|
[email]{email}[/email]|``|
[ftp={FTP URL}][/ftp]|``|
[ftp]{FTP URL}[/ftp]|``|
[glow={XXXXXX}][/glow]|``|
[glow={#XXXXXX}][/glow]|``|
[glow={Color Name}][/glow]|``|Color Names allowed shown below
[green][/green]|``|
[hr][/hr]|`
`|Closing tag is required
[html][/html]||This is a noop
[i][/i]|``|
[img alt={String} width={Number} height={Number}] {URL} [/img]|`
`|_alt, width, and height are all optional_
[iurl={URL}][/iurl]|``|{URL} is always link text, [1]
[iurl]{URL}[/iurl]|``|{URL} is always link text, [1]
[left][/left]|``|
[li][/li]|``|_parent can only be [list], [ol], [ul]_
[list {List Type}][/list]|`
`|_List Type is optional_, List Types allowed shown below, children can only be [li]
[ltr][/ltr]|``|
[me={author}][/me]|`* {author} `|
[move][/move]|``|deprecated tag, does nothing
[noparse][/noparse]||_does not parse inner contents_
[nobbc][/nobbc]||_does not parse inner contents_
[ol][/ol]|`
`|children can only be [li]
[pre][/pre]|``|
[php][/php]|``|not really useful anymore
[quote][/quote]|`Quote`|
[quote={author}][/quote]|`Quote From: {author}`|
[quote author={author}][/quote]|`Quote From: {author}`|
[quote author={author} link={link} date={Number}][/quote]|``| {Number} as milliseconds from epoch
[right][/right]|``|
[red][/red]|``|
[rtl][/rtl]|``|
[s][/s]|``|
[shadow={color},{direction},{blur}][/shadow]|``| [2] check bottom of grid
[size={size}][/size]|``| [3] check bottom of grid
[spoiler][/spoiler]|``|
[sub][/sub]|``|
[sup][/sup]|``|
[tt][/tt]|``|
[time]{time}[/time]|`ept-date={time}`|[4] check bottom of grid
[table][/table]|`
`|Children can only be tbody, thead, tfoot, tr
[tbody][/tbody]|``|Parent can only be table, children can only be tr
[thead][/thead]|``|Parent can only be table, children can only be tr
[tfoot][/tfoot]|``|Parent can only be table, children can only be tr
[td][/td]|``|Parent can only be tr
[th][/th]|``|Parent can only be tr
[tr][/tr]|``|Parent can only be table, tbody, tfoot, thead. Children can only be td, th
[u][/u]|``|
[ul][/ul]|`
`|Children can only be li
[url={URL}]{content}[/url]|``|{content} is link text
[url]{URL}[/url]|``|{URL} is always link text
[white][/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| | | |
-----------|----------|-----------|----------|
red|green|blue|orange|
yellow|pink|black|white|
beige|brown|grey|gray|
silver|purple|maroon|lime|
limegreen|olive|navy|teal|
aqua||||
#### List Types supported for the above [list] tag
List Types||||
----------|----------|----------|----------|
none|disc|circle|square|
decimal|decimal-leading-zero|lower-roman|upper-roman|
lower-alpha|upper-alpha|lower-greek|lower-latin|
upper-latin|hebrew|armenian|georgian|
cjk-ideographic|hiragana|katakana|hiragana-iroha|
katakana-iroha||||