Skip to content

Commit a65dc71

Browse files
committed
Move subs logic
1 parent 31e6d29 commit a65dc71

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

src/Elastic.Markdown/Myst/Directives/Stepper/StepViewModel.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,23 @@ public class StepViewModel : DirectiveViewModel
2020
/// </summary>
2121
public HtmlString RenderTitle()
2222
{
23-
// Parse the title as markdown inline content
24-
var document = Markdig.Markdown.Parse(Title, MarkdownParser.Pipeline);
25-
var firstBlock = document.FirstOrDefault() as Markdig.Syntax.ParagraphBlock;
26-
var inline = firstBlock?.Inline;
23+
// Apply substitutions first, then parse with Markdig
24+
var directiveBlock = (DirectiveBlock)DirectiveBlock;
25+
var span = Title.AsSpan();
26+
var processedTitle = span.ReplaceSubstitutions(directiveBlock.Build.Configuration.Substitutions, directiveBlock.Build.Collector, out var replacement)
27+
? replacement : Title;
2728

28-
if (firstBlock == null)
29-
return new(Title);
29+
// Parse the processed title as markdown inline content
30+
var document = Markdig.Markdown.Parse(processedTitle, MarkdownParser.Pipeline);
31+
32+
if (document.FirstOrDefault() is not Markdig.Syntax.ParagraphBlock firstBlock)
33+
return new(processedTitle);
3034

3135
// Use the HTML renderer to render the inline content with full processing
3236
var subscription = DocumentationObjectPoolProvider.HtmlRendererPool.Get();
3337
_ = subscription.HtmlRenderer.WriteLeafInline(firstBlock);
3438

35-
var result = subscription.RentedStringBuilder?.ToString() ?? Title;
39+
var result = subscription.RentedStringBuilder?.ToString() ?? processedTitle;
3640
DocumentationObjectPoolProvider.HtmlRendererPool.Return(subscription);
3741
return new(result);
3842
}

src/Elastic.Markdown/Myst/Directives/Stepper/StepperBlock.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ public override void FinalizeAndValidate(ParserContext context)
2727
{
2828
Title = Arguments ?? string.Empty;
2929

30-
// Apply substitutions to the title
31-
Title = Title.ReplaceSubstitutions(context);
32-
3330
Anchor = Prop("anchor") ?? Title.Slugify();
3431

3532
// Calculate heading level based on preceding heading

0 commit comments

Comments
 (0)