Skip to content

Commit deeb33a

Browse files
committed
Fix inline code in left navigation and h1 rendering
1 parent 44e4627 commit deeb33a

File tree

4 files changed

+18
-6
lines changed

4 files changed

+18
-6
lines changed

docs/contribute/locally.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Contribute locally
1+
# Contribute locally `This is a code block`
22

33
Follow these steps to contribute to Elastic docs.
44
* [Step 1: Install `docs-builder`](#step-one)
@@ -116,4 +116,4 @@ Open a PR. Good luck.
116116

117117
## Step 5: View on elastic.co/docs
118118

119-
soon...
119+
soon...
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace Elastic.Markdown.Helpers;
2+
3+
public static class TitleSanitizer
4+
{
5+
// Removes markdown formatting from the title and returns only the text
6+
// Currently, only support 'bold' and 'code' formatting
7+
public static string Sanitize(string title) => title.Replace("`", "").Replace("*", "");
8+
}

src/Elastic.Markdown/IO/MarkdownFile.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ public DocumentationGroup? Parent
4646
public string? Title { get; private set; }
4747
public string? NavigationTitle
4848
{
49-
get => !string.IsNullOrEmpty(_navigationTitle) ? _navigationTitle : Title;
49+
get {
50+
var title = !string.IsNullOrEmpty(_navigationTitle) ? _navigationTitle : Title;
51+
return string.IsNullOrEmpty(title) ? null : TitleSanitizer.Sanitize(title);
52+
}
5053
private set => _navigationTitle = value;
5154
}
5255

@@ -159,7 +162,7 @@ private void ReadDocumentInstructions(MarkdownDocument document)
159162
.Select(h => (h.GetData("header") as string, h.GetData("anchor") as string))
160163
.Select(h => new PageTocItem
161164
{
162-
Heading = h.Item1!.Replace("`", "").Replace("*", ""),
165+
Heading = TitleSanitizer.Sanitize(h.Item1!),
163166
Slug = _slugHelper.GenerateSlug(h.Item2 ?? h.Item1)
164167
})
165168
.ToList();

src/Elastic.Markdown/Slices/Index.cshtml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
@using Markdig
12
@inherits RazorSliceHttpResult<IndexViewModel>
23
@implements IUsesLayout<Elastic.Markdown.Slices._Layout, LayoutViewModel>
34
@functions {
45
public LayoutViewModel LayoutModel => new()
56
{
6-
Title = $"Elastic Documentation: {Model.Title}",
7+
Title = $"Elastic Documentation: {Model.Title ?? "Untitled"}",
78
PageTocItems = Model.PageTocItems,
89
Tree = Model.Tree,
910
CurrentDocument = Model.CurrentDocument,
@@ -16,7 +17,7 @@
1617
};
1718
}
1819
<section id="elastic-docs-v3">
19-
<h1>@(Model.Title)</h1>
20+
@(new HtmlString(Markdown.ToHtml("# " + Model.Title)))
2021
@if (Model.Applies is not null)
2122
{
2223
await RenderPartialAsync(Applies.Create(Model.Applies));

0 commit comments

Comments
 (0)