Skip to content

Commit

Permalink
Fix links in header
Browse files Browse the repository at this point in the history
  • Loading branch information
linkdotnet committed Jun 30, 2024
1 parent b682836 commit dd32f71
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/LinkDotNet.Blog.Web/Features/MarkdownConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Text;
using Markdig;
using Markdig.Extensions.AutoIdentifiers;
using Markdig.Helpers;
using Markdig.Renderers.Html;
using Markdig.Syntax;
using Markdig.Syntax.Inlines;
Expand Down Expand Up @@ -51,14 +52,14 @@ private static string InlineToString(ContainerInline inline)
var current = inline.FirstChild;
while (current is not null)
{
if (current is CodeInline cd)
var text = current switch
{
sb.Append(cd.Content);
}
else
{
sb.Append(current);
}
CodeInline cd => cd.Content,
LinkInline link => link.FirstChild?.ToString(),
_ => current.ToString()
};

sb.Append(text);

current = current.NextSibling;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,17 @@ public void ShouldCreateCorrectTocWithCodeInHeadings()
var link = cut.Find("nav a");
link.TextContent.Should().Be("This is Header 1");
}

[Fact]
public void ShouldCreateCorrectTocWithLinkInHeadings()
{
const string content = "# [This is a link](https://link.com)";

var cut = Render<TableOfContents>(p => p
.Add(x => x.Content, content)
.Add(x => x.CurrentUri, "https://localhost"));

var link = cut.Find("nav a");
link.TextContent.Should().Be("This is a link");
}
}

0 comments on commit dd32f71

Please sign in to comment.