Skip to content

Commit 3ecf00e

Browse files
authored
Fix rendering subs in LLM markdown output headings (#1597)
* Fix rendering subs in LLM markdown output headings * Refactor for readability
1 parent 408c009 commit 3ecf00e

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

src/Elastic.Markdown/Myst/Renderers/LlmMarkdown/LlmBlockRenderers.cs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,10 @@ protected override void Write(LlmMarkdownRenderer renderer, HeadingBlock obj)
8080
{
8181
renderer.EnsureBlockSpacing();
8282
renderer.WriteLine();
83-
84-
var headingText = ExtractHeadingText(obj);
85-
8683
renderer.Write(new string('#', obj.Level));
8784
renderer.Write(" ");
88-
renderer.WriteLine(headingText);
89-
}
90-
91-
private static string ExtractHeadingText(HeadingBlock heading)
92-
{
93-
if (heading.Inline == null)
94-
return string.Empty;
95-
return heading.Inline.Descendants()
96-
.OfType<LiteralInline>()
97-
.Select(l => l.Content.ToString())
98-
.Aggregate(string.Empty, (current, text) => current + text);
85+
if (obj.Inline is not null)
86+
renderer.WriteChildren(obj.Inline);
9987
}
10088
}
10189

tests/authoring/LlmMarkdown/LlmMarkdownOutput.fs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ type ``codeblock in list`` () =
445445
```
446446
"""
447447

448-
type ``substitions`` () =
448+
type ``substitutions`` () =
449449
static let markdown = Setup.Document """---
450450
sub:
451451
hello-world: "Hello World!"
@@ -462,7 +462,7 @@ Hello, this is a substitution: Hello World!
462462
This is not a substitution: {{not-found}}
463463
"""
464464

465-
type ``substition in codeblock`` () =
465+
type ``substitution in codeblock`` () =
466466
static let markdown = Setup.Document """---
467467
sub:
468468
hello-world: "Hello World!"
@@ -488,3 +488,18 @@ Hello, this is a substitution: {{hello-world}}
488488
Hello, this is a substitution: Hello World!
489489
```
490490
"""
491+
492+
type ``substitution in heading`` () =
493+
static let markdown = Setup.Document """---
494+
sub:
495+
world: "World"
496+
---
497+
498+
## Hello, {{world}}!
499+
"""
500+
501+
[<Fact>]
502+
let ``renders correctly`` () =
503+
markdown |> convertsToNewLLM """
504+
## Hello, World!
505+
"""

0 commit comments

Comments
 (0)