-
Notifications
You must be signed in to change notification settings - Fork 643
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
Markdig version update #8292
Markdig version update #8292
Conversation
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.
What's the update for? FYI, the issue link seems to be incorrect
Tested with updated markdig version in serverCommon, need update package version with NuGet.Services.Messaging.Email, then merge this after change in serverCommon(NuGet/ServerCommon#348) |
Please verify the account deletion emails in particular. The account deleter is in the strange position to refer to ServerCommon, NuGet.Jobs, and NuGetGallery libraries all at once. There can be some strange dependency issues because of that. |
Would have separate PR for migrating functionality using markdig, I will revert the last commit "migrate to markdig" after test |
@@ -110,5 +122,72 @@ public RenderedMarkdownResult GetHtmlFromMarkdown(string markdownString, int inc | |||
return output; | |||
} | |||
} | |||
|
|||
public RenderedMarkdownResult GetHtmlFromMarkdownMarkdig(string markdownString, int incrementHeadersBy) | |||
{ |
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.
Any argument validation needed?
@@ -110,5 +122,72 @@ public RenderedMarkdownResult GetHtmlFromMarkdown(string markdownString, int inc | |||
return output; | |||
} | |||
} | |||
|
|||
public RenderedMarkdownResult GetHtmlFromMarkdownMarkdig(string markdownString, int incrementHeadersBy) |
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.
This method seems to be used only here. Is the parametrization of the "incrementHeadersBy" needed?
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.
Current we support adaptive header, in order to continue support the same functionality, I believe we still need "incrementHeaderBy"
{ | ||
if (node is HeadingBlock heading) | ||
{ | ||
heading.Level = (byte)Math.Min(heading.Level + incrementHeadersBy, 6); |
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.
Maybe add a comment why 6?
{ | ||
if (linkInline.IsImage) | ||
{ | ||
// Allow only http or https links in markdown. Transform link to https for known domains. |
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.
Should this comment be used for links? I see that we always apply HTTPS for images, even though I am not sure why we design it in this way.
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.
Yes, It's also used to link. I could make same comments for links if you think it's not clear
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.
I think this comment only applies to links (see "CommonMark" one). For images, we don't "allow http or https", and we don't transform links to https only for known domains. We always force images to use "https", is it ("rewriteAllHttp: true")?
[InlineData("[text](javascript:alert('hi'))", "<p><a href=\"\" rel=\"nofollow\">text</a></p>", false, true)] | ||
[InlineData("[text](javascript:alert('hi'))", "<p><a href=\"\" rel=\"nofollow\">text</a></p>", false, false)] | ||
[InlineData("> <text>Blockquote</text>", "<blockquote>\n<p><text>Blockquote</text></p>\n</blockquote>", false, true)] | ||
[InlineData("> <text>Blockquote</text>", "<blockquote>\r\n<p><text>Blockquote</text></p>\r\n</blockquote>", 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.
I am not very sure but it may be helpful to have a test case of "Nested Blockquotes".
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.
Nested Blockquotes added with latest changes
} | ||
|
||
[Fact] | ||
public void ThrowsArgumentOutOfRangeExceptionForNegativeParameterValue() |
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.
nit: how about naming it like "ThrowsArgumentOutOfRangeExceptionForNegativeIncrementHeadersBy()"?
|
||
if (incrementHeadersBy < 0) | ||
{ | ||
throw new ArgumentOutOfRangeException(nameof(incrementHeadersBy)); |
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.
nit: maybe add a message about the accepted range, for example:
NuGetGallery/src/NuGetGallery/Helpers/StreamHelper.cs
Lines 28 to 31 in e53e623
if (maxSize <= 0 || maxSize >= int.MaxValue) | |
{ | |
throw new ArgumentOutOfRangeException(nameof(maxSize), $"{nameof(maxSize)} must be greater than 0 and less than int.MaxValue"); | |
} |
and you can also verify this message in the test.
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.
Added changes with more details message for exception
throw new ArgumentOutOfRangeException(nameof(incrementHeadersBy), $"{nameof(incrementHeadersBy)} must be greater than or equal to 0"); |
test:
public void ThrowsArgumentOutOfRangeExceptionForNegativeIncrementHeadersBy(int incrementHeadersBy) |
[Theory]
[InlineData(-1)]
public void ThrowsArgumentOutOfRangeExceptionForNegativeIncrementHeadersBy(int incrementHeadersBy)
{
var exception = Assert.Throws<ArgumentOutOfRangeException>(() => _markdownService.GetHtmlFromMarkdown("markdown file test", incrementHeadersBy));
Assert.Equal(nameof(incrementHeadersBy), exception.ParamName);
Assert.Contains("must be greater than or equal to 0", exception.Message);
}
Update markdig with latest version to have all new features
Update markdig to latest version 0.22.0
New extension added:
table, tasklist, autolink, emoji
Feature flag was added
Below showed the table, autolink, emoji render difference with two libs
Old CommonMark render:
New Markdig render:
Details comparison about Markdig and CommonMark, please check out OneNote: Markdig vs CommonMark
Addresses https://github.com/NuGet/Engineering/issues/3429