Add BBCodes from the bundled repository

$configurator = new s9e\TextFormatter\Configurator;
$configurator->BBCodes->addFromRepository('B');
$configurator->BBCodes->addFromRepository('I');
$configurator->BBCodes->addFromRepository('URL');

// Get an instance of the parser and the renderer
extract($configurator->finalize());

$text = 'Here be [url=http://example.org]the [b]bold[/b] [i]italic[/i] URL[/url].';
$xml  = $parser->parse($text);
$html = $renderer->render($xml);

echo $html;
Here be <a href="http://example.org">the <b>bold</b> <i>italic</i> URL</a>.

Add a configurable BBCode from the bundled repository

$configurator = new s9e\TextFormatter\Configurator;
$configurator->BBCodes->addFromRepository('SIZE', 'default', ['min' => 5, 'max' => 40]);

// Get an instance of the parser and the renderer
extract($configurator->finalize());

$text = "[size=1]Smallest[/size]\n[size=99]Biggest[/size]";
$xml  = $parser->parse($text);
$html = $renderer->render($xml);

echo $html;
<span style="font-size:5px">Smallest</span>
<span style="font-size:40px">Biggest</span>

List of bundled BBCodes

ACRONYM
[ACRONYM title={TEXT1;optional}]{TEXT2}[/ACRONYM]

<acronym title="{TEXT1}">{TEXT2}</acronym>

ALIGN
[ALIGN={CHOICE=left,right,center,justify}]{TEXT}[/ALIGN]

<div style="text-align:{CHOICE}">{TEXT}</div>

B
[B]{TEXT}[/B]

<b><xsl:apply-templates /></b>

BACKGROUND
[BACKGROUND={COLOR}]{TEXT}[/BACKGROUND]

<span style="background-color:{COLOR}">{TEXT}</span>

C
[C]{TEXT}[/C]

<code class="inline"><xsl:apply-templates /></code>

CENTER
[CENTER]{TEXT}[/CENTER]

<div style="text-align:center">{TEXT}</div>

CODE
[CODE lang={IDENTIFIER;optional}]{TEXT}[/CODE]

<pre data-hljs="" data-s9e-livepreview-postprocess="if('undefined'!==typeof hljs)hljs._hb(this)"><code>
    <xsl:if test="@lang">
        <xsl:attribute name="class">language-<xsl:value-of select="@lang"/></xsl:attribute>
    </xsl:if>
    <xsl:apply-templates />
</code></pre>
<script>if("undefined"!==typeof hljs)hljs._ha();else if("undefined"===typeof hljsLoading){hljsLoading=1;var a=document.getElementsByTagName("head")[0],e=document.createElement("link");e.type="text/css";e.rel="stylesheet";e.href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.7.0/styles/default.min.css";a.appendChild(e);e=document.createElement("script");e.type="text/javascript";e.onload=function(){var d={},f=0;hljs._hb=function(b){b.removeAttribute("data-hljs");var c=b.innerHTML;c in d?b.innerHTML=d[c]:(7&lt;++f&amp;&amp;(d={},f=0),hljs.highlightBlock(b.firstChild),d[c]=b.innerHTML)};hljs._ha=function(){for(var b=document.querySelectorAll("pre[data-hljs]"),c=b.length;0&lt;c;)hljs._hb(b.item(--c))};hljs._ha()};e.async=!0;e.src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.7.0/highlight.min.js";a.appendChild(e)}</script>

COLOR
[COLOR={COLOR}]{TEXT}[/COLOR]

<span style="color:{COLOR}">{TEXT}</span>

DD
[DD]{TEXT}[/DD]

<dd>{TEXT}</dd>

DEL
[DEL]{TEXT}[/DEL]

<del>{TEXT}</del>

DL
[DL]{TEXT}[/DL]

<dl>{TEXT}</dl>

DT
[DT]{TEXT}[/DT]

<dt>{TEXT}</dt>

EM
[EM]{TEXT}[/EM]

<em>{TEXT}</em>

EMAIL
[EMAIL={EMAIL;useContent}]{TEXT}[/EMAIL]

