disable leading and ending paragraph #427

Closed
opened 2026-01-29 14:36:23 +00:00 by claunia · 5 comments
Owner

Originally created by @schmitch on GitHub (Jan 27, 2021).

Hello currently when I'm rendering a simple html string to markdown via markdig:

Console.WriteLine(Markdig.ToHtml("test **hello**"));

and the output will be <p>test <strong>hello</strong></p> is there a way to stop rendering the p tag?

Originally created by @schmitch on GitHub (Jan 27, 2021). Hello currently when I'm rendering a simple html string to markdown via markdig: ``` Console.WriteLine(Markdig.ToHtml("test **hello**")); ``` and the output will be `<p>test <strong>hello</strong></p>` is there a way to stop rendering the p tag?
claunia added the question label 2026-01-29 14:36:23 +00:00
Author
Owner

@xoofx commented on GitHub (Jan 27, 2021):

No, it's part of CommonMark. You can workaround by trimming start/end of the string.

@xoofx commented on GitHub (Jan 27, 2021): No, it's part of CommonMark. You can workaround by trimming start/end of the string.
Author
Owner

@jjxtra commented on GitHub (Jan 10, 2023):

Trimming is tricky especially if text has newlines, you can end up trimming out paragraph tags inadvertently.

@jjxtra commented on GitHub (Jan 10, 2023): Trimming is tricky especially if text has newlines, you can end up trimming out paragraph tags inadvertently.
Author
Owner

@xoofx commented on GitHub (Jan 10, 2023):

Trimming is tricky especially if text has newlines, you can end up trimming out paragraph tags inadvertently.

Trimming is not tricky, because trimming only happens on the edges, so it won't trim intermediate paragraphs

@xoofx commented on GitHub (Jan 10, 2023): > Trimming is tricky especially if text has newlines, you can end up trimming out paragraph tags inadvertently. Trimming is not tricky, because trimming only happens on the edges, so it won't trim intermediate paragraphs
Author
Owner

@jjxtra commented on GitHub (Jan 10, 2023):

Trimming leading/tailing <p> and </p> can screw up the html. This bit me when I trimmed generated text of <p>paragraph 1 text</p>...<p>paragraph 2 text</p>

@jjxtra commented on GitHub (Jan 10, 2023): Trimming leading/tailing `<p> and </p>` can screw up the html. This bit me when I trimmed generated text of `<p>paragraph 1 text</p>...<p>paragraph 2 text</p>`
Author
Owner

@xoofx commented on GitHub (Jan 10, 2023):

Trimming leading/tailing <p> and </p> can screw up the html. This bit me when I trimmed generated text of <p>paragraph 1 text</p>...<p>paragraph 2 text</p>

Right, and if it is more complicated than that, you should use something like AngleSharp.

Implementing it in Markdig would not be not more simple.

@xoofx commented on GitHub (Jan 10, 2023): > Trimming leading/tailing `<p> and </p>` can screw up the html. This bit me when I trimmed generated text of `<p>paragraph 1 text</p>...<p>paragraph 2 text</p>` Right, and if it is more complicated than that, you should use something like [AngleSharp](https://github.com/AngleSharp/AngleSharp). Implementing it in Markdig would not be not more simple.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#427