From 2a86c1ea310d72f978a48de6501d35fb0c832d14 Mon Sep 17 00:00:00 2001 From: jsteuer Date: Sun, 16 Feb 2020 17:56:09 +0100 Subject: [PATCH] allow inline links with empty link text. see #101 --- commonmark_test.go | 23 +++++++++++++++++++++++ parser/link.go | 5 ----- 2 files changed, 23 insertions(+), 5 deletions(-) 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()