Skip to content

Instantly share code, notes, and snippets.

@colinodell
Created February 6, 2017 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save colinodell/d9ffb915c4b06cfb2bb8da22793377bb to your computer and use it in GitHub Desktop.
Save colinodell/d9ffb915c4b06cfb2bb8da22793377bb to your computer and use it in GitHub Desktop.
CommonMark - Overriding default renderers
<?php
use League\CommonMark\Block\Element\AbstractBlock;
use League\CommonMark\ElementRendererInterface;
class CustomParagraphRenderer implements BlockRendererInterface
{
public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, $inTightList = false)
{
return $htmlRenderer->renderInlines($block->children());
}
}
<?php
$environment = Environment::createCommonMarkEnvironment();
$environment->addBlockRenderer('League\CommonMark\Block\Element\Paragraph', new CustomParagraphRenderer());
$converter = new CommonMarkConverter([], $environment);
echo $converter->convertToHtml('**Hello World!**');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment