Skip to content

Commit 9818323

Browse files
fix: enum summaries correctly format with rich information (#25)
1 parent b4c00a2 commit 9818323

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

docs/sample/myclasslib.myenum.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Implements [IComparable](https://docs.microsoft.com/en-us/dotnet/api/system.icom
1919

2020
| Name | Value | Description |
2121
| --- | --: | --- |
22-
| Default | 0 | The default. |
22+
| Default | 0 | The default value for [MyEnum](./myclasslib.myenum). This is additional information. |
2323
| First | 1 | The first. |
2424
| Second | 2 | The second. |
2525

sample/MyClassLib/MyEnum.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ namespace MyClassLib
66
public enum MyEnum
77
{
88
/// <summary>
9-
/// The default.
9+
/// The default value for <see cref="MyEnum"/>.
10+
/// This is additional information.
1011
/// </summary>
1112
Default = 0,
1213

src/XMLDoc2Markdown/TypeDocumentation.cs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.IO;
44
using System.Linq;
55
using System.Reflection;
6+
using System.Text;
67
using System.Text.RegularExpressions;
78
using System.Xml.Linq;
89
using Markdown;
@@ -454,14 +455,38 @@ private void WriteEnumFields(IEnumerable<FieldInfo> fields)
454455

455456
foreach (FieldInfo field in fields)
456457
{
457-
string paramDoc = this.documentation.GetMember(field)?.Element("summary")?.Value ?? String.Empty;
458-
table.AddRow(new MarkdownTableRow(field.Name, ((Enum)Enum.Parse(this.type, field.Name)).ToString("D"), paramDoc.Trim()));
458+
IEnumerable<XNode> nodes = this.documentation.GetMember(field)?.Element("summary")?.Nodes();
459+
if (nodes == null)
460+
{
461+
continue;
462+
}
463+
464+
MarkdownParagraph summary = this.XNodesToMarkdownParagraph(nodes);
465+
string formattedSummary = TableFormat(summary.ToString());
466+
467+
table.AddRow(new MarkdownTableRow(field.Name, ((Enum)Enum.Parse(this.type, field.Name)).ToString("D"), formattedSummary));
459468
}
460469

461470
this.document.Append(table);
462471
}
463472
}
464473

474+
private static string TableFormat(string input)
475+
{
476+
input = input.Replace("\r\n", "\n");
477+
StringBuilder sb = new(input.Length);
478+
479+
foreach (string line in input.Split("\n"))
480+
{
481+
if (!string.IsNullOrWhiteSpace(line))
482+
{
483+
sb.Append(line);
484+
}
485+
}
486+
487+
return sb.ToString();
488+
}
489+
465490
private bool WriteExample(MemberInfo memberInfo)
466491
{
467492
if (this.options.ExamplesDirectory == null)

0 commit comments

Comments
 (0)