Created
February 6, 2017 14:40
-
-
Save colinodell/d9ffb915c4b06cfb2bb8da22793377bb to your computer and use it in GitHub Desktop.
CommonMark - Overriding default renderers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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()); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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