How to render only inlines? #656
-
is there a method for inline rendering ? $converter = new CommonMarkConverter(); to produce |
Beta Was this translation helpful? Give feedback.
Answered by
colinodell
Jun 12, 2021
Replies: 2 comments 3 replies
-
You could create a custom renderer for class InlineOnlyRenderer implements BlockRendererInterface
{
public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, $inTightList = false)
{
return $htmlRenderer->renderInlines($block->children());
}
} To use it: // Create the standard environment with all the default parsers, renderers, etc.
$environment = Environment::createCommonMarkEnvironment();
// Override the default Paragraph renderer with the one we just created
$environment->addBlockRenderer(Paragraph::class, new InlineOnlyRenderer());
// Instantiate the converter with the custom Environment we just configured
$converter = new CommonMarkConverter([], $environment);
// Convert to HTML
echo $converter->convertToHtml('**Hello World!**'); I hope that helps! |
Beta Was this translation helpful? Give feedback.
0 replies
-
We now have an Inlines-Only Extension which solves this use case. |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
colinodell
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We now have an Inlines-Only Extension which solves this use case.