PHP code example of develate / commonmark-customtags
1. Go to this page and download the library: Download develate/commonmark-customtags library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
develate / commonmark-customtags example snippets
evelate\CommonmarkCustomtags\Customtag;
use Develate\CommonmarkCustomtags\CustomtagExtension;
use League\CommonMark\Environment\Environment;
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
use League\CommonMark\MarkdownConverter;
final class BadgeTag extends Customtag
{
public function identifier(): string
{
return 'badge';
}
public function render($arguments, $globals): Stringable|string|null
{
$text = htmlspecialchars($arguments['text'] ?? '', ENT_QUOTES);
$tone = htmlspecialchars($arguments['tone'] ?? 'default', ENT_QUOTES);
return sprintf('<span class="badge badge--%s">%s</span>', $tone, $text);
}
}
$environment = new Environment([]);
$environment->addExtension(new CommonMarkCoreExtension());
$environment->addExtension(
(new CustomtagExtension())
->addTag(new BadgeTag())
);
$converter = new MarkdownConverter($environment);
echo $converter->convert('Status: {{badge text="Ready now" tone=success}}');