From 5ca1c272239824cf2bbcd81429dc74df5123c5ec Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Mon, 21 Jul 2025 23:36:36 +0200 Subject: [PATCH 1/2] Fix rendering subs in LLM markdown output headings --- .../LlmMarkdown/LlmBlockRenderers.cs | 16 ++-------------- .../LlmMarkdown/LlmMarkdownOutput.fs | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/Elastic.Markdown/Myst/Renderers/LlmMarkdown/LlmBlockRenderers.cs b/src/Elastic.Markdown/Myst/Renderers/LlmMarkdown/LlmBlockRenderers.cs index 2fca4e4b7..994485f6f 100644 --- a/src/Elastic.Markdown/Myst/Renderers/LlmMarkdown/LlmBlockRenderers.cs +++ b/src/Elastic.Markdown/Myst/Renderers/LlmMarkdown/LlmBlockRenderers.cs @@ -81,22 +81,10 @@ protected override void Write(LlmMarkdownRenderer renderer, HeadingBlock obj) { renderer.EnsureBlockSpacing(); renderer.WriteLine(); - - var headingText = ExtractHeadingText(obj); - renderer.Write(new string('#', obj.Level)); renderer.Write(" "); - renderer.WriteLine(headingText); - } - - private static string ExtractHeadingText(HeadingBlock heading) - { - if (heading.Inline == null) - return string.Empty; - return heading.Inline.Descendants() - .OfType() - .Select(l => l.Content.ToString()) - .Aggregate(string.Empty, (current, text) => current + text); + if (obj.Inline is { } inline) + renderer.WriteChildren(inline); } } diff --git a/tests/authoring/LlmMarkdown/LlmMarkdownOutput.fs b/tests/authoring/LlmMarkdown/LlmMarkdownOutput.fs index 275def95d..97d1f4f31 100644 --- a/tests/authoring/LlmMarkdown/LlmMarkdownOutput.fs +++ b/tests/authoring/LlmMarkdown/LlmMarkdownOutput.fs @@ -445,7 +445,7 @@ type ``codeblock in list`` () = ``` """ -type ``substitions`` () = +type ``substitutions`` () = static let markdown = Setup.Document """--- sub: hello-world: "Hello World!" @@ -462,7 +462,7 @@ Hello, this is a substitution: Hello World! This is not a substitution: {{not-found}} """ -type ``substition in codeblock`` () = +type ``substitution in codeblock`` () = static let markdown = Setup.Document """--- sub: hello-world: "Hello World!" @@ -488,3 +488,18 @@ Hello, this is a substitution: {{hello-world}} Hello, this is a substitution: Hello World! ``` """ + +type ``substitution in heading`` () = + static let markdown = Setup.Document """--- +sub: + world: "World" +--- + +## Hello, {{world}}! +""" + + [] + let ``renders correctly`` () = + markdown |> convertsToNewLLM """ +## Hello, World! +""" From d4c1cbe4a288ee906a00c8234f97bdbd21427b28 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Tue, 22 Jul 2025 00:59:05 +0200 Subject: [PATCH 2/2] Refactor for readability --- .../Myst/Renderers/LlmMarkdown/LlmBlockRenderers.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Elastic.Markdown/Myst/Renderers/LlmMarkdown/LlmBlockRenderers.cs b/src/Elastic.Markdown/Myst/Renderers/LlmMarkdown/LlmBlockRenderers.cs index 994485f6f..807d601b0 100644 --- a/src/Elastic.Markdown/Myst/Renderers/LlmMarkdown/LlmBlockRenderers.cs +++ b/src/Elastic.Markdown/Myst/Renderers/LlmMarkdown/LlmBlockRenderers.cs @@ -83,8 +83,8 @@ protected override void Write(LlmMarkdownRenderer renderer, HeadingBlock obj) renderer.WriteLine(); renderer.Write(new string('#', obj.Level)); renderer.Write(" "); - if (obj.Inline is { } inline) - renderer.WriteChildren(inline); + if (obj.Inline is not null) + renderer.WriteChildren(obj.Inline); } }