Skip to content

Commit

Permalink
support multiple summaries for member documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidVollmers committed Jun 22, 2024
1 parent 54c74cd commit 39b27f3
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 46 deletions.
51 changes: 39 additions & 12 deletions src/Doki.Output.Markdown/MarkdownOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,14 @@ public async Task WriteAsync(TypeDocumentation typeDocumentation, CancellationTo

markdown.Add(Element.Separator);

if (typeDocumentation.Summary != null)
if (typeDocumentation.Summaries.Length != 0)
{
var summary = markdown.BuildText(typeDocumentation.Summary);
summary.IsBold = true;
markdown.Add(summary);
foreach (var summary in typeDocumentation.Summaries)
{
var text = markdown.BuildText(summary);
text.IsBold = true;
markdown.Add(text);
}
}

markdown.Add(new Code(typeDocumentation.Definition));
Expand Down Expand Up @@ -209,8 +212,14 @@ public async Task WriteAsync(TypeDocumentation typeDocumentation, CancellationTo
var table = new Table(new Text(" "), new Text("Summary"));
foreach (var constructor in typeDocumentation.Constructors)
{
table.AddRow(new Text(constructor.Name),
constructor.Summary == null ? Text.Empty : markdown.BuildText(constructor.Summary));
var text = Text.Empty;
foreach (var summary in constructor.Summaries)
{
text.Append(markdown.BuildText(summary));
text.NewLine();
}

table.AddRow(new Text(constructor.Name), text);
}

markdown.Add(table);
Expand All @@ -223,8 +232,14 @@ public async Task WriteAsync(TypeDocumentation typeDocumentation, CancellationTo
var table = new Table(new Text(" "), new Text("Summary"));
foreach (var field in typeDocumentation.Fields)
{
table.AddRow(new Text(field.Name),
field.Summary == null ? Text.Empty : markdown.BuildText(field.Summary));
var text = Text.Empty;
foreach (var summary in field.Summaries)
{
text.Append(markdown.BuildText(summary));
text.NewLine();
}

table.AddRow(new Text(field.Name), text);
}

markdown.Add(table);
Expand All @@ -237,8 +252,14 @@ public async Task WriteAsync(TypeDocumentation typeDocumentation, CancellationTo
var table = new Table(new Text(" "), new Text("Summary"));
foreach (var property in typeDocumentation.Properties)
{
table.AddRow(new Text(property.Name),
property.Summary == null ? Text.Empty : markdown.BuildText(property.Summary));
var text = Text.Empty;
foreach (var summary in property.Summaries)
{
text.Append(markdown.BuildText(summary));
text.NewLine();
}

table.AddRow(new Text(property.Name), text);
}

markdown.Add(table);
Expand All @@ -251,8 +272,14 @@ public async Task WriteAsync(TypeDocumentation typeDocumentation, CancellationTo
var table = new Table(new Text(" "), new Text("Summary"));
foreach (var method in typeDocumentation.Methods)
{
table.AddRow(new Text(method.Name),
method.Summary == null ? Text.Empty : markdown.BuildText(method.Summary));
var text = Text.Empty;
foreach (var summary in method.Summaries)
{
text.Append(markdown.BuildText(summary));
text.NewLine();
}

table.AddRow(new Text(method.Name), text);
}

markdown.Add(table);
Expand Down
72 changes: 38 additions & 34 deletions tests/Doki.Output.Json.Tests/JsonOutputTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public class ExampleClass : AbstractClass {}
Assert.Equal("Object", typeDocumentation.BaseType.Name);
Assert.Equal("System", typeDocumentation.BaseType.Namespace);
Assert.Equal("System.Private.CoreLib", typeDocumentation.BaseType.Assembly);
Assert.Null(typeDocumentation.BaseType.Summary);
Assert.Empty(typeDocumentation.BaseType.Summaries);
Assert.Equal(DocumentationContentType.TypeReference, typeDocumentation.BaseType.ContentType);
Assert.Equal("System.Object", typeDocumentation.BaseType.Id);

Expand All @@ -113,45 +113,49 @@ public class ExampleClass : AbstractClass {}
memberDocumentation.Namespace);
Assert.Equal("Doki.TestAssembly.InheritanceChain.Abstractions",
memberDocumentation.Assembly);
Assert.Null(memberDocumentation.Summary);
Assert.Empty(memberDocumentation.Summaries);
Assert.Equal(DocumentationContentType.Constructor, memberDocumentation.ContentType);
Assert.Equal("Doki.TestAssembly.InheritanceChain.Abstractions.AbstractClass.#ctor",
memberDocumentation.Id);
});

Assert.NotNull(typeDocumentation.Summary);
Assert.Equal("summary", typeDocumentation.Summary.Name);
Assert.Equal("summary", typeDocumentation.Summary.Id);
Assert.Equal(DocumentationContentType.Xml, typeDocumentation.Summary.ContentType);
Assert.Collection(typeDocumentation.Summary.Contents,
documentationObject =>
Assert.Collection(typeDocumentation.Summaries,
summary =>
{
Assert.NotNull(documentationObject);
Assert.IsType<TextContent>(documentationObject);
var textContent = (TextContent)documentationObject;
Assert.Equal("This is an abstract class. See", textContent.Text);
Assert.Equal(DocumentationContentType.Text, documentationObject.ContentType);
Assert.Equal("text", documentationObject.Id);
},
documentationObject =>
{
Assert.NotNull(documentationObject);
Assert.IsType<TypeDocumentationReference>(documentationObject);
var typeDocumentationReference = (TypeDocumentationReference)documentationObject;
Assert.False(typeDocumentationReference.IsGeneric);
Assert.Equal("Doki.TestAssembly.InheritanceChain.Abstractions.AbstractClass",
typeDocumentationReference.FullName);
Assert.True(typeDocumentationReference.IsDocumented);
Assert.False(typeDocumentationReference.IsMicrosoft);
},
documentationObject =>
{
Assert.NotNull(documentationObject);
Assert.IsType<TextContent>(documentationObject);
var textContent = (TextContent)documentationObject;
Assert.Equal("for more information.", textContent.Text);
Assert.Equal(DocumentationContentType.Text, documentationObject.ContentType);
Assert.Equal("text", documentationObject.Id);
Assert.Equal("summary", summary.Name);
Assert.Equal("summary", summary.Id);
Assert.Equal(DocumentationContentType.Xml, summary.ContentType);
Assert.Collection(summary.Contents,
documentationObject =>
{
Assert.NotNull(documentationObject);
Assert.IsType<TextContent>(documentationObject);
var textContent = (TextContent)documentationObject;
Assert.Equal("This is an abstract class. See", textContent.Text);
Assert.Equal(DocumentationContentType.Text, documentationObject.ContentType);
Assert.Equal("text", documentationObject.Id);
},
documentationObject =>
{
Assert.NotNull(documentationObject);
Assert.IsType<TypeDocumentationReference>(documentationObject);
var typeDocumentationReference =
(TypeDocumentationReference)documentationObject;
Assert.False(typeDocumentationReference.IsGeneric);
Assert.Equal("Doki.TestAssembly.InheritanceChain.Abstractions.AbstractClass",
typeDocumentationReference.FullName);
Assert.True(typeDocumentationReference.IsDocumented);
Assert.False(typeDocumentationReference.IsMicrosoft);
},
documentationObject =>
{
Assert.NotNull(documentationObject);
Assert.IsType<TextContent>(documentationObject);
var textContent = (TextContent)documentationObject;
Assert.Equal("for more information.", textContent.Text);
Assert.Equal(DocumentationContentType.Text, documentationObject.ContentType);
Assert.Equal("text", documentationObject.Id);
});
});
});
});
Expand Down

0 comments on commit 39b27f3

Please sign in to comment.