Skip to content

Commit e8aceee

Browse files
commonmark: for link don't fallback to title anymore
1 parent 1aa78e4 commit e8aceee

File tree

3 files changed

+39
-8
lines changed

3 files changed

+39
-8
lines changed

plugin/commonmark/render_link.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,6 @@ func (c *commonmark) renderLink(ctx converter.Context, w converter.Writer, n *ht
7171
ctx.RenderChildNodes(ctx, &buf, n)
7272
content := buf.Bytes()
7373

74-
if len(bytes.TrimSpace(content)) == 0 {
75-
// Fallback to the title
76-
content = []byte(l.title)
77-
}
7874
if len(bytes.TrimSpace(content)) == 0 && c.config.LinkEmptyContentBehavior == LinkBehaviorSkip {
7975
// There is *no content* inside the link. Now we have two options:
8076
// Continue rendering as a link OR skip to let other renderers take over.

plugin/commonmark/testdata/GoldenFiles/link.in.html

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
</a></p>
1919
<p><a href="/no_content"><br /></a></p>
2020

21-
<!--no content but fallback-->
21+
<!--no content but title-->
2222
<p><a href="/no_content" title="link title"></a></p>
2323

2424

@@ -116,6 +116,29 @@
116116
<p>before <a href="/">A</a> middle <a href="/">B</a> after</p>
117117

118118

119+
<!--------------------------------------
120+
Anchor Links in Headings
121+
--------------------------------------->
122+
123+
<h1 id="intro">
124+
<a href="#intro">Introduction</a>
125+
</h1>
126+
127+
<h1 id="intro">
128+
<a href="#intro" class="anchor"></a>
129+
Introduction
130+
</h1>
131+
132+
<h1 id="intro">
133+
Introduction
134+
<a href="#intro" class="anchor">#</a>
135+
</h1>
136+
137+
<h1 id="intro">
138+
<a href="#intro" class="anchor">🔗</a>
139+
Introduction
140+
</h1>
141+
119142

120143
<!--------------------------------------
121144
Content and Combinations

plugin/commonmark/testdata/GoldenFiles/link.out.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424

2525
[](/no_content)
2626

27-
<!--no content but fallback-->
27+
<!--no content but title-->
2828

29-
[link title](/no_content "link title")
29+
[](/no_content "link title")
3030

3131
* * *
3232

@@ -120,6 +120,18 @@ before [A](/) middle [B](/) after
120120

121121
before [A](/) middle [B](/) after
122122

123+
<!--------------------------------------
124+
Anchor Links in Headings
125+
--------------------------------------->
126+
127+
# [Introduction](#intro)
128+
129+
# [](#intro)Introduction
130+
131+
# Introduction [#](#intro)
132+
133+
# [🔗](#intro) Introduction
134+
123135
<!--------------------------------------
124136
Content and Combinations
125137
--------------------------------------->
@@ -200,7 +212,7 @@ second text](/page.html)
200212

201213
<!--link with an svg-->
202214

203-
[title](/ "title")
215+
[](/ "title")
204216

205217
<!-- link and strong inside word -->
206218

0 commit comments

Comments
 (0)