File tree Expand file tree Collapse file tree 2 files changed +21
-7
lines changed
src/LinkDotNet.Blog.Web/Features
tests/LinkDotNet.Blog.UnitTests/Web/Features/ShowBlogPost/Components Expand file tree Collapse file tree 2 files changed +21
-7
lines changed Original file line number Diff line number Diff line change 3
3
using System . Text ;
4
4
using Markdig ;
5
5
using Markdig . Extensions . AutoIdentifiers ;
6
+ using Markdig . Helpers ;
6
7
using Markdig . Renderers . Html ;
7
8
using Markdig . Syntax ;
8
9
using Markdig . Syntax . Inlines ;
@@ -51,14 +52,14 @@ private static string InlineToString(ContainerInline inline)
51
52
var current = inline . FirstChild ;
52
53
while ( current is not null )
53
54
{
54
- if ( current is CodeInline cd )
55
+ var text = current switch
55
56
{
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 ) ;
62
63
63
64
current = current . NextSibling ;
64
65
}
Original file line number Diff line number Diff line change @@ -65,4 +65,17 @@ public void ShouldCreateCorrectTocWithCodeInHeadings()
65
65
var link = cut . Find ( "nav a" ) ;
66
66
link . TextContent . Should ( ) . Be ( "This is Header 1" ) ;
67
67
}
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
+ }
68
81
}
You can’t perform that action at this time.
0 commit comments