Skip to content

Commit b34ad70

Browse files
committed
Support extracting markdown from <remarks>, and parse <img src="" /> to markdown.
1 parent c893736 commit b34ad70

3 files changed

Lines changed: 16 additions & 11 deletions

File tree

markdowngen/DTOs.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public class Item
3939
public string[]? InheritedMembers { get; set; }
4040

4141
public string[] ExtensionMethods { get; set; }
42+
public string Remarks { get; set; }
4243
// modifiers.csharp
4344
// modifiers.vb
4445
}

markdowngen/Program.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ await Parallel.ForEachAsync(items, async (kvp, _) =>
7878
str.AppendLine("sidebar_label: " + item.Name);
7979
if (item.Summary != null)
8080
// todo: run a regex replace to get rid of hyperlinks and inline code blocks?
81-
str.AppendLine($"description: \"{items.GetSummary(item.Summary)?.Trim().Replace("\"", "\\\"")}\"");
81+
str.AppendLine($"description: \"{item.GetSummary(items,item.Summary)?.Trim().Replace("\"", "\\\"")}\"");
8282
str.AppendLine("---");
8383
str.AppendLine();
8484
if (config.UseIconify)
@@ -88,7 +88,7 @@ await Parallel.ForEachAsync(items, async (kvp, _) =>
8888
}
8989

9090
str.AppendLine(item.WithIconifyHeading("# "));
91-
str.AppendLine(items.GetSummary(item.Summary)?.Trim());
91+
str.AppendLine(item.GetSummary(items,item.Summary)?.Trim());
9292
str.AppendLine();
9393
str.AppendLine($"###### **Assembly**: {item.Assemblies[0]}.dll");
9494
MarkdownWritingExtensions.Declaration(str, item);
@@ -103,7 +103,7 @@ await Parallel.ForEachAsync(items, async (kvp, _) =>
103103
str.AppendLine(property.WithIconifyHeading());
104104
else
105105
str.AppendLine($"### {property.Name}");
106-
str.AppendLine(items.GetSummary(property.Summary)?.Trim());
106+
str.AppendLine(item.GetSummary(items,property.Summary)?.Trim());
107107
MarkdownWritingExtensions.Declaration(str, property);
108108
}
109109
}
@@ -119,7 +119,7 @@ await Parallel.ForEachAsync(items, async (kvp, _) =>
119119
str.AppendLine(property.WithIconifyHeading());
120120
else
121121
str.AppendLine($"### {property.Name}");
122-
str.AppendLine(items.GetSummary(property.Summary)?.Trim());
122+
str.AppendLine(item.GetSummary(items,property.Summary)?.Trim());
123123
MarkdownWritingExtensions.Declaration(str, property);
124124
}
125125
}
@@ -133,7 +133,7 @@ await Parallel.ForEachAsync(items, async (kvp, _) =>
133133
foreach (var field in fields)
134134
{
135135
str.AppendLine(config.UseIconify ? field.WithIconifyHeading() : $"### {field.Name}");
136-
str.AppendLine(items.GetSummary(field.Summary)?.Trim());
136+
str.AppendLine(item.GetSummary(items,field.Summary)?.Trim());
137137
MarkdownWritingExtensions.Declaration(str, field);
138138
}
139139
}
@@ -168,7 +168,7 @@ await Parallel.ForEachAsync(items, async (kvp, _) =>
168168
foreach (var @event in events)
169169
{
170170
str.AppendLine($"### {@event.Name.HtmlEscape()}");
171-
str.AppendLine(items.GetSummary(@event.Summary)?.Trim());
171+
str.AppendLine(item.GetSummary(items,@event.Summary)?.Trim());
172172
MarkdownWritingExtensions.Declaration(str, @event);
173173
str.AppendLine("##### Event Type");
174174
if (@event.Syntax.Return.Description == null)
@@ -219,7 +219,7 @@ void Do(string type, string header)
219219
foreach (var item1 in @where.OrderBy(i => i.Name))
220220
{
221221
str.AppendLine($"### {items.Link(item1.Uid, config, true)}");
222-
str.AppendLine(items.GetSummary(item1.Summary)?.Trim());
222+
str.AppendLine(item.GetSummary(items,item1.Summary)?.Trim());
223223
}
224224
}
225225
}

markdowngen/Utils.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public static class MarkdownWritingExtensions
8080

8181
static Regex codeRegex = new("<code>(.+?)</code>", RegexOptions.Compiled);
8282
static Regex linkRegex = new("<a href=\"(.+?)\">(.+?)</a>", RegexOptions.Compiled);
83+
static Regex imgRegex = new ("<img src=[\"'](.+?)[\"'].*?>", RegexOptions.Compiled);
8384

8485
private static List<string> csharpKeywords = new()
8586
{
@@ -176,7 +177,7 @@ public static string Link(this Dictionary<string, Item> items, string uid, Confi
176177
return result;
177178
}
178179

179-
public static string? GetSummary(this Dictionary<string, Item> items, string? summary)
180+
public static string? GetSummary(this Item item, Dictionary<string, Item> items, string? summary)
180181
{
181182
if (summary == null)
182183
return null;
@@ -188,6 +189,9 @@ public static string Link(this Dictionary<string, Item> items, string uid, Confi
188189
summary = langwordXrefRegex.Replace(summary, match => $"`{match.Groups[1].Value}`");
189190
summary = codeRegex.Replace(summary, match => $"`{match.Groups[1].Value}`");
190191
summary = linkRegex.Replace(summary, match => $"[{match.Groups[2].Value}]({match.Groups[1].Value})");
192+
summary = imgRegex.Replace(summary, match => $"![]({match.Groups[1].Value})");
193+
194+
summary += $"\n{item.Remarks}\n";
191195

192196
return summary.HtmlEscape();
193197
}
@@ -213,7 +217,7 @@ public static void MethodSummary(this Dictionary<string, Item> items, StringBuil
213217
str.AppendLine(method.WithIconifyHeading());
214218
else
215219
str.AppendLine($"### {method.Name.HtmlEscape()}");
216-
str.AppendLine(items.GetSummary(method.Summary)?.Trim());
220+
str.AppendLine(method.GetSummary(items,method.Summary)?.Trim());
217221
Declaration(str, method);
218222
if (!string.IsNullOrWhiteSpace(method.Syntax.Return?.Type))
219223
{
@@ -224,7 +228,7 @@ public static void MethodSummary(this Dictionary<string, Item> items, StringBuil
224228
if (string.IsNullOrWhiteSpace(method.Syntax.Return?.Description))
225229
str.AppendLine();
226230
else
227-
str.Append(": " + items.GetSummary(method.Syntax.Return.Description));
231+
str.Append(": " + method.GetSummary(items, method.Syntax.Return.Description));
228232
}
229233

230234
if ((method.Syntax?.Parameters?.Length ?? 0) != 0)
@@ -238,7 +242,7 @@ public static void MethodSummary(this Dictionary<string, Item> items, StringBuil
238242
str.AppendLine("|:--- |:--- |:--- |");
239243
foreach (var parameter in method.Syntax.Parameters)
240244
str.AppendLine(
241-
$"| {items.Link(parameter.Type)} | *{parameter.Id}* | {items.GetSummary(parameter.Description)} |");
245+
$"| {items.Link(parameter.Type)} | *{parameter.Id}* | {method.GetSummary(items,parameter.Description)} |");
242246
}
243247
else
244248
{

0 commit comments

Comments
 (0)