<a href="mailto:{EMAIL}">{TEXT}</a>

FLASH
[FLASH={PARSE=/^(?<width>\d+),(?<height>\d+)/} width={RANGE=0,1920;defaultValue=80} height={RANGE=0,1080;defaultValue=60} url={URL;useContent}]

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://fpdownload.macromedia.com/get/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="{@width}" height="{@height}">
    <param name="movie" value="{@url}" />
    <param name="quality" value="high" />
    <param name="wmode" value="opaque" />
    <param name="play" value="false" />
    <param name="loop" value="false" />

    <param name="allowScriptAccess" value="never" />
    <param name="allowNetworking" value="internal" />

    <embed src="{@url}" quality="high" width="{@width}" height="{@height}" wmode="opaque" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" play="false" loop="false" allowscriptaccess="never" allownetworking="internal"></embed>
</object>
Var name Default Description
minWidth 0 Minimum width for the Flash object
maxWidth 1920 Maximum width for the Flash object
minHeight 0 Minimum height for the Flash object
maxHeight 1080 Maximum height for the Flash object

FLOAT
[float={CHOICE=left,right,none}]{TEXT}[/float]

<div style="float:{CHOICE}">{TEXT}</div>

FONT
[font={FONTFAMILY}]{TEXT}[/font]

<span style="font-family:{FONTFAMILY}">{TEXT}</span>

H1
[H1]{TEXT}[/H1]

<h1>{TEXT}</h1>

H2
[H2]{TEXT}[/H2]

<h2>{TEXT}</h2>

H3
[H3]{TEXT}[/H3]

<h3>{TEXT}</h3>

H4
[H4]{TEXT}[/H4]

<h4>{TEXT}</h4>

H5
[H5]{TEXT}[/H5]

<h5>{TEXT}</h5>

H6
[H6]{TEXT}[/H6]

<h6>{TEXT}</h6>

HR
[HR]

<hr/>

I
[I]{TEXT}[/I]

<i>{TEXT}</i>

IMG
[IMG src={URL;useContent} title={TEXT;optional} alt={TEXT;optional}]

<img src="{@src}" title="{@title}" alt="{@alt}" />

INS
[INS]{TEXT}[/INS]

<ins>{TEXT}</ins>

JUSTIFY
[JUSTIFY]{TEXT}[/JUSTIFY]

<div style="text-align:justify">{TEXT}</div>

LEFT
[LEFT]{TEXT}[/LEFT]

<div style="text-align:left">{TEXT}</div>

