Skip to content

Commit

Permalink
Use Markdown link format for see href tags (#2392)
Browse files Browse the repository at this point in the history
Resolves #2577.
  • Loading branch information
mburumaxwell authored Apr 15, 2024
1 parent 0108842 commit 45a2cb7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public static class XmlCommentsTextHelper
private static Regex CodeTagPattern = new Regex(@"<c>(?<display>.+?)</c>");
private static Regex MultilineCodeTagPattern = new Regex(@"<code>(?<display>.+?)</code>", RegexOptions.Singleline);
private static Regex ParaTagPattern = new Regex(@"<para>(?<display>.+?)</para>", RegexOptions.Singleline);
private static Regex HrefPattern = new(@"<see href=\""(.*)\"">(.*)<\/see>");

public static string Humanize(string text)
{
Expand All @@ -22,6 +23,7 @@ public static string Humanize(string text)
return text
.NormalizeIndentation()
.HumanizeRefTags()
.HumanizeHrefTags()
.HumanizeCodeTags()
.HumanizeMultilineCodeTags()
.HumanizeParaTags()
Expand Down Expand Up @@ -92,6 +94,11 @@ private static string HumanizeRefTags(this string text)
return RefTagPattern.Replace(text, (match) => match.Groups["display"].Value);
}

private static string HumanizeHrefTags(this string text)
{
return HrefPattern.Replace(text, m => $"[{m.Groups[2].Value}]({m.Groups[1].Value})");
}

private static string HumanizeCodeTags(this string text)
{
return CodeTagPattern.Replace(text, (match) => "`" + match.Groups["display"].Value + "`");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ Misplaced Tab Indentation
[InlineData("<para>This is a paragraph</para>.", "<br>This is a paragraph.")]
[InlineData("GET /Todo?iscomplete=true&amp;owner=mike", "GET /Todo?iscomplete=true&owner=mike")]
[InlineData(@"Returns a <see langword=""null""/> item.", "Returns a null item.")]
[InlineData(@"<see href=""https://www.iso.org/iso-4217-currency-codes.html"">ISO currency code</see>", "[ISO currency code](https://www.iso.org/iso-4217-currency-codes.html)")]
public void Humanize_HumanizesInlineTags(
string input,
string expectedOutput)
Expand Down

0 comments on commit 45a2cb7

Please sign in to comment.