Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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=\"");
Expand Down
16 changes: 8 additions & 8 deletions tests/Elastic.Markdown.Tests/Inline/InlineImageTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class InlineImageTest(ITestOutputHelper output) : InlineTest<LinkInline>(
public void GeneratesAttributesInHtml() =>
// language=html
Html.ShouldContainHtml(
"""<p><img src="/docs/_static/img/observability.png" alt="Elasticsearch" /></p>"""
"""<p><img src="/docs/_static/img/observability.png" alt="Elasticsearch" title="Elasticsearch" /></p>"""
);
}

Expand All @@ -36,7 +36,7 @@ public class RelativeInlineImageTest(ITestOutputHelper output) : InlineTest<Link
public void GeneratesAttributesInHtml() =>
// language=html
Html.ShouldContainHtml(
"""<p><img src="/docs/_static/img/observability.png" alt="Elasticsearch" /></p>"""
"""<p><img src="/docs/_static/img/observability.png" alt="Elasticsearch" title="Elasticsearch" /></p>"""
);
}

Expand All @@ -54,7 +54,7 @@ public class InlineImageWithSizingSpaceBeforeTest(ITestOutputHelper output) : In
public void GeneratesAttributesInHtml() =>
// language=html
Html.ShouldContainHtml(
"""<p><img src="/docs/_static/img/observability.png" alt="Elasticsearch" width="50%" height="50%" /></p>"""
"""<p><img src="/docs/_static/img/observability.png" alt="Elasticsearch" width="50%" height="50%" title="Elasticsearch" /></p>"""
);
}

Expand All @@ -72,7 +72,7 @@ public class InlineImageWithSizingNoSpaceBeforeTest(ITestOutputHelper output) :
public void GeneratesAttributesInHtml() =>
// language=html
Html.ShouldContainHtml(
"""<p><img src="/docs/_static/img/observability.png" alt="Elasticsearch" width="50%" height="50%" /></p>"""
"""<p><img src="/docs/_static/img/observability.png" alt="Elasticsearch" width="50%" height="50%" title="Elasticsearch" /></p>"""
);
}

Expand All @@ -90,11 +90,11 @@ public class InlineImageWithPixelSizingTest(ITestOutputHelper output) : InlineTe
public void GeneratesAttributesInHtml() =>
// language=html
Html.ShouldContainHtml(
"""<p><img src="/docs/_static/img/observability.png" alt="Elasticsearch" width="250px" height="330px" /></p>"""
"""<p><img src="/docs/_static/img/observability.png" alt="Elasticsearch" width="250px" height="330px" title="Elasticsearch" /></p>"""
);
}

// 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<LinkInline>(output,
"""
![Elasticsearch](/_static/img/observability.png "My Title =50%")
Expand All @@ -108,7 +108,7 @@ public class InlineImageWithTitleAndSizingTest(ITestOutputHelper output) : Inlin
public void GeneratesAttributesInHtml() =>
// language=html
Html.ShouldContainHtml(
"""<p><img src="/docs/_static/img/observability.png" alt="Elasticsearch" title="My Title" width="50%" height="50%" /></p>"""
"""<p><img src="/docs/_static/img/observability.png" alt="Elasticsearch" width="50%" height="50%" title="Elasticsearch" /></p>"""
);
}

Expand All @@ -126,6 +126,6 @@ public class InlineImageWithWidthOnlyTest(ITestOutputHelper output) : InlineTest
public void GeneratesAttributesInHtml() =>
// language=html
Html.ShouldContainHtml(
"""<p><img src="/docs/_static/img/observability.png" alt="Elasticsearch" width="250px" height="250px" /></p>"""
"""<p><img src="/docs/_static/img/observability.png" alt="Elasticsearch" width="250px" height="250px" title="Elasticsearch" /></p>"""
);
}
2 changes: 1 addition & 1 deletion tests/Elastic.Markdown.Tests/PrettyHtmlExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions tests/Elastic.Markdown.Tests/PrettyHtmlExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -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 = """
<p>Rendered output</p>
""";

var expected = """
<strong>Missing output</strong>
""";

var act = () => actual.ShouldContainHtml(expected);

act.Should().Throw<XunitException>();
}
}
Loading