I don't understand why KaTeX would interact with BBCode markup. Don't you run it on HTML code?
Not knowing anything about KaTeX or MathJax, I'd create a BBCode that outputs its content in a code
element then I'd run the TeX library over elements that match the code.text
selector. That probably means you would not use the auto-render plugin and execute the transformation manually.
$configurator = new s9e\TextFormatter\Configurator;
$configurator->Litedown;
$configurator->BBCodes->addCustom(
'[imath]{TEXT}[/imath]',
'<code class="tex">{TEXT}</code>'
);
extract($configurator->finalize());
$text = '[imath]x^2[/imath]';
$xml = $parser->parse($text);
$html = $renderer->render($xml);
die("$html\n");
<p><code class="tex">x^2</code></p>
Or is it related to this?
Kylo If it encounters a custom delimiter including equation (like $$x2$$)
I don't know about your extension, I guess maybe you implemented your own custom markup? I generally don't recommend using custom markup if you can use something like BBCode. Otherwise, the most reliable method would be to create a plugin for it, which isn't really documented IIRC. Next, would be using a custom parser but there's no JavaScript API for it. If the markup is simple enough, you can get away with using the Preg
plugin:
$configurator = new s9e\TextFormatter\Configurator;
$configurator->Litedown;
$configurator->BBCodes->addCustom(
'[imath]{TEXT}[/imath]',
'<code class="tex">{TEXT}</code>'
);
$configurator->Preg->match('/\\$\\$(.+?)\\$\\$/', 'IMATH');
extract($configurator->finalize());
$text = '$$x^2$$';
$xml = $parser->parse($text);
$html = $renderer->render($xml);
die("$html\n");
<p><code class="tex">x^2</code></p>