How to convert empty lines into <br> tag? #654
-
How can I convert empty lines into a Example: foo
bar Turns into this: <p>Foo</p>
<p>Bar</p> While I want this: <p>Foo</p>
<br />
<p>Bar</p> |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
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 class MyParagraphRenderer extends ParagraphRenderer
{
public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, $inTightList = false)
{
return parent::render($block, $htmlRenderer, $inTightList) . '<br>';
}
} If you only want If you truly want to convert ALL empty lines to Our docs should give you a good starting point on how to implement these various approaches: https://commonmark.thephpleague.com/customization/overview/ Hope that helps! |
Beta Was this translation helpful? Give feedback.
-
@marktopper See also at MDN:
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/br#Notes |
Beta Was this translation helpful? Give feedback.
-
Thanks @colinodell, will try that out. @froschdesign, the reason I need this is because that I have a Markdown editor in Javascript on my application's admin panel that makes an empty newline into a break tag. |
Beta Was this translation helpful? Give feedback.
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:If you only want
<br>
to appear between paragraphs, you'll probably need to implement aDocumentProcessor
which iterates through the tree of parsed elements a…