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

Markdig version update #8292

Merged
merged 22 commits into from
Dec 11, 2020
Merged

Markdig version update #8292

merged 22 commits into from
Dec 11, 2020

Conversation

lyndaidaii
Copy link
Contributor

@lyndaidaii lyndaidaii commented Oct 23, 2020

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:
NuGet Gallery _ Manage Package ReadmeWithURLTest33

New Markdig render:
NuGet Gallery _ Manage Package xiaodaidaitest

Details comparison about Markdig and CommonMark, please check out OneNote: Markdig vs CommonMark

Addresses https://github.com/NuGet/Engineering/issues/3429

Copy link
Contributor

@loic-sharma loic-sharma left a 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

@lyndaidaii
Copy link
Contributor Author

lyndaidaii commented Oct 27, 2020

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)

@joelverhagen
Copy link
Member

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.

@lyndaidaii
Copy link
Contributor Author

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)
{
Copy link
Contributor

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)
Copy link
Contributor

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?

Copy link
Contributor Author

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);
Copy link
Contributor

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.
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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>&lt;text&gt;Blockquote&lt;/text&gt;</p>\n</blockquote>", false, true)]
[InlineData("> <text>Blockquote</text>", "<blockquote>\r\n<p>&lt;text&gt;Blockquote&lt;/text&gt;</p>\r\n</blockquote>", 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.

I am not very sure but it may be helpful to have a test case of "Nested Blockquotes".

Copy link
Contributor Author

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()
Copy link
Contributor

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));
Copy link
Contributor

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:

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.

Copy link
Contributor Author

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);
            }

@lyndaidaii lyndaidaii merged commit b84ca7d into dev Dec 11, 2020
@zhhyu zhhyu mentioned this pull request Jan 28, 2021
17 tasks
@joelverhagen joelverhagen deleted the markdig-version-update branch August 22, 2024 16:25
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.

6 participants