LIST
[LIST type={HASHMAP=1:decimal,a:lower-alpha,A:upper-alpha,i:lower-roman,I:upper-roman;optional;postFilter=#simpletext} start={UINT;optional} #createChild=LI]{TEXT}[/LIST]

<xsl:choose>
    <xsl:when test="not(@type)">
        <ul><xsl:apply-templates /></ul>
    </xsl:when>
    <xsl:when test="starts-with(@type,'decimal') or starts-with(@type,'lower') or starts-with(@type,'upper')">
        <ol style="list-style-type:{@type}"><xsl:copy-of select="@start"/><xsl:apply-templates /></ol>
    </xsl:when>
    <xsl:otherwise>
        <ul style="list-style-type:{@type}"><xsl:apply-templates /></ul>
    </xsl:otherwise>
</xsl:choose>

*
[*]{TEXT}[/*]

<li><xsl:apply-templates /></li>

MAGNET
[MAGNET={REGEXP=/^magnet:/;useContent}]{TEXT}[/MAGNET]

<a href="{REGEXP}"><img alt="" src="data:image/gif;base64,R0lGODlhDAAMALMPAOXl5ewvErW1tebm5oocDkVFRePj47a2ts0WAOTk5MwVAIkcDesuEs0VAEZGRv///yH5BAEAAA8ALAAAAAAMAAwAAARB8MnnqpuzroZYzQvSNMroUeFIjornbK1mVkRzUgQSyPfbFi/dBRdzCAyJoTFhcBQOiYHyAABUDsiCxAFNWj6UbwQAOw==" style="vertical-align:middle;border:0;margin:0 5px 0 0"/>{TEXT}</a>

NOPARSE
[NOPARSE #ignoreTags=true]{TEXT}[/NOPARSE]

{TEXT}

OL
[OL]{TEXT}[/OL]

<ol>{TEXT}</ol>

QUOTE
[QUOTE author={TEXT;optional}]{TEXT}[/QUOTE]

<blockquote>
    <xsl:if test="not(@author)">
        <xsl:attribute name="class">uncited</xsl:attribute>
    </xsl:if>
    <div>
        <xsl:if test="@author">
            <cite>
                <xsl:value-of select="@author" /> wrote:
            </cite>
        </xsl:if>
        <xsl:apply-templates />
    </div>
</blockquote>
Var name Default Description
authorStr <xsl:value-of select="@author" /> wrote:

RIGHT
[RIGHT]{TEXT}[/RIGHT]

<div style="text-align:right">{TEXT}</div>

S
[S]{TEXT}[/S]

<s>{TEXT}</s>

SIZE
[SIZE={RANGE=8,36}]{TEXT}[/SIZE]

<span style="font-size:{RANGE}px">{TEXT}</span>
Var name Default Description
min 8
max 36

SPOILER
[SPOILER title={TEXT1;optional}]{TEXT2}[/SPOILER]

<div class="spoiler">
    <div class="spoiler-header">
        <!--
            var nextSiblingStyle = parentNode.nextSibling.style,
                firstChildStyle  = firstChild.style,
                lastChildStyle   = lastChild.style;

            firstChildStyle.display  = nextSiblingStyle.display;
            nextSiblingStyle.display = lastChildStyle.display = (firstChildStyle.display) ? '' : 'none';
        -->
        <button onclick="var a=parentNode.nextSibling.style,b=firstChild.style,c=lastChild.style;b.display=a.display;a.display=c.display=(b.display)?'':'none'"><span>Show</span><span style="display:none">Hide</span></button>
        <span class="spoiler-title">Spoiler: {TEXT1}</span>
    </div>
    <div class="spoiler-content" style="display:none">{TEXT2}</div>
</div>
Var name Default Description
showStr Show
hideStr Hide
spoilerStr Spoiler:

STRONG
[STRONG]{TEXT}[/STRONG]

<strong>{TEXT}</strong>

SUB
[SUB]{TEXT}[/SUB]

<sub>{TEXT}</sub>

SUP
[SUP]{TEXT}[/SUP]

<sup>{TEXT}</sup>

TABLE
[TABLE]{ANYTHING}[/TABLE]

<table>{ANYTHING}</table>

TBODY
[TBODY]{ANYTHING}[/TBODY]

<tbody>{ANYTHING}</tbody>

TD
[TD align={CHOICE=left,center,right,justify;caseSensitive;optional;preFilter=strtolower} #createParagraphs=false]{TEXT}[/TD]

<td>
    <xsl:if test="@align">
        <xsl:attribute name="style">text-align:{CHOICE}</xsl:attribute>
    </xsl:if>
    <xsl:apply-templates/>
</td>

TH
[TH align={CHOICE=left,center,right,justify;caseSensitive;optional;preFilter=strtolower} #createParagraphs=false]{TEXT}[/TH]

<th>
    <xsl:if test="@align">
        <xsl:attribute name="style">text-align:{CHOICE}</xsl:attribute>
    </xsl:if>
    <xsl:apply-templates/>
</th>

THEAD
[THEAD]{ANYTHING}[/THEAD]

<thead>{ANYTHING}</thead>

TR
[TR]{ANYTHING}[/TR]

<tr>{ANYTHING}</tr>

U
[U]{TEXT}[/U]

<u>{TEXT}</u>

UL
[UL]{TEXT}[/UL]

<ul>{TEXT}</ul>

URL
[URL={URL;useContent} title={TEXT;optional}]{TEXT}[/URL]

<a href="{@url}"><xsl:copy-of select="@title" /><xsl:apply-templates /></a>

VAR
[VAR]{TEXT}[/VAR]

<var>{TEXT}</var>