Skip to content

Commit dd32f71

Browse files
committed
Fix links in header
1 parent b682836 commit dd32f71

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

src/LinkDotNet.Blog.Web/Features/MarkdownConverter.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Text;
44
using Markdig;
55
using Markdig.Extensions.AutoIdentifiers;
6+
using Markdig.Helpers;
67
using Markdig.Renderers.Html;
78
using Markdig.Syntax;
89
using 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
}

tests/LinkDotNet.Blog.UnitTests/Web/Features/ShowBlogPost/Components/TableOfContentsTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)