Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unabled to convert empty lines into the correct HTML element #698

Closed
tiagolima97 opened this issue Feb 16, 2023 · 6 comments
Closed

Unabled to convert empty lines into the correct HTML element #698

tiagolima97 opened this issue Feb 16, 2023 · 6 comments
Labels

Comments

@tiagolima97
Copy link

tiagolima97 commented Feb 16, 2023

Here's an image showing what the markdown text I'm trying to convert looks like:
image

Here's the value I have relative to the previous image:
TEST 1\n\nTEST 2\n\nTEST 3\n\n- TEST 4\n- TEST 5

Here's the output I'm getting from the Markdown.ToHtml method:
<p>TEST 1</p>\n<p>TEST 2</p>\n<p>TEST 3</p>\n<ul>\n<li>TEST 4</li>\n<li>TEST 5</li>\n</ul>\n

The output is returned with a bunch of \n that aren't converted successfully to HTML tags.

Here's the output I was expecting to get:
<p>TEST 1</p><br><p>TEST 2</p><br><p>TEST 3</p><br><ul><li>TEST 4</li><li>TEST 5</li></ul>

@xoofx xoofx added the question label Feb 16, 2023
@xoofx
Copy link
Owner

xoofx commented Feb 16, 2023

The output is returned with a bunch of \n that aren't converted successfully to HTML tags.

It depends on the options you are using. The default is that it should be CommonMark compliant, and it means that you don't get <br> for multiple lines. There is an extension in Markdig to create hard break lines, but it's not outside of a paragraph as you expect (afair, <br> has to be inside a <p> as per the HTML specs)

@tiagolima97
Copy link
Author

Thanks for the quick response @xoofx!

In regard to the <br> being inside the <p>, you're correct, that's how it should be returned. My mistake.

However, I've tried adding the extension needed to create hard break lines but I still get the same output.
It seems that Markdig is struggling to understand what these \n mean and leaves them unparsed.

Here's the implementation I'm testing:
image

Here's the output I'm getting:
image

@tiagolima97 tiagolima97 changed the title Unabled to convert empty lines into the correct HTML tag Unabled to convert empty lines into the correct HTML element Feb 17, 2023
@xoofx
Copy link
Owner

xoofx commented Feb 17, 2023

It seems that Markdig is struggling to understand what these \n mean and leaves them unparsed.

Yep, but the extension is for lines within a paragraph, not trailing blank lines. The problem is that blank lines are used to break paragraph already. It's part of CommonMark parsing rules and this is not something that can be changed.

@CraigComeOnThisNameCantBeTaken

I am also finding this a problem

@angezid
Copy link

angezid commented May 26, 2023

It's part of CommonMark parsing rules and this is not something that can be changed.

Why Github

not following this stupid

rule?

Markdown is a plain text format for writing structured documents.

How to keep structure of documents then?

@xoofx
Copy link
Owner

xoofx commented May 26, 2023

How to keep structure of documents then?

A blank line is not considered as a structure. Don't use Markdown in that case.

@xoofx xoofx closed this as completed May 26, 2023
Repository owner locked and limited conversation to collaborators May 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants