Replies: 2 comments 2 replies
-
If the goal is to replace image URLs with the image itself, you can use the Autoimage plugin. Otherwise, I'd probably create a tag filter that invalidates the tag if the URL matches a static image and that no markup was used to create the link, so that you can still manually/explicitly link to those. https://s9etextformatter.readthedocs.io/Filters/Callback_signature/ $configurator = new s9e\TextFormatter\Configurator;
function unlinkStaticImages(s9e\TextFormatter\Parser\Tag $tag, $tagText)
{
if ($tagText === '' && preg_match('(\\.(?:bmp|gif|jpe?g|png|svg|webp)$)', $tag->getAttribute('url')))
{
$tag->invalidate();
}
}
$configurator->Autolink;
$configurator->Litedown;
$configurator->tags['URL']->filterChain->append('unlinkStaticImages($tag, $tagText)')->setJS('
function (tag, tagText)
{
if (tagText === "" && /\\.(?:bmp|gif|jpe?g|png|svg|webp)$/.test(tag.getAttribute("url"))
{
tag.invalidate();
}
}
');
extract($configurator->finalize());
$text = "http://localhost/img.png\n"
. "http://localhost/img.php\n"
. '<http://localhost/img.png>';
$xml = $parser->parse($text);
$html = $renderer->render($xml);
die("$html\n"); <p>http://localhost/img.png
<a href="http://localhost/img.php">http://localhost/img.php</a>
<a href="http://localhost/img.png">http://localhost/img.png</a></p> |
Beta Was this translation helpful? Give feedback.
-
Not sure whether it's better, but you can use the $configurator->Preg->match(
'#\\b(?<src>https?://[\\w./]+\\.(?:gif|png))(?!\\S)#i',
'IMG'
); |
Beta Was this translation helpful? Give feedback.
-
Hi Joshy,
Once again, I'm reaching out for some assistance.
ChatGPT helped me set up exclusion rules for the img class in the autolink feature, and it's working as expected.
Here’s the relevant code in the Configurator.php file:
I’d like to ask if it's possible to achieve the same effect by configuring it in the ServiceProvider.php file. Here is my current setup. I've tried making some adjustments for autolink, but so far, I've not been successful.
Perhaps you could guide me in the right direction.
Much appreciated!
BR,
Kai
Beta Was this translation helpful? Give feedback.
All reactions