naba0123/commonmark-ext-img-url-prefix

Extension for league/commonmark to add prefix to src url of Img tag with specitific distinction

1.0 2021-07-21 13:14 UTC

This package is auto-updated.

Last update: 2024-04-06 19:29:27 UTC


README

Extension for league/commonmark to add prefix url to img with specitific distinction.

https://packagist.org/packages/naba0123/commonmark-ext-img-url-prefix

Install

composer require naba0123/commonmark-ext-img-url-prefix

Example

$environment = \League\CommonMark\Environment::createCommonMarkEnvironment();
$environment->addExtension(new \Naba0123\CommonMark\Ext\ImgPreUrl\ImgPreUrlExtension());

$converter = new \League\CommonMark\CommonMarkConverter([
	'img_pre_url-pre_url' => '/example/dir/',
	'img_pre_url-distinction_char' => '@',
], $environment);

echo $converter->convertToHtml('![Alt Text](path.jpg)');

The above is converted to Img tag as the following

<img src="/example/dir/path.jpg" alt="Alt Text">