Skip to content

Commit 6eea484

Browse files
warn when heading contains inline applies_to
1 parent fc7ab4f commit 6eea484

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/Elastic.Markdown/Myst/InlineParsers/HeadingBlockWithSlugParser.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,20 @@ public void Setup(MarkdownPipelineBuilder pipeline) =>
2929
public void Setup(MarkdownPipeline pipeline, IMarkdownRenderer renderer) { }
3030
}
3131

32-
public class HeadingBlockWithSlugParser : HeadingBlockParser
32+
public partial class HeadingBlockWithSlugParser : HeadingBlockParser
3333
{
3434
private static readonly Regex IconSyntax = IconParser.IconRegex();
35+
private static readonly Regex AppliesToSyntax = HeadingAppliesToParser.AppliesToSyntaxRegex();
3536

3637
public override bool Close(BlockProcessor processor, Block block)
3738
{
3839
if (block is not HeadingBlock headingBlock)
3940
return base.Close(processor, block);
4041

4142
var text = headingBlock.Lines.Lines[0].Slice.AsSpan();
43+
if (AppliesToSyntax.IsMatch(text))
44+
processor.GetContext().Build.Collector.EmitWarning(processor.GetContext().MarkdownSourcePath, "Do not use inline 'applies_to' annotations with headings. Use a section 'applies_to' annotation instead.");
45+
4246
// Remove icon syntax from the heading text
4347
var cleanText = IconSyntax.Replace(text.ToString(), "").Trim();
4448
headingBlock.SetData("header", cleanText);
@@ -79,3 +83,9 @@ public static partial class HeadingAnchorParser
7983
[GeneratedRegex(@"\$\$\$[^\$]+\$\$\$", RegexOptions.IgnoreCase, "en-US")]
8084
public static partial Regex InlineAnchors();
8185
}
86+
87+
public static partial class HeadingAppliesToParser
88+
{
89+
[GeneratedRegex(@"\{applies_to\}`[^`]*`", RegexOptions.Compiled)]
90+
public static partial Regex AppliesToSyntaxRegex();
91+
}

0 commit comments

Comments
 (0)