Allow disabling wrapping <p> tags in one liners.
See original GitHub issueSteps to reproduce the problem (provide example input)
Parser parser = Parser.builder().build()
HtmlRenderer renderer = HtmlRenderer.builder().build()
Node document = parser.parseReader('Here I have a test [link](http://www.google.com)')
String result = renderer.render(document)
Expected behavior:
result == "Here I have a test <a href="http://www.google.com">link</a>"
Actual behavior:
result == "<p>Here I have a test <a href="http://www.google.com">link</a></p>"
I understand that this may be a breaking change, so an option on HtmlRenderer on this would be sufficient.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:7
- Comments:11
Top Results From Across the Web
Allow disabling wrapping <p> tags in one liners. #150 - GitHub
I guess the real question is why would I want the wrapping <p> tag when my input did not have any leading/trailing whitespace?...
Read more >Is it possible to disable wrapping of inline HTML with <p> tags?
I get the tag without the <p> tags, but that's three lines of text just for a single tag. For background, I'm trying...
Read more >How to Disable Word Wrapping in HTML - W3docs
To prevent the text from wrapping, you can use the CSS white-space property with the “nowrap” or “pre” value. In this snippet, you...
Read more >Stop <p> tags from wrapping onto a new line - Stack Overflow
You can add white-space: nowrap to the p tag css and it will stop the wrapping. you can read more about it here: ......
Read more >wpautop() | Function - WordPress Developer Resources
Description. A group of regex replaces used to identify text formatted with newlines and replace double line breaks with HTML paragraph tags.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Again, consumers should not be aware of or rely on any specific HTML or structure that is generated by this library. I’m not arguing that it isn’t easy…it is incredibly easy. However, it’s not future proof and it’s brittle. It also completely defeats the purpose of using any rendering library (MD or otherwise) to have to post process and manipulate the results. Think of it like a translator library. If I call you to translate English to Spanish, should I manipulate the output or ask you for a specific dialect? It’s no different for MD to HTML.
I’m not sure how else to explain that this is a bad design decision. Coding around it is almost as painful as having to explain why.
They have to be aware of the AST (abstract syntax tree, node structure), yeah.
No, it doesn’t. To be clear, what I’m proposing is that you do this:
The middle step is not dependent on how HtmlRenderer behaves. Not sure why you would think that?
We could add a utility method for this middle step, but I’m not sure about it yet. The method name would be something like
unwrapParagraphIfDocumentContainsSingleParagraph(Node document)
It’s consistent with what the reference implementations commonmark.js and cmark do. I had a quick look and there’s an open issue for the JS implementation here, but no replies yet: https://github.com/commonmark/commonmark.js/issues/152