allow inline links with empty link text. see #101

This commit is contained in:
jsteuer 2020-02-16 17:56:09 +01:00
parent 70a5404a11
commit 2a86c1ea31
2 changed files with 23 additions and 5 deletions

View file

@ -42,3 +42,26 @@ func TestSpec(t *testing.T) {
))
testutil.DoTestCases(markdown, cases, t)
}
func TestSpec_EdgeCase_LinkWithEmptyText(t *testing.T) {
// TODO: maybe this test cases will be part of the official spec in the future.
// check: https://github.com/commonmark/commonmark-spec/issues/636
cases := []testutil.MarkdownTestCase{
testutil.MarkdownTestCase{
No: -1,
Markdown: "[](./target.md)",
Expected: "<p><a href=\"./target.md\"></a></p>",
},
testutil.MarkdownTestCase{
No: -1,
Markdown: "[]()",
Expected: "<p><a href=\"\"></a></p>",
},
}
markdown := New(WithRendererOptions(
html.WithXHTML(),
html.WithUnsafe(),
))
testutil.DoTestCases(markdown, cases, t)
}

View file

@ -147,11 +147,6 @@ func (s *linkParser) Parse(parent ast.Node, block text.Reader, pc Context) ast.N
ast.MergeOrReplaceTextSegment(last.Parent(), last, last.Segment)
return nil
}
labelValue := block.Value(text.NewSegment(last.Segment.Start+1, segment.Start))
if util.IsBlank(labelValue) && !last.IsImage {
ast.MergeOrReplaceTextSegment(last.Parent(), last, last.Segment)
return nil
}
c := block.Peek()
l, pos := block.Position()