Skip to content

How to convert empty lines into <br> tag? #654

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

You must be logged in to vote

This behavior follows the CommonMark spec. However, there are ways you can customize this library which might work.

If you only want this tag to appear after paragraphs, one possible option for you would be extending the ParagraphRenderer to always add a <br> after every paragraph:

class MyParagraphRenderer extends ParagraphRenderer
{
    public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, $inTightList = false)
    {
        return parent::render($block, $htmlRenderer, $inTightList) . '<br>';
    }
}

If you only want <br> to appear between paragraphs, you'll probably need to implement a DocumentProcessor which iterates through the tree of parsed elements a…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by colinodell
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question General questions about the project or usage
3 participants
Converted from issue

This discussion was converted from issue #310 on June 12, 2021 14:06.