diff --git a/commonmark_test.go b/commonmark_test.go index e1a2d1b..bd367e0 100644 --- a/commonmark_test.go +++ b/commonmark_test.go @@ -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: "

", + }, + testutil.MarkdownTestCase{ + No: -1, + Markdown: "[]()", + Expected: "

", + }, + } + markdown := New(WithRendererOptions( + html.WithXHTML(), + html.WithUnsafe(), + )) + testutil.DoTestCases(markdown, cases, t) +} diff --git a/parser/link.go b/parser/link.go index 8611194..e7c6966 100644 --- a/parser/link.go +++ b/parser/link.go @@ -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()