Skip to content

Commit 5c25c06

Browse files
committed
Render markdown descriptions
1 parent 64f9b31 commit 5c25c06

File tree

16 files changed

+82
-17
lines changed

16 files changed

+82
-17
lines changed

src/Elastic.ApiExplorer/ApiRenderContext.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information
44

5+
using Elastic.Documentation;
56
using Elastic.Documentation.Configuration;
67
using Elastic.Documentation.Site.FileProviders;
78
using Elastic.Documentation.Site.Navigation;
@@ -18,4 +19,5 @@ StaticFileContentHashProvider StaticFileContentHashProvider
1819
{
1920
public required string NavigationHtml { get; init; }
2021
public required INavigationItem CurrentNavigation { get; init; }
22+
public required IMarkdownStringRenderer MarkdownRenderer { get; init; }
2123
}

src/Elastic.ApiExplorer/ApiViewModel.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information
44

5+
using Elastic.Documentation;
56
using Elastic.Documentation.Site.FileProviders;
67
using Elastic.Documentation.Site.Navigation;
8+
using Microsoft.AspNetCore.Html;
79

810
namespace Elastic.ApiExplorer;
911

@@ -12,4 +14,9 @@ public abstract class ApiViewModel
1214
public required string NavigationHtml { get; init; }
1315
public required StaticFileContentHashProvider StaticFileContentHashProvider { get; init; }
1416
public required INavigationItem CurrentNavigationItem { get; init; }
17+
public required IMarkdownStringRenderer MarkdownRenderer { get; init; }
18+
19+
20+
public HtmlString RenderMarkdown(string? markdown) =>
21+
string.IsNullOrEmpty(markdown) ? new(string.Empty) : new(MarkdownRenderer.Render(markdown, null));
1522
}

src/Elastic.ApiExplorer/Endpoints/ApiEndpoint.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ public async Task RenderAsync(FileSystemStream stream, ApiRenderContext context,
2727
ApiEndpoint = this,
2828
StaticFileContentHashProvider = context.StaticFileContentHashProvider,
2929
NavigationHtml = context.NavigationHtml,
30-
CurrentNavigationItem = context.CurrentNavigation
30+
CurrentNavigationItem = context.CurrentNavigation,
31+
MarkdownRenderer = context.MarkdownRenderer
3132

3233
};
3334
var slice = EndpointView.Create(viewModel);

src/Elastic.ApiExplorer/Endpoints/IndexViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
// See the LICENSE file in the project root for more information
44

55
using Elastic.ApiExplorer.Landing;
6+
using Elastic.Documentation;
67

78
namespace Elastic.ApiExplorer.Endpoints;
89

910
public class IndexViewModel : ApiViewModel
1011
{
1112
public required ApiEndpoint ApiEndpoint { get; init; }
12-
1313
}

src/Elastic.ApiExplorer/Landing/LandingNavigationItem.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ public async Task RenderAsync(FileSystemStream stream, ApiRenderContext context,
2020
StaticFileContentHashProvider = context.StaticFileContentHashProvider,
2121
NavigationHtml = context.NavigationHtml,
2222
ApiInfo = context.Model.Info,
23-
CurrentNavigationItem = context.CurrentNavigation
23+
CurrentNavigationItem = context.CurrentNavigation,
24+
MarkdownRenderer = context.MarkdownRenderer
2425
};
2526
var slice = LandingView.Create(viewModel);
2627
await slice.RenderAsync(stream, cancellationToken: ctx);

src/Elastic.ApiExplorer/OpenApiGenerator.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.IO.Abstractions;
66
using Elastic.ApiExplorer.Landing;
77
using Elastic.ApiExplorer.Operations;
8+
using Elastic.Documentation;
89
using Elastic.Documentation.Configuration;
910
using Elastic.Documentation.Site.FileProviders;
1011
using Elastic.Documentation.Site.Navigation;
@@ -37,7 +38,7 @@ public record ApiEndpoint(List<ApiOperation> Operations, string? Name) : IApiGro
3738
public Task RenderAsync(FileSystemStream stream, ApiRenderContext context, CancellationToken ctx = default) => Task.CompletedTask;
3839
}
3940

