File tree Expand file tree Collapse file tree
src/LinkDotNet.Blog.Web/Features
tests/LinkDotNet.Blog.UnitTests/Web/Features/ShowBlogPost/Components Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33using System . Text ;
44using Markdig ;
55using Markdig . Extensions . AutoIdentifiers ;
6+ using Markdig . Helpers ;
67using Markdig . Renderers . Html ;
78using Markdig . Syntax ;
89using Markdig . Syntax . Inlines ;
@@ -51,14 +52,14 @@ private static string InlineToString(ContainerInline inline)
5152 var current = inline . FirstChild ;
5253 while ( current is not null )
5354 {
54- if ( current is CodeInline cd )
55+ var text = current switch
5556 {
56- sb . Append ( cd . Content ) ;
57- }
58- else
59- {
60- sb . Append ( current ) ;
61- }
57+ CodeInline cd => cd . Content ,
58+ LinkInline link => link . FirstChild ? . ToString ( ) ,
59+ _ => current . ToString ( )
60+ } ;
61+
62+ sb . Append ( text ) ;
6263
6364 current = current . NextSibling ;
6465 }
Original file line number Diff line number Diff line change @@ -65,4 +65,17 @@ public void ShouldCreateCorrectTocWithCodeInHeadings()
6565 var link = cut . Find ( "nav a" ) ;
6666 link . TextContent . Should ( ) . Be ( "This is Header 1" ) ;
6767 }
68+
69+ [ Fact ]
70+ public void ShouldCreateCorrectTocWithLinkInHeadings ( )
71+ {
72+ const string content = "# [This is a link](https://link.com)" ;
73+
74+ var cut = Render < TableOfContents > ( p => p
75+ . Add ( x => x . Content , content )
76+ . Add ( x => x . CurrentUri , "https://localhost" ) ) ;
77+
78+ var link = cut . Find ( "nav a" ) ;
79+ link . TextContent . Should ( ) . Be ( "This is a link" ) ;
80+ }
6881}
You can’t perform that action at this time.
0 commit comments