Skip to content

Commit

Permalink
Merge pull request #254 from MihaZupan/issue_251
Browse files Browse the repository at this point in the history
Empty image alt text for link reference definitions
  • Loading branch information
xoofx authored Oct 7, 2018
2 parents 2501c6a + 1b54bb1 commit 07e6a13
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 25 additions & 0 deletions src/Markdig.Tests/TestImageAltText.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
2 changes: 1 addition & 1 deletion src/Markdig/Parsers/Inlines/LinkInlineParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 07e6a13

Please sign in to comment.