Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including tail.bbsolid with all npm packages installed. Try it out:

var tailBbsolid = require("tail.bbsolid")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

tail.bbsolid v0.1.1

tail.BBSolid is a solid and extendable BBCode Parser written in Vanilla JavaScript, available as AMD and for nodeJS too.

tail.BBSolid - A BBCode Markup Parser

npm Version License Author

tail.BBSolid is a expendable and easy-to-use BBCode Parser, written in vanilla JavaScript and available for your Browser, as AMD Module as well as for nodeJS! It already supports 46 BBCode Markups (+12 special markups are excluded in a separate file) and BBCode Tag Attributes as [tag attr=value], [tag attr="value"] or [tag="value"].

This script is inspired by Patorjks Extendible BBCode Parser!

The tail.BBSolid Markup Parser is currently an experimental Alpha version, and still may contains some bugs. It would be really helpful if you write us each issue and request on the official GitHub Issues Page. Thanks!

Demonstration

Features

  • 46 BBCode Tags (+ 12 Separated Special Tags) (+ 12 Aliases) (+ Attributes)
  • Parent -> Children Relationships / Restrictions
  • Valid HTML (5), no Stylesheet required!
  • Support for the latest Browsers, including Internet Explorer 9+
  • debug Shows the Errors directly in the console (including the index)
  • prettyPrint Make the Output HTML Code as pretty as possible
  • allowedHTML Define allowed HTML Tags, or dis/enable any HTML.
  • wrapParagraphs Paragraph-Wrapping around "Inline" elements
  • showLineBreaks Line Break Sequenzes within Paragraphs
  • removeUnparsed And Faulty BBCode Tags.

Usage

Smart Usage Code:

    // BBSolid is an Alias for BBSolid.parse(content, config)
    var HTMLContent = BBSolid("[b]Your BBCode Content[/b]", {
        debug:          false,      // Writes each error directly in the console
        prettyPrint:    true,       // Try to "pretty" format the HTML Code.
        allowedHTML:    true,       // The allowed HTML Tags as Array, True to allow any, False to disable any HTML Tag
        wrapParagraphs: true,       // Wrap Content in <p> Paragraphs
        showLineBreaks: true,       // Replaces single \n within <p> Paragraphs into <br />
        removeUnparsed: false       // Remove Unparsed / Faulty BBCodes
    });

    // Get the latest "passed" content with
    var LatestBBCodeContent = BBSolid.content;

    // Get the latest "parsed" content with
    var LatestHTMLContent = BBSolid.parsed;

    // Check if the latest passed occured an Error
    if(BBSolid.error){
        console.log( BBSolid.errors );
    }

Available BBCodes

Inline Elements

BBCodeAlt.AttributesExamples
[noparse][bbcode]null[noparse] [b]Bold[/b] [/noparse]
[b]color, font, size[b]Bold[/b]
[strong]color, font, size[strong color=red]Red String[/strong]
[i]color, font, size[i font=serif]Serif Italic[/i]
[em]color, font, size[em size=12px]Small Emphasized[/em]
[u]color, font, size[u font=serif color=#000]Back Serif underlined[/u]
[ins]color, font, size[ins]Just inserted Text[/ins]
[s]color, font, size[s]Strikethroughed Text[/s]
[del]color, font, size[del size=larger]Larger Deleted Text[/del]
[sub]color, font, size[sub color="rgb(0, 255, 0)"]Green subscripted Text[/sub]
[sup]color, font, size[sup font=Arial]Arial Superscripted Text[/sup]
[big][large]color, font, size[big]Big Text[/big]
[small]color, font, size[small]Small Text[/small]
[font][face]font*[font=Arial]Arial Text[/font]
[font font=Times]Times Text[/font]
[size]size*[size=20px]Big Text[/size]
[size size=small]Small Text[/small]
[color]color*[color=steelblue]SteelBlue Text[/color]
[color color=#000]Black Text[/color]
[url][link]href*, target[url]https://example.com[/url]
[url=https://example.com target=_blank]Custom Text[/url]
[img][image]src*, alt**[img]http://image.url[/img]
[img=http://image.url]Alt Text[/img]
[mail][email]mail*[mail]info@example.com[/mail]
[mail=info@example.com]Custom Text[/mail]
[code]null[code]Any Code, BB Tags doesn't get parsed in here![/code]

Legende

All Attributes marked with an * can be used inline, for example:
Default:    [bbcode attribute=value][/bbcode]
Inline:     [bbcode=value][/bbode]

The 'alt**' attribute on the 'img' and 'image' tags can also used WITHIN the tags:
Default:    [img]http://www.example.com/image.png[/img]
Parameter:  [img src=http://www.example.com/image.png alt="Alternative Text"][/img]
Inline:     [img=http://www.example.com/image.png alt="Alternative Text"][/img]
Within:     [img=http://www.example.com/image.png]Alternative Text[/img]

Block Elements

Some Block elements allows only a few BBCode Tags, or requires a specific Parent BBCode Tag.

BBCodeAlt.AttributesNote
[h1][h]nullFirst Header
[h2]nullSecond Header
[h3]nullThird Header
[h4]nullFourth Header
[h5]nullFifth Header
[h6]nullSixth Header
[hr]nullHorizontal Rule, doesn't require an closing tag!
[left]nullLeft-Align Paragraph
[right]nullRight-Align Paragraph
[center]nullCenter-Align Paragraph
[justify]nullJustify-Align Paragraph
[quote]cite*Blockquote with optional cite.
[codeblock]language*Codeblock with additional language-classnames.
[table]nullAllows: thead, tbody, tfoot and tr
[thead]nullAllows: tr
Requires: table
[tbody]nullAllows: tr
Requires: table
[tfoot]nullAllows: tr
Requires: table
[tr]nullAllows: th, td
Requires: table, thead, tbody or tfoot
[th]align, valign, colspan, rowspanRequires: tr
[td]align, valign, colspan, rowspanRequires: tr
[list][ul] [ol]type*Allows: li, *
[li][*]null* doesn't require an closing tag!
Required: list, ul or ol
[dl]nullAllows: dt, dd
[dt]nullRequires: dl
[dd]nullRequires: dl

Legende

All Attributes marked with an * can be used inline, for example:
Default:    [bbcode attribute=value][/bbcode]
Inline:     [bbcode=value][/bbode]

Extended Elements

You need to include the tail.bbsolid-extended.js JavaScript file, to use the following BBCode Tags. (on nodeJS: Include ONLY the extended file, but make sure, that the main file is available in the same folder as the extended file)!

BBCodeAttributesNote
[address]nullHTML5: Address Block
[caption]align*Table Caption
Requires: table
[mark]nullHTML5: Mark some Content
[q]nullHTML5: Inline Quotation
[abbr]title*Abbreviation
[acronym]title*Acronym
[dfn]title*Definition
[embed]src*, width, heightEmbed some Content
[audio]src*, width, height, autoplay, loopHTML5: Embed a Audio Source
[video]src*, width, height, autoplay, loopHTML5: Embed a Video Source
[youtube]src*, width, heightEmbed a YouTube Video, using iframe.
[spoiler]title*, closeCreate an Spoiler element

Legende

All Attributes marked with an * can be used inline, for example:
Default:    [bbcode attribute=value][/bbcode]
Inline:     [bbcode=value][/bbode]
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free