Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,16 @@ private static string HumanizeMultilineCodeTags(this string text)

private static string HumanizeParaTags(this string text)
{
return ParaTag().Replace(text, (match) => "<br>" + match.Groups["display"].Value);
return ParaTag().Replace(text, match =>
{
var paraText = "<br>" + match.Groups["display"].Value.Trim();
return LineBreaks().Replace(paraText, _ => string.Empty);
});
}

private static string HumanizeBrTags(this string text)
{
return BrTag().Replace(text, m => Environment.NewLine);
return BrTag().Replace(text, _ => Environment.NewLine);
Comment thread
martincostello marked this conversation as resolved.
}

private static string DecodeXml(this string text)
Expand All @@ -125,6 +129,7 @@ private static string DecodeXml(this string text)
private const string ParaTagPattern = @"<para>(?<display>.+?)</para>";
private const string HrefPattern = @"<see href=\""(.*)\"">(.*)<\/see>";
private const string BrPattern = @"(<br ?\/?>)"; // handles <br>, <br/>, <br />
private const string LineBreaksPattern = @"\r\n?|\n";
Comment thread
martincostello marked this conversation as resolved.
Outdated

#if NET7_0_OR_GREATER
[GeneratedRegex(RefTagPattern)]
Expand All @@ -144,20 +149,25 @@ private static string DecodeXml(this string text)

[GeneratedRegex(BrPattern)]
private static partial Regex BrTag();

[GeneratedRegex(LineBreaksPattern)]
private static partial Regex LineBreaks();
#else
private static readonly Regex _refTag = new(RefTagPattern);
private static readonly Regex _codeTag = new(CodeTagPattern);
private static readonly Regex _multilineCodeTag = new(MultilineCodeTagPattern, RegexOptions.Singleline);
private static readonly Regex _paraTag = new(ParaTagPattern, RegexOptions.Singleline);
private static readonly Regex _hrefTag = new(HrefPattern);
private static readonly Regex _brTag = new(BrPattern);
private static readonly Regex _lineBreaks = new(LineBreaksPattern);

private static Regex RefTag() => _refTag;
private static Regex CodeTag() => _codeTag;
private static Regex MultilineCodeTag() => _multilineCodeTag;
private static Regex ParaTag() => _paraTag;
private static Regex HrefTag() => _hrefTag;
private static Regex BrTag() => _brTag;
private static Regex LineBreaks() => _lineBreaks;
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@
"CrudActions"
],
"summary": "Updates some properties of a specific product",
"description": "\r\nOnly provided properties will be updated, other remain unchanged.\r\n\r\nIdentifier must be non-default value\r\n\r\nBody must be specified",
"operationId": "PatchProduct",
"parameters": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@
"CrudActions"
],
"summary": "Updates some properties of a specific product",
"description": "\r\nOnly provided properties will be updated, other remain unchanged.\r\n\r\nIdentifier must be non-default value\r\n\r\nBody must be specified",
"operationId": "PatchProduct",
"parameters": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ Misplaced Tab Indentation
[InlineData("<c>DoWork</c> is a method in <c>TestClass</c>.", "`DoWork` is a method in `TestClass`.")]
[InlineData("<code>DoWork</code> is a method in <code>\nTestClass\n</code>.", "```DoWork``` is a method in ```\nTestClass\n```.")]
[InlineData("<para>This is a paragraph</para>.", "\r\nThis is a paragraph.")]
[InlineData("<para> This is a paragraph </para>.", "\r\nThis is a paragraph.")]
Comment thread
martincostello marked this conversation as resolved.
[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)")]
Expand All @@ -141,5 +142,20 @@ public void Humanize_HumanizesInlineTags(

Assert.Equal(expectedOutput, output, false, true);
}

[Fact]
public void Humanize_ParaMultiLineTags()
{
const string input = @"
<para>
This is a paragraph.
MultiLined.
</para>
<para> This is a paragraph </para>.";

var output = XmlCommentsTextHelper.Humanize(input);

Assert.Equal("\r\nThis is a paragraph. MultiLined.\r\nThis is a paragraph.", output, false, true);
}
}
}
10 changes: 9 additions & 1 deletion test/WebSites/Basic/Controllers/CrudActionsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ public void Update(int id, [FromBody, Required]Product product)
/// <summary>
/// Updates some properties of a specific product
/// </summary>
/// <remarks>
Comment thread
martincostello marked this conversation as resolved.
/// <para>
/// Only provided properties will be updated,
/// other remain unchanged.
/// </para>
/// <para> Identifier must be non-default value </para>
/// <para>Body must be specified</para>
/// </remarks>
/// <param name="id" example="333"></param>
/// <param name="updates"></param>
[HttpPatch("{id}", Name = "PatchProduct")]
Expand Down Expand Up @@ -114,4 +122,4 @@ public class Product

public ProductStatus? Status2 { get; set; }
}
}
}