Skip to content
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
1 change: 1 addition & 0 deletions docs/_docset.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ subs:
ech: "Elastic Cloud Hosted"
serverless-full: "Elastic Cloud Serverless"
ecloud: "Elastic Cloud"
dbuild: "docs-builder"

features:
primary-nav: false
Expand Down
2 changes: 1 addition & 1 deletion docs/contribute/locally.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ cd docs-content
```
:::::

:::::{step} Run docs-builder
:::::{step} Run {{dbuild}}

Run the `docs-builder` binary with the `serve` command to build and serve the content set to [http://localhost:3000](http://localhost:3000). If necessary, specify the path to the `docset.yml` file that you want to build with `-p`.

Expand Down
24 changes: 17 additions & 7 deletions src/Elastic.Markdown/IO/MarkdownFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,15 +289,25 @@ public static List<PageTocItem> GetAnchors(
.OfType<StepBlock>()
.Where(step => !string.IsNullOrEmpty(step.Title))
.Where(step => !IsNestedInOtherDirective(step))
.Select(step => new
.Select(step =>
{
TocItem = new PageTocItem
var processedTitle = step.Title;
// Apply substitutions to step titles
if (subs.Count > 0 && processedTitle.AsSpan().ReplaceSubstitutions(subs, set.Context.Collector, out var replacement))
{
Heading = step.Title,
Slug = step.Anchor,
Level = step.HeadingLevel // Use dynamic heading level
},
step.Line
processedTitle = replacement;
}

return new
{
TocItem = new PageTocItem
{
Heading = processedTitle,
Slug = step.Anchor,
Level = step.HeadingLevel // Use dynamic heading level
},
step.Line
};
});

var toc = headingTocs
Expand Down
12 changes: 6 additions & 6 deletions src/Elastic.Markdown/Myst/Directives/Stepper/StepView.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,32 @@
{
case 1:
<h1 id="@Model.Anchor">
<a href="#@Model.Anchor">@Model.Title</a>
<a href="#@Model.Anchor">@Model.RenderTitle()</a>
</h1>
break;
case 2:
<h2 id="@Model.Anchor">
<a href="#@Model.Anchor">@Model.Title</a>
<a href="#@Model.Anchor">@Model.RenderTitle()</a>
</h2>
break;
case 3:
<h3 id="@Model.Anchor">
<a href="#@Model.Anchor">@Model.Title</a>
<a href="#@Model.Anchor">@Model.RenderTitle()</a>
</h3>
break;
case 4:
<h4 id="@Model.Anchor">
<a href="#@Model.Anchor">@Model.Title</a>
<a href="#@Model.Anchor">@Model.RenderTitle()</a>
</h4>
break;
case 5:
<h5 id="@Model.Anchor">
<a href="#@Model.Anchor">@Model.Title</a>
<a href="#@Model.Anchor">@Model.RenderTitle()</a>
</h5>
break;
default:
<h6 id="@Model.Anchor">
<a href="#@Model.Anchor">@Model.Title</a>
<a href="#@Model.Anchor">@Model.RenderTitle()</a>
</h6>
break;
}
Expand Down
40 changes: 40 additions & 0 deletions src/Elastic.Markdown/Myst/Directives/Stepper/StepViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,51 @@
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

using Elastic.Markdown.Helpers;
using Elastic.Markdown.IO;
using Markdig.Syntax;
using Markdig.Syntax.Inlines;
using Microsoft.AspNetCore.Html;

namespace Elastic.Markdown.Myst.Directives.Stepper;

public class StepViewModel : DirectiveViewModel
{
public required string Title { get; init; }
public required string Anchor { get; init; }
public required int HeadingLevel { get; init; }

/// <summary>
/// Renders the title with full markdown processing (substitutions, links, emphasis, etc.)
/// </summary>
public HtmlString RenderTitle()
{
// Parse the title as markdown with full pipeline (including substitutions)
var directiveBlock = (DirectiveBlock)DirectiveBlock;

// Get the YamlFrontMatter from the original document to support local substitutions
var originalContext = directiveBlock.GetData("context") as ParserContext;
var yamlFrontMatter = originalContext?.YamlFrontMatter;

var context = new ParserContext(new ParserState(directiveBlock.Build)
{
MarkdownSourcePath = directiveBlock.CurrentFile,
YamlFrontMatter = yamlFrontMatter,
DocumentationFileLookup = (path) => null!,
CrossLinkResolver = null!
});

var document = Markdig.Markdown.Parse(Title, MarkdownParser.Pipeline, context);

if (document.FirstOrDefault() is not Markdig.Syntax.ParagraphBlock firstBlock)
return new(Title);

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

var result = subscription.RentedStringBuilder?.ToString() ?? Title;
DocumentationObjectPoolProvider.HtmlRendererPool.Return(subscription);
return new(result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class StepBlock(DirectiveBlockParser parser, ParserContext context) : Dir
public override void FinalizeAndValidate(ParserContext context)
{
Title = Arguments ?? string.Empty;

Anchor = Prop("anchor") ?? Title.Slugify();

// Calculate heading level based on preceding heading
Expand Down
Loading