Skip to content

Avoid wrapping single paragraphs in p tags? #812

Answered by colinodell
kokoshneta asked this question in Q&A
Discussion options

You must be logged in to vote

Hey there! There's no built-in functionality to enable that behavior. You could probably accomplish this with by decorating the built-in ParagraphRenderer with one that immediately returns just the child inlines if it's the only paragraph. Something like this (untested):

final class AvoidParagraphTagsIfOnlyParagraphRenderer implements NodeRendererInterface
{
    private ParagraphRenderer $normalRenderer;

    public function __construct(ParagraphRenderer $normalRenderer)
    {
        $this->normalRenderer = $normalRenderer;
    }

    public function render(Node $node, ChildNodeRendererInterface $childRenderer): string
    {
        // Is this paragraph the only block in the document?

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@kokoshneta
Comment options

Answer selected by kokoshneta
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants