-
Notifications
You must be signed in to change notification settings - Fork 641
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
Fix newline breaks in markdown #8673
Conversation
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. |
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. |
@@ -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)] |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
[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)] |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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?
Fixes #8642