Skip to content

Commit 69da41e

Browse files
committed
feat: add markdown parsing, virtual methods for
html export
1 parent 7cc529a commit 69da41e

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

extensions/Sisk.Documenting.Html/HtmlDocumentationExporter.cs

+21-11
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ namespace Sisk.Documenting.Html;
1212
/// </summary>
1313
public class HtmlDocumentationExporter : IApiDocumentationExporter {
1414

15+
/// <summary>
16+
/// Creates an new instance of the <see cref="HtmlDocumentationExporter"/> class.
17+
/// </summary>
18+
public HtmlDocumentationExporter () {
19+
}
20+
1521
/// <summary>
1622
/// Gets or sets the title of the HTML page.
1723
/// </summary>
@@ -63,23 +69,29 @@ public class HtmlDocumentationExporter : IApiDocumentationExporter {
6369
public string FormatRequiredText { get; set; } = "Required";
6470

6571
/// <summary>
66-
/// Gets or sets an optional object to append to the footer
67-
/// of the generated page.
72+
/// Gets or sets an optional object to append after the generated contents, right at the end of the <c>&lt;main&gt;</c>
73+
/// tag of the generated page.
6874
/// </summary>
6975
public object? Footer { get; set; }
7076

7177
/// <summary>
72-
/// Gets or sets an optional object to append to the header
73-
/// of the generated page.
78+
/// Gets or sets an optional object to append after the main title, at the beginning of the <c>&lt;main&gt;</c>
79+
/// tag of the generated page.
7480
/// </summary>
7581
public object? Header { get; set; }
7682

83+
/// <summary>
84+
/// Gets or sets an optional object to append inside the <c>&lt;head&gt;</c>
85+
/// tag of the generated page.
86+
/// </summary>
87+
public object? Head { get; set; }
88+
7789
/// <summary>
7890
/// Writes the main title of the API documentation.
7991
/// </summary>
8092
/// <param name="documentation">The API documentation to write the title for.</param>
8193
/// <returns>The HTML element representing the main title.</returns>
82-
protected virtual HtmlElement WriteMainTitle ( ApiDocumentation documentation ) {
94+
protected virtual HtmlElement? WriteMainTitle ( ApiDocumentation documentation ) {
8395
return HtmlElement.Fragment ( fragment => {
8496
fragment += new HtmlElement ( "h1", documentation.ApplicationName ?? "Application name" )
8597
.WithClass ( "app-title" );
@@ -108,6 +120,8 @@ protected virtual HtmlElement WriteMainTitle ( ApiDocumentation documentation )
108120
details += new HtmlElement ( "h3", endpoint.Name );
109121
details += this.CreateParagraphs ( endpoint.Description );
110122

123+
details += this.CreateCodeBlock ( $"{endpoint.RouteMethod.ToString ().ToUpper ()} {endpoint.Path}", null );
124+
111125
if (endpoint.Headers.Length > 0) {
112126
details += new HtmlElement ( "div", div => {
113127
div += new HtmlElement ( "p", this.FormatEndpointHeaders );
@@ -251,15 +265,11 @@ protected virtual HtmlElement WriteMainTitle ( ApiDocumentation documentation )
251265
/// <param name="text">The text to display in the paragraphs, or null for no paragraphs.</param>
252266
/// <returns>The HTML element representing the paragraphs, or null if no text is provided.</returns>
253267
[return: NotNullIfNotNull ( nameof ( text ) )]
254-
protected virtual HtmlElement? CreateParagraphs ( string? text ) {
268+
protected virtual object? CreateParagraphs ( string? text ) {
255269
if (text is null)
256270
return null;
257271

258-
return HtmlElement.Fragment ( fragment => {
259-
foreach (var s in text.Split ( '\n', StringSplitOptions.RemoveEmptyEntries )) {
260-
fragment += new HtmlElement ( "p", s );
261-
}
262-
} );
272+
return new MarkdownText ( text );
263273
}
264274

265275
/// <summary>

0 commit comments

Comments
 (0)