@@ -29,18 +29,29 @@ 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 = AppliesToSyntaxRegex ( ) ;
36+
37+ private static string StripAppliesToAnnotations ( string text )
38+ {
39+ // Remove applies_to inline annotations from the text
40+ return AppliesToSyntax . Replace ( text , "" ) . Trim ( ) ;
41+ }
42+
43+ [ GeneratedRegex ( @"\{applies_to\}`[^`]*`" , RegexOptions . Compiled ) ]
44+ private static partial Regex AppliesToSyntaxRegex ( ) ;
3545
3646 public override bool Close ( BlockProcessor processor , Block block )
3747 {
3848 if ( block is not HeadingBlock headingBlock )
3949 return base . Close ( processor , block ) ;
4050
4151 var text = headingBlock . Lines . Lines [ 0 ] . Slice . AsSpan ( ) ;
42- // Remove icon syntax from the heading text
43- var cleanText = IconSyntax . Replace ( text . ToString ( ) , "" ) . Trim ( ) ;
52+ // Remove icon syntax and applies_to annotations from the heading text
53+ var cleanText = IconSyntax . Replace ( text . ToString ( ) , "" ) ;
54+ cleanText = StripAppliesToAnnotations ( cleanText ) ;
4455 headingBlock . SetData ( "header" , cleanText ) ;
4556
4657 if ( ! HeadingAnchorParser . MatchAnchorLine ( ) . IsMatch ( text ) )
@@ -59,8 +70,10 @@ public override bool Close(BlockProcessor processor, Block block)
5970 if ( header . IndexOf ( '$' ) >= 0 )
6071 anchor = HeadingAnchorParser . MatchAnchor ( ) . Replace ( anchor . ToString ( ) , "" ) ;
6172 headingBlock . SetData ( "anchor" , anchor . ToString ( ) ) ;
62- // Remove icon syntax from the header text when setting it as data
63- headingBlock . SetData ( "header" , IconSyntax . Replace ( header . ToString ( ) , "" ) . Trim ( ) ) ;
73+ // Remove icon syntax and applies_to annotations from the header text when setting it as data
74+ var headerText = IconSyntax . Replace ( header . ToString ( ) , "" ) ;
75+ headerText = StripAppliesToAnnotations ( headerText ) ;
76+ headingBlock . SetData ( "header" , headerText . Trim ( ) ) ;
6477 return base . Close ( processor , block ) ;
6578 }
6679
0 commit comments