Skip to content

Commit e5b6a0d

Browse files
net8.0 and list support (#34) +semver: major
1 parent 58bbe31 commit e5b6a0d

File tree

10 files changed

+107
-22
lines changed

10 files changed

+107
-22
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,3 +327,7 @@ ASALocalRun/
327327

328328
# MFractors (Xamarin productivity tool) working folder
329329
.mfractor/
330+
331+
332+
# output
333+
out/

.vscode/extensions.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
{
22
"recommendations": [
3-
"ms-dotnettools.csharp",
43
"editorconfig.editorconfig",
5-
"k--kato.docomment",
6-
"formulahendry.dotnet-test-explorer",
4+
"ms-dotnettools.csdevkit",
75
"redhat.vscode-yaml"
86
]
97
}

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2022 Charles de Vandière
3+
Copyright (c) 2024 Charles de Vandière
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

docs/sample/myclasslib.myclass.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ if (true)
8787
}
8888
```
8989

90+
- **item 1** - The first item. `1`
91+
- **item 2** - The second item. `2`
92+
9093
### **MyClass(String, Int32)**
9194

9295
Initializes a new instance of the [MyClass](./myclasslib.myclass) class.

docs/sample/myclasslib.myenum.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public enum MyEnum
1313
```
1414

1515
Inheritance [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object) → [ValueType](https://docs.microsoft.com/en-us/dotnet/api/system.valuetype) → [Enum](https://docs.microsoft.com/en-us/dotnet/api/system.enum) → [MyEnum](./myclasslib.myenum)<br>
16-
Implements [IComparable](https://docs.microsoft.com/en-us/dotnet/api/system.icomparable), [IFormattable](https://docs.microsoft.com/en-us/dotnet/api/system.iformattable), [IConvertible](https://docs.microsoft.com/en-us/dotnet/api/system.iconvertible)
16+
Implements [IComparable](https://docs.microsoft.com/en-us/dotnet/api/system.icomparable), [ISpanFormattable](https://docs.microsoft.com/en-us/dotnet/api/system.ispanformattable), [IFormattable](https://docs.microsoft.com/en-us/dotnet/api/system.iformattable), [IConvertible](https://docs.microsoft.com/en-us/dotnet/api/system.iconvertible)
1717

1818
## Fields
1919

generate-sample-doc.bat

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
@echo off
2-
dotnet build
3-
.\src\XMLDoc2Markdown\bin\Debug\net6.0\XMLDoc2Markdown.exe .\sample\MyClassLib\bin\Debug\netstandard2.0\MyClassLib.dll .\docs\sample --examples-path .\sample\docs\examples --github-pages --back-button
2+
3+
dotnet build -o ./out
4+
5+
./out/XMLDoc2Markdown.exe ./out/MyClassLib.dll ./docs/sample --examples-path ./sample/docs/examples --github-pages --back-button

generate-sample-doc.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
rm -rf ./out
4+
5+
dotnet build -o ./out
6+
7+
./out/XMLDoc2Markdown ./out/MyClassLib.dll ./docs/sample --examples-path ./sample/docs/examples --github-pages --back-button

sample/MyClassLib/MyClass.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,16 @@ public class MyClass : IMyInterface
7171
/// Console.WriteLine(foo.ToString());
7272
/// }
7373
/// </code>
74+
/// <list type="bullet">
75+
/// <item>
76+
/// <term>item 1</term>
77+
/// <description>The first item. <c>1</c></description>
78+
/// </item>
79+
/// <item>
80+
/// <term>item 2</term>
81+
/// <description>The second item. <c>2</c></description>
82+
/// </item>
83+
/// </list>
7484
/// </remarks>
7585
public MyClass()
7686
{ }
@@ -110,15 +120,6 @@ public void Do(string firstParam, int secondParam)
110120
public int DoGeneric<T>(T value)
111121
{ throw new ArgumentException(); }
112122

113-
/// <summary>
114-
/// Do some thing.
115-
/// </summary>
116-
/// <typeparam name="T">The type argument. Used by <see cref="DoGeneric{T}(T)"/>.</typeparam>
117-
/// <param name="value">The param. Used by <see cref="DoGeneric{T}(T)"/>.</param>
118-
/// <returns>Returns a value <see cref="int"/>.</returns>
119-
/// <exception cref="ArgumentException">Thrown instead of <see cref="Exception"/>.</exception>
120-
public int DoGeneric<T>(T value) { throw new ArgumentException(); }
121-
122123
/// <summary>
123124
/// Gets some thing.
124125
/// </summary>

src/XMLDoc2Markdown/TypeDocumentation.cs

Lines changed: 73 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ private void WriteMemberInfoRemarks(XElement memberDocElement)
194194
}
195195
}
196196

197-
private MarkdownTextElement XElementToMarkdown(XElement element)
197+
private object XElementToMarkdown(XElement element)
198198
{
199199
return element.Name.ToString() switch
200200
{
@@ -205,6 +205,7 @@ private MarkdownTextElement XElementToMarkdown(XElement element)
205205
"para" => this.XNodesToMarkdownParagraph(element.Nodes()),
206206
"example" => this.XNodesToMarkdownParagraph(element.Nodes()),
207207
"code" => new MarkdownCode("csharp", TypeDocumentation.FormatCodeElementValue(element.Value)),
208+
"list" => this.XElementToMarkdownList(element),
208209
_ => new MarkdownText(element.Value)
209210
};
210211
}
@@ -268,7 +269,7 @@ private MarkdownParagraph XNodesToMarkdownParagraph(IEnumerable<XNode> nodes)
268269

269270
foreach (XNode node in nodes)
270271
{
271-
MarkdownTextElement element = this.XNodeToMarkdown(node);
272+
object element = this.XNodeToMarkdown(node);
272273
if (element is null)
273274
{
274275
continue;
@@ -305,7 +306,76 @@ private MarkdownParagraph XNodesToMarkdownParagraph(IEnumerable<XNode> nodes)
305306
return new MarkdownParagraph(string.Join(Environment.NewLine, blocks));
306307
}
307308

308-
private MarkdownTextElement XNodeToMarkdown(XNode node)
309+
private MarkdownList XElementToMarkdownList(XElement element)
310+
{
311+
MarkdownList markdownList = element.Attribute("type")?.Value switch
312+
{
313+
"number" => new MarkdownOrderedList(),
314+
_ => new MarkdownList()
315+
};
316+
317+
foreach (XElement item in element.Elements("item"))
318+
{
319+
MarkdownText markdownListItem = new(string.Empty);
320+
321+
IEnumerable<XNode> term = item.Element("term").Nodes();
322+
323+
MarkdownText markdownTerm = null;
324+
325+
foreach (XNode node in term)
326+
{
327+
object md = this.XNodeToMarkdown(node);
328+
if (md is MarkdownInlineElement inlineElement)
329+
{
330+
if (markdownTerm is null)
331+
{
332+
markdownTerm = new MarkdownText(inlineElement);
333+
}
334+
else
335+
{
336+
markdownTerm.Append(inlineElement);
337+
}
338+
}
339+
}
340+
341+
if (markdownTerm is not null)
342+
{
343+
markdownListItem.Append(new MarkdownStrongEmphasis(markdownTerm));
344+
}
345+
346+
IEnumerable<XNode> description = item.Element("description").Nodes();
347+
348+
MarkdownText markdownDescription = null;
349+
350+
foreach (XNode node in description)
351+
{
352+
object md = this.XNodeToMarkdown(node);
353+
if (md is MarkdownInlineElement inlineElement)
354+
{
355+
if (markdownDescription is null)
356+
{
357+
markdownDescription = new MarkdownText(inlineElement);
358+
}
359+
else
360+
{
361+
markdownDescription.Append(inlineElement);
362+
}
363+
}
364+
}
365+
366+
if (markdownDescription is not null)
367+
{
368+
markdownListItem.Append(" - ");
369+
markdownListItem.Append(markdownDescription);
370+
}
371+
372+
markdownList.AddItem(markdownListItem);
373+
}
374+
375+
return markdownList;
376+
}
377+
378+
private object XNodeToMarkdown(XNode node)
309379
{
310380
return node switch
311381
{

src/XMLDoc2Markdown/XMLDoc2Markdown.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net6.0</TargetFramework>
5+
<TargetFramework>net8.0</TargetFramework>
66
<LangVersion>latest</LangVersion>
77
<Version>0.0.0</Version>
88
<ToolCommandName>xmldoc2md</ToolCommandName>
99
<PackAsTool>true</PackAsTool>
1010
<IsPackable>true</IsPackable>
1111

1212
<Authors>Charles de Vandière</Authors>
13-
<Copyright2022 Charles de Vandière</Copyright>
13+
<Copyright2024 Charles de Vandière</Copyright>
1414
<Product>XMLDoc2Markdown</Product>
1515
<Title>XMLDoc2Markdown</Title>
1616
<Description>Tool to generate markdown from C# XML documentation.</Description>
@@ -40,7 +40,7 @@
4040
<ItemGroup>
4141
<PackageReference Include="MarkdownBuilder" Version="0.2.0" />
4242
<PackageReference Include="Microsoft.Extensions.CommandLineUtils" Version="1.1.1" />
43-
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All"/>
43+
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All"/>
4444
</ItemGroup>
4545

4646
</Project>

0 commit comments

Comments
 (0)