question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow disabling wrapping <p> tags in one liners.

See original GitHub issue

Steps 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:open
  • Created 5 years ago
  • Reactions:7
  • Comments:11

github_iconTop GitHub Comments

2reactions
dustindclarkcommented, Jun 1, 2019

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.

2reactions
robinstcommented, Apr 11, 2019

Are you saying that libraries/apps that consume CommonMark should be aware of the HTML/DOM that is being generated and manipulate it accordingly?

They have to be aware of the AST (abstract syntax tree, node structure), yeah.

That’s extremely brittle and breaks every time HtmlRenderer changes.

No, it doesn’t. To be clear, what I’m proposing is that you do this:

  • Parse the text
  • Manipulate the AST if needed
  • Render it using HtmlRenderer

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)

The problem here is that CommonMark makes a bad assumption that a single line is a paragraph in the first place.

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found