Skip to content

Fix rendering subs in LLM markdown output headings #1597

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<LiteralInline>()
.Select(l => l.Content.ToString())
.Aggregate(string.Empty, (current, text) => current + text);
if (obj.Inline is not null)
renderer.WriteChildren(obj.Inline);
}
}

Expand Down
19 changes: 17 additions & 2 deletions tests/authoring/LlmMarkdown/LlmMarkdownOutput.fs
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ type ``codeblock in list`` () =
```
"""

type ``substitions`` () =
type ``substitutions`` () =
static let markdown = Setup.Document """---
sub:
hello-world: "Hello World!"
Expand All @@ -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!"
Expand All @@ -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}}!
"""

[<Fact>]
let ``renders correctly`` () =
markdown |> convertsToNewLLM """
## Hello, World!
"""
Loading