diff --git a/src/Elastic.Markdown/Myst/Renderers/HtmxLinkInlineRenderer.cs b/src/Elastic.Markdown/Myst/Renderers/HtmxLinkInlineRenderer.cs index a33e8de5d9..873ae1cd2b 100644 --- a/src/Elastic.Markdown/Myst/Renderers/HtmxLinkInlineRenderer.cs +++ b/src/Elastic.Markdown/Myst/Renderers/HtmxLinkInlineRenderer.cs @@ -94,7 +94,7 @@ private static void WriteImage(HtmlRenderer renderer, LinkInline link) // Write any additional attributes (like width/height from styling instructions) _ = renderer.WriteAttributes(link); - // Set title to alt text for inline images (after any substitutions are processed) + // Always use alt text as title for accessibility consistency if (link.FirstChild != null) { _ = renderer.Write(" title=\""); diff --git a/tests/Elastic.Markdown.Tests/Inline/InlineImageTest.cs b/tests/Elastic.Markdown.Tests/Inline/InlineImageTest.cs index 0d372b0575..ffe4cc40c6 100644 --- a/tests/Elastic.Markdown.Tests/Inline/InlineImageTest.cs +++ b/tests/Elastic.Markdown.Tests/Inline/InlineImageTest.cs @@ -19,7 +19,7 @@ public class InlineImageTest(ITestOutputHelper output) : InlineTest( public void GeneratesAttributesInHtml() => // language=html Html.ShouldContainHtml( - """

Elasticsearch

""" + """

Elasticsearch

""" ); } @@ -36,7 +36,7 @@ public class RelativeInlineImageTest(ITestOutputHelper output) : InlineTest // language=html Html.ShouldContainHtml( - """

Elasticsearch

""" + """

Elasticsearch

""" ); } @@ -54,7 +54,7 @@ public class InlineImageWithSizingSpaceBeforeTest(ITestOutputHelper output) : In public void GeneratesAttributesInHtml() => // language=html Html.ShouldContainHtml( - """

Elasticsearch

""" + """

Elasticsearch

""" ); } @@ -72,7 +72,7 @@ public class InlineImageWithSizingNoSpaceBeforeTest(ITestOutputHelper output) : public void GeneratesAttributesInHtml() => // language=html Html.ShouldContainHtml( - """

Elasticsearch

""" + """

Elasticsearch

""" ); } @@ -90,11 +90,11 @@ public class InlineImageWithPixelSizingTest(ITestOutputHelper output) : InlineTe public void GeneratesAttributesInHtml() => // language=html Html.ShouldContainHtml( - """

Elasticsearch

""" + """

Elasticsearch

""" ); } -// Test image sizing with title and sizing +// Test image sizing with title and sizing — explicit title in markdown is ignored; alt text is always used as title public class InlineImageWithTitleAndSizingTest(ITestOutputHelper output) : InlineTest(output, """ ![Elasticsearch](/_static/img/observability.png "My Title =50%") @@ -108,7 +108,7 @@ public class InlineImageWithTitleAndSizingTest(ITestOutputHelper output) : Inlin public void GeneratesAttributesInHtml() => // language=html Html.ShouldContainHtml( - """

Elasticsearch

""" + """

Elasticsearch

""" ); } @@ -126,6 +126,6 @@ public class InlineImageWithWidthOnlyTest(ITestOutputHelper output) : InlineTest public void GeneratesAttributesInHtml() => // language=html Html.ShouldContainHtml( - """

Elasticsearch

""" + """

Elasticsearch

""" ); } diff --git a/tests/Elastic.Markdown.Tests/PrettyHtmlExtensions.cs b/tests/Elastic.Markdown.Tests/PrettyHtmlExtensions.cs index 221abb89c7..b24e21482d 100644 --- a/tests/Elastic.Markdown.Tests/PrettyHtmlExtensions.cs +++ b/tests/Elastic.Markdown.Tests/PrettyHtmlExtensions.cs @@ -81,7 +81,7 @@ public static void ShouldContainHtml( actual = actual.Trim('\n').PrettyHtml(sanitize); var actualCompare = actual.Replace("\t", string.Empty); - var expectedCompare = actual.Replace("\t", string.Empty); + var expectedCompare = expected.Replace("\t", string.Empty); // we compare over unindented HTML, but if that fails, we rely on the pretty HTML Contain(). // to throw for improved error messages diff --git a/tests/Elastic.Markdown.Tests/PrettyHtmlExtensionsTests.cs b/tests/Elastic.Markdown.Tests/PrettyHtmlExtensionsTests.cs new file mode 100644 index 0000000000..ee5606bf8d --- /dev/null +++ b/tests/Elastic.Markdown.Tests/PrettyHtmlExtensionsTests.cs @@ -0,0 +1,27 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information + +using AwesomeAssertions; +using Xunit.Sdk; + +namespace Elastic.Markdown.Tests; + +public class PrettyHtmlExtensionsTests +{ + [Fact] + public void ShouldContainHtml_WhenExpectedHtmlIsMissing_Throws() + { + var actual = """ +

Rendered output

+ """; + + var expected = """ + Missing output + """; + + var act = () => actual.ShouldContainHtml(expected); + + act.Should().Throw(); + } +}