40-
public class OpenApiGenerator(BuildContext context, ILoggerFactory logger)
41+
public class OpenApiGenerator(BuildContext context, IMarkdownStringRenderer markdownStringRenderer, ILoggerFactory logger)
4142
{
4243
private readonly ILogger _logger = logger.CreateLogger<OpenApiGenerator>();
4344
private readonly IFileSystem _writeFileSystem = context.WriteFileSystem;
@@ -256,7 +257,8 @@ public async Task Generate(Cancel ctx = default)
256257
var renderContext = new ApiRenderContext(context, openApiDocument, _contentHashProvider)
257258
{
258259
NavigationHtml = string.Empty,
259-
CurrentNavigation = navigation
260+
CurrentNavigation = navigation,
261+
MarkdownRenderer = markdownStringRenderer
260262
};
261263
_ = await Render(navigation, navigation.Index, renderContext, navigationRenderer, ctx);
262264
await RenderNavigationItems(navigation);

src/Elastic.ApiExplorer/Operations/OperationNavigationItem.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ public async Task RenderAsync(FileSystemStream stream, ApiRenderContext context,
2121
Operation = this,
2222
StaticFileContentHashProvider = context.StaticFileContentHashProvider,
2323
NavigationHtml = context.NavigationHtml,
24-
CurrentNavigationItem = context.CurrentNavigation
24+
CurrentNavigationItem = context.CurrentNavigation,
25+
MarkdownRenderer = context.MarkdownRenderer
2526
};
2627
var slice = OperationView.Create(viewModel);
2728
await slice.RenderAsync(stream, cancellationToken: ctx);

src/Elastic.ApiExplorer/Operations/OperationView.cshtml

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
<section id="elastic-api-v3">
4545
<h1>@operation.Summary</h1>
4646
<p>
47-
@operation.Description
47+
@(Model.RenderMarkdown(operation.Description))
4848
</p>
4949
<ul class="api-url-listing">
5050
@foreach (var overload in allOperations)
@@ -64,12 +64,12 @@
6464
}
6565
@if (pathParameters.Length > 0)
6666
{
67-
<h3>Path Parameters</h3>
67+
<h4>Path Parameters</h4>
6868
<dl>
6969
@foreach (var path in pathParameters)
7070
{
7171
<dt id="@path.Name"><a href="#@path.Name"><code>@path.Name</code></a></dt>
72-
<dd>@path.Description</dd>
72+
<dd>@Model.RenderMarkdown(path.Description)</dd>
7373
}
7474
</dl>
7575
}
@@ -78,12 +78,25 @@
7878
}
7979
@if (queryStringParameters.Length > 0)
8080
{
81-
<h3>Query String Parameters</h3>
81+
<h4>Query String Parameters</h4>
8282
<dl>
8383
@foreach (var path in queryStringParameters)
8484
{
8585
<dt id="@path.Name"><a href="#@path.Name"><code>@path.Name</code></a></dt>
86-
<dd>@path.Description</dd>
86+
<dd>@Model.RenderMarkdown(path.Description)</dd>
87+
}
88+
</dl>
89+
}
90+
@if (operation.RequestBody is not null)
91+
{
92+
<h3>Request Body</h3>
93+
if (!string.IsNullOrEmpty(operation.RequestBody.Description))
94+
{
95+
<p>@operation.RequestBody.Description</p>
96+
}
97+
<dl>
98+
@foreach (var path in operation.RequestBody.Content)
99+
{
87100
}
88101
</dl>
89102
}

src/Elastic.Documentation.Configuration/Elastic.Documentation.Configuration.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,5 @@
1515
<PackageReference Include="Samboy063.Tomlet" />
1616
<PackageReference Include="Vecc.YamlDotNet.Analyzers.StaticGenerator"/>
1717
<PackageReference Include="YamlDotNet"/>
18-
<PackageReference Include="System.IO.Abstractions" />
1918
</ItemGroup>
2019
</Project>

src/Elastic.Documentation.Site/Assets/api-docs.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,7 @@
9898
h3 {
9999
@apply border-b-grey-20 border-b-1 pb-2;
100100
}
101+
h4 {
102+
@apply border-b-grey-20 border-b-1 pb-2;
103+
}
101104
}

0 commit comments

Comments
 (0)