From 4a9de25c2e2e604dcf8712b2d933a69d380059ea Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Thu, 4 Jul 2024 21:41:22 +0200 Subject: [PATCH] Fix: EmphasisInline not detected --- .../Features/MarkdownConverter.cs | 1 + .../Components/TableOfContentsTests.cs | 26 +++++-------------- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/src/LinkDotNet.Blog.Web/Features/MarkdownConverter.cs b/src/LinkDotNet.Blog.Web/Features/MarkdownConverter.cs index 24704eac..0b1c6e8d 100644 --- a/src/LinkDotNet.Blog.Web/Features/MarkdownConverter.cs +++ b/src/LinkDotNet.Blog.Web/Features/MarkdownConverter.cs @@ -56,6 +56,7 @@ private static string InlineToString(ContainerInline inline) { CodeInline cd => cd.Content, LinkInline link => link.FirstChild?.ToString(), + EmphasisInline em => em.FirstChild?.ToString(), _ => current.ToString() }; diff --git a/tests/LinkDotNet.Blog.UnitTests/Web/Features/ShowBlogPost/Components/TableOfContentsTests.cs b/tests/LinkDotNet.Blog.UnitTests/Web/Features/ShowBlogPost/Components/TableOfContentsTests.cs index ea8fed2b..3ce947dd 100644 --- a/tests/LinkDotNet.Blog.UnitTests/Web/Features/ShowBlogPost/Components/TableOfContentsTests.cs +++ b/tests/LinkDotNet.Blog.UnitTests/Web/Features/ShowBlogPost/Components/TableOfContentsTests.cs @@ -53,29 +53,17 @@ public void ShouldSetAnchorLinkCorrectWhenAlreadyAnchorInUrl() links[1].GetAttribute("href").Should().Be("https://localhost#header-2"); } - [Fact] - public void ShouldCreateCorrectTocWithCodeInHeadings() + [Theory] + [InlineData("# This is `Header` 1", "This is Header 1")] + [InlineData("# [This is a link](https://link.com)", "This is a link")] + [InlineData("# **What** *if*", "What if")] + public void ShouldCreateCorrectToc(string markdown, string expectedToc) { - const string content = "# This is `Header` 1"; - var cut = Render(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 Header 1"); - } - - [Fact] - public void ShouldCreateCorrectTocWithLinkInHeadings() - { - const string content = "# [This is a link](https://link.com)"; - - var cut = Render(p => p - .Add(x => x.Content, content) + .Add(x => x.Content, markdown) .Add(x => x.CurrentUri, "https://localhost")); var link = cut.Find("nav a"); - link.TextContent.Should().Be("This is a link"); + link.TextContent.Should().Be(expectedToc); } }