Closed frankli0324 closed 2 years ago
Yes.
it would be nicer if it's somehow configurable...
If your goal is to display emoji from a specific CDN, the simplest way would be to set your own template via $configurator->Emoji->getTag()->template
. If you want to keep the original template and only change the image's source, you can modify the existing template using DOM operations. For example:
$configurator = new s9e\TextFormatter\Configurator;
$dom = $configurator->Emoji->getTag()->template->asDOM();
foreach ($dom->query('//img') as $img)
{
$img->setAttribute('src', '/path/to/emoji/{@seq}.svg');
}
$dom->saveChanges();
extract($configurator->finalize());
$text = "\u{1F600}";
$xml = $parser->parse($text);
$html = $renderer->render($xml);
die("$html\n");
<img alt="😀" class="emoji" draggable="false" src="/path/to/emoji/1f600.svg">
actually I already dealt with emoji, and I'm currently struggling with code highlighting
Then it's the same but with the CODE
tag.
Thanks for the suggestion( but.... I didn't... hmmmm like it that much? it's not ... can't explain(((:P thanks anyway
also, I'm just a user of flarum, and followed the jsdelivr url to this repo.
https://cdn.jsdelivr.net/gh/s9e/hljs-loader@1.0.28/loader.min.js
seems to be hard coded
Yes, the URL to highlight.js
can be changed at the time of the BBCode's creation (see below) but the URL to hljs-loader
is hardcoded. Even if there were mirrors for the library, you'd have to match the exact version otherwise the integrity check would fail and the thing would break silently. At that point, it's simpler to just create your own BBCode than try to modify this one.
$configurator = new s9e\TextFormatter\Configurator;
$configurator->BBCodes->addFromRepository(
'CODE',
'default',
['url' => 'https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.5.1/']
);
extract($configurator->finalize());
$text = '[code]printf("%s", $var);[/code]';
$xml = $parser->parse($text);
$html = $renderer->render($xml);
die("$html\n");
<pre><code>printf("%s", $var);</code><script async="" crossorigin="anonymous" data-hljs-style="github" data-hljs-url="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.5.1/" integrity="sha384-fQc6882DqpMzcLWJbK07+Xnd8dceuG+q15iFvx+m/bAzjiBJeLnbNfaiXYzJBEn/" onload="hljsLoader.highlightBlocks(this.parentNode)" src="https://cdn.jsdelivr.net/gh/s9e/hljs-loader@1.0.28/loader.min.js"></script></pre>
this is in fact more of a feature request rather than seeking help... well, this wouldn't be solved then? also, why not publishing hljs-loader on npm? to make CDNs happy
could jsdelivr be replaced? ref https://github.com/flarum/framework/issues/3440