diff --git a/src/Markdig.Tests/TestImageAltText.cs b/src/Markdig.Tests/TestImageAltText.cs new file mode 100644 index 000000000..db6626036 --- /dev/null +++ b/src/Markdig.Tests/TestImageAltText.cs @@ -0,0 +1,25 @@ +using NUnit.Framework; +using System.Text.RegularExpressions; + +namespace Markdig.Tests +{ + [TestFixture] + public class TestImageAltText + { + [Test] + [TestCase("![](image.jpg)", "")] + [TestCase("![foo](image.jpg)", "foo")] + [TestCase("![][1]\n\n[1]: image.jpg", "")] + [TestCase("![bar][1]\n\n[1]: image.jpg", "bar")] + [TestCase("![](image.jpg 'title')", "")] + [TestCase("![foo](image.jpg 'title')", "foo")] + [TestCase("![][1]\n\n[1]: image.jpg 'title'", "")] + [TestCase("![bar][1]\n\n[1]: image.jpg 'title'", "bar")] + public void TestImageHtmlAltText(string markdown, string expectedAltText) + { + string html = Markdown.ToHtml(markdown); + string actualAltText = Regex.Match(html, "alt=\"(.*?)\"").Groups[1].Value; + Assert.AreEqual(expectedAltText, actualAltText); + } + } +} diff --git a/src/Markdig/Parsers/Inlines/LinkInlineParser.cs b/src/Markdig/Parsers/Inlines/LinkInlineParser.cs index 21ebcee47..fb4c67ea5 100644 --- a/src/Markdig/Parsers/Inlines/LinkInlineParser.cs +++ b/src/Markdig/Parsers/Inlines/LinkInlineParser.cs @@ -136,7 +136,7 @@ private bool ProcessLinkReference(InlineProcessor state, string label, bool isSh { child = new LiteralInline() { - Content = new StringSlice(label), + Content = StringSlice.Empty, IsClosed = true, // Not exact but we leave it like this Span = parent.Span,