From e00d555e7d3d962ca93f06798074c24b261c20fe Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Thu, 23 Jan 2025 16:17:13 +0100 Subject: [PATCH] Add TitleRaw property --- docs/testing/req.md | 3 ++- src/Elastic.Markdown/IO/MarkdownFile.cs | 13 ++++++++++++- src/Elastic.Markdown/Slices/HtmlWriter.cs | 1 + src/Elastic.Markdown/Slices/Index.cshtml | 2 +- src/Elastic.Markdown/Slices/_ViewModels.cs | 2 ++ 5 files changed, 18 insertions(+), 3 deletions(-) diff --git a/docs/testing/req.md b/docs/testing/req.md index 4617b62d..7c870fa9 100644 --- a/docs/testing/req.md +++ b/docs/testing/req.md @@ -1,4 +1,5 @@ -# Requirements +# Requirements [link](https://www.elastic.co) `code` +## Requirements [link](https://www.elastic.co) `code` To follow this tutorial you will need to install the following components: diff --git a/src/Elastic.Markdown/IO/MarkdownFile.cs b/src/Elastic.Markdown/IO/MarkdownFile.cs index 961b9105..f697caaa 100644 --- a/src/Elastic.Markdown/IO/MarkdownFile.cs +++ b/src/Elastic.Markdown/IO/MarkdownFile.cs @@ -43,7 +43,17 @@ public DocumentationGroup? Parent public string? UrlPathPrefix { get; } private MarkdownParser MarkdownParser { get; } public YamlFrontMatter? YamlFrontMatter { get; private set; } - public string? Title { get; private set; } + public string? TitleRaw { get; private set; } + + public string? Title + { + get => _title; + private set + { + _title = value?.StripMarkdown(); + TitleRaw = value; + } + } public string? NavigationTitle { get => !string.IsNullOrEmpty(_navigationTitle) ? _navigationTitle : Title; @@ -65,6 +75,7 @@ public string? NavigationTitle private bool _instructionsParsed; private DocumentationGroup? _parent; + private string? _title; public MarkdownFile[] YieldParents() { diff --git a/src/Elastic.Markdown/Slices/HtmlWriter.cs b/src/Elastic.Markdown/Slices/HtmlWriter.cs index aac30edf..23ef8aec 100644 --- a/src/Elastic.Markdown/Slices/HtmlWriter.cs +++ b/src/Elastic.Markdown/Slices/HtmlWriter.cs @@ -56,6 +56,7 @@ public async Task RenderLayout(MarkdownFile markdown, Cancel ctx = defau var slice = Index.Create(new IndexViewModel { Title = markdown.Title ?? "[TITLE NOT SET]", + TitleRaw = markdown.TitleRaw ?? "[TITLE NOT SET]", MarkdownHtml = html, PageTocItems = markdown.TableOfContents.Values.ToList(), Tree = DocumentationSet.Tree, diff --git a/src/Elastic.Markdown/Slices/Index.cshtml b/src/Elastic.Markdown/Slices/Index.cshtml index 6c3ef6e6..3abb070d 100644 --- a/src/Elastic.Markdown/Slices/Index.cshtml +++ b/src/Elastic.Markdown/Slices/Index.cshtml @@ -18,7 +18,7 @@ }
@* This way it's correctly rendered as

text

instead of

text

*@ - @(new HtmlString(Markdown.ToHtml("# " + Model.Title))) + @(new HtmlString(Markdown.ToHtml("# " + Model.TitleRaw))) @if (Model.Applies is not null) { await RenderPartialAsync(Applies.Create(Model.Applies)); diff --git a/src/Elastic.Markdown/Slices/_ViewModels.cs b/src/Elastic.Markdown/Slices/_ViewModels.cs index 3e89a70f..987f5f6d 100644 --- a/src/Elastic.Markdown/Slices/_ViewModels.cs +++ b/src/Elastic.Markdown/Slices/_ViewModels.cs @@ -10,6 +10,7 @@ namespace Elastic.Markdown.Slices; public class IndexViewModel { public required string Title { get; init; } + public required string TitleRaw { get; init; } public required string MarkdownHtml { get; init; } public required DocumentationGroup Tree { get; init; } public required IReadOnlyCollection PageTocItems { get; init; } @@ -26,6 +27,7 @@ public class IndexViewModel public class LayoutViewModel { public string Title { get; set; } = "Elastic Documentation"; + public string RawTitle { get; set; } = "Elastic Documentation"; public required IReadOnlyCollection PageTocItems { get; init; } public required DocumentationGroup Tree { get; init; } public required MarkdownFile CurrentDocument { get; init; }