extension which allowes to parse links with empty link text

pull/581/head
jsteuer 2020-02-15 23:09:06 +01:00
parent 3e56bb68c8
commit df0dfd23f8
3 changed files with 18 additions and 3 deletions

View File

@ -538,9 +538,12 @@ func link(p *Markdown, data []byte, offset int) (int, *Node) {
unescapeText(&uLinkBuf, link)
uLink = uLinkBuf.Bytes()
}
// links need something to click on and somewhere to go
if len(uLink) == 0 || (t == linkNormal && txtE <= 1) {
// links need somewhere to go
if len(uLink) == 0 {
return 0, nil
}
// links usually need something to click on
if t == linkNormal && txtE <= 1 && p.extensions&AllowLinksWithoutText == 0 {
return 0, nil
}
}

View File

@ -466,9 +466,20 @@ func TestInlineLink(t *testing.T) {
"[link](<../>)\n",
"<p><a href=\"../\">link</a></p>\n",
"[](./dummy.md)\n",
"<p>[](./dummy.md)</p>\n",
}
doLinkTestsInline(t, tests)
var testsAllowLinksWithoutText = []string{
"[](./dummy.md)\n",
"<p><a href=\"./dummy.md\"></a></p>\n",
}
doTestsInlineParam(t, testsAllowLinksWithoutText, TestParams{
extensions: AllowLinksWithoutText,
})
}
func TestRelAttrLink(t *testing.T) {

View File

@ -47,6 +47,7 @@ const (
AutoHeadingIDs // Create the heading ID from the text
BackslashLineBreak // Translate trailing backslashes into line breaks
DefinitionLists // Render definition lists
AllowLinksWithoutText // Parse links without text, (e.g. [](./target.md)
CommonHTMLFlags HTMLFlags = UseXHTML | Smartypants |
SmartypantsFractions | SmartypantsDashes | SmartypantsLatexDashes