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

Fix newline breaks in markdown #8673

Merged
merged 4 commits into from
Jul 19, 2021

Conversation

CyberAndrii
Copy link
Contributor

Fixes #8642

@CyberAndrii CyberAndrii requested a review from a team as a code owner July 9, 2021 11:21
@joelverhagen
Copy link
Member

Hey @CyberAndrii, thanks for taking the time to investigate this and provide a fix. @lyndaidaii will review this PR and support you in any PR comments that come up.

@lyndaidaii
Copy link
Contributor

Looks great to me. Already verified changes. Overall, it improved how existing readme display, made prettier. However, It might impact few existing readme. I think it's great contribution and encourage users to adapt best practice of markdown readme.
Let me get another reviewer before we merge. @CyberAndrii thanks for great work!

@@ -77,6 +77,8 @@ public void EncodesHtmlInMarkdownWithAdaptiveHeader(string originalMd, string ex
[InlineData("\ufeff# Heading with BOM", "<h2>Heading with BOM</h2>", false, false)]
[InlineData("- List", "<ul>\n<li>List</li>\n</ul>", false, true)]
[InlineData("- List", "<ul>\r\n<li>List</li>\r\n</ul>", false, false)]
[InlineData("This is a paragraph\nwithout a break inside", "<p>This is a paragraph\nwithout a break inside</p>", false, true)]
[InlineData("This is a paragraph\r\nwithout a break inside", "<p>This is a paragraph\r\nwithout a break inside</p>", false, false)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A break should still be inserted if I have a readme with multiple empty lines, right? For example:

Hello world

I expect a break between these two lines

Could you add a test for this case?

Copy link
Contributor

@loic-sharma loic-sharma Jul 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EDIT: Please ignore this message as per @lyndaidaii's reply below

@lyndaidaii Should all new markdown tests use markdig? The commonmark code is effectively dead now, right?

Suggested change
[InlineData("This is a paragraph\r\nwithout a break inside", "<p>This is a paragraph\r\nwithout a break inside</p>", false, false)]
[InlineData("This is a paragraph\r\nwithout a break inside", "<p>This is a paragraph\r\nwithout a break inside</p>", false, true)]

Copy link
Contributor

@lyndaidaii lyndaidaii Jul 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are no longer use commonMark to render markdown file right now. this unit test case here, is because that in commonMark we encode first. that's why it appear \r\n instead for commonMark. it will nice to have a this case included as we did
[InlineData("- List", "<ul>\n<li>List</li>\n</ul>", false, true)]

[InlineData("- List", "<ul>\r\n<li>List</li>\r\n</ul>", false, false)]

Also This is a paragraph\r\nwithout a break inside", "<p>This is a paragraph\r\nwithout a break inside</p>
is same to 'This is a paragraph\nwithout a break inside', only \r\n is encoded in commonMark.

@loic-sharma, let me know if it make sense?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CyberAndrii Would you like to add unit test as Loic suggested above? thanks

Copy link
Contributor Author

@CyberAndrii CyberAndrii Jul 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, missed his message.

It converts to separate paragraphs regardless of the number of blank lines (same as on github):


image


image

Is this right?

Copy link
Contributor

@lyndaidaii lyndaidaii Jul 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this unit test with multiple new line. we will treat as one line here.

I added unit test for soft line break and hard line break. also include your multiple new line cases.

You can create line breaks in two ways.

Soft line break
Hardline break

Soft line breaks can be created by adding two spaces at the end of the line. This way markdown will render each line to be separate lines.
Hardline breaks can be created by inserting an empty line between each line.

Thank you for your contribution!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@loic-sharma, could you take a look at changes we added for unit test?

@lyndaidaii lyndaidaii changed the base branch from main to dev July 19, 2021 19:50
@lyndaidaii lyndaidaii merged commit e82c930 into NuGet:dev Jul 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Package readme display creates a <br> for every markdown newline, against markdown specification
4 participants