Skip to content

Commit

Permalink
fix link title w. quote, multiple headings in link
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesKaufmann committed Jun 13, 2021
1 parent d5f4e55 commit 9cd4bbd
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 5 deletions.
3 changes: 3 additions & 0 deletions commonmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ var commonmark = []Rule{
insideLink := selec.ParentsFiltered("a").Length() > 0
if insideLink {
text := opt.StrongDelimiter + content + opt.StrongDelimiter
text = AddSpaceIfNessesary(selec, text)
return &text
}

Expand Down Expand Up @@ -219,6 +220,8 @@ var commonmark = []Rule{
var title string
if t, ok := selec.Attr("title"); ok {
t = strings.Replace(t, "\n", " ", -1)
// escape all quotes
t = strings.Replace(t, `"`, `\"`, -1)
title = fmt.Sprintf(` "%s"`, t)
}

Expand Down
19 changes: 19 additions & 0 deletions testdata/TestCommonmark/link/input.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,22 @@
<!--links directly next to each other-->
<p>Before<a href="http://example_close.com">close</a>After</p>
<br />


<!--link with headings-->
<a href="/page.html">
<h4>Heading A</h4>
<h3>Heading B</h3>
</a>
<br />


<!--link with quotes in title-->
<a
href="/page.html"
title="&quot;Vermögenssteuer ist aus wirtschaftlicher Sicht klug&quot;"
>
<span class="teaser__kicker">DIW-Chef zum Grünen-Programm</span>
<span class="teaser__headline"> "Vermögenssteuer ist aus wirtschaftlicher Sicht klug"</span>
</a>
<br />
6 changes: 5 additions & 1 deletion testdata/TestCommonmark/link/output.inlined.golden
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ Second Text](http://multi.org/)

[first left](http://first_next.com) [second right](http://second_next.com)

Before [close](http://example_close.com) After
Before [close](http://example_close.com) After

[**Heading A** **Heading B**](http://example.com/page.html)

[DIW-Chef zum Grünen-Programm "Vermögenssteuer ist aus wirtschaftlicher Sicht klug"](http://example.com/page.html "\"Vermögenssteuer ist aus wirtschaftlicher Sicht klug\"")
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ Second Text][]

Before [close][] After

[**Heading A** **Heading B**][]

[DIW-Chef zum Grünen-Programm "Vermögenssteuer ist aus wirtschaftlicher Sicht klug"][]

[Simple Absolute Link]: http://simple.org/
[Simple Relative Link]: http://example.com/page.html
[Link with Space]: http://space.org/
Expand All @@ -45,4 +49,6 @@ Second Text]: http://list.org/
[second below]: http://second_under.com
[first left]: http://first_next.com
[second right]: http://second_next.com
[close]: http://example_close.com
[close]: http://example_close.com
[**Heading A** **Heading B**]: http://example.com/page.html
[DIW-Chef zum Grünen-Programm "Vermögenssteuer ist aus wirtschaftlicher Sicht klug"]: http://example.com/page.html "\"Vermögenssteuer ist aus wirtschaftlicher Sicht klug\""
8 changes: 7 additions & 1 deletion testdata/TestCommonmark/link/output.referenced_full.golden
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ Second Text][7]

Before [close][14] After

[**Heading A** **Heading B**][15]

[DIW-Chef zum Grünen-Programm "Vermögenssteuer ist aus wirtschaftlicher Sicht klug"][16]

[1]: http://simple.org/
[2]: http://example.com/page.html
[3]: http://space.org/
Expand All @@ -40,4 +44,6 @@ Before [close][14] After
[11]: http://second_under.com
[12]: http://first_next.com
[13]: http://second_next.com
[14]: http://example_close.com
[14]: http://example_close.com
[15]: http://example.com/page.html
[16]: http://example.com/page.html "\"Vermögenssteuer ist aus wirtschaftlicher Sicht klug\""
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ Second Text]

Before [close] After

[**Heading A** **Heading B**]

[DIW-Chef zum Grünen-Programm "Vermögenssteuer ist aus wirtschaftlicher Sicht klug"]

[Simple Absolute Link]: http://simple.org/
[Simple Relative Link]: http://example.com/page.html
[Link with Space]: http://space.org/
Expand All @@ -45,4 +49,6 @@ Second Text]: http://list.org/
[second below]: http://second_under.com
[first left]: http://first_next.com
[second right]: http://second_next.com
[close]: http://example_close.com
[close]: http://example_close.com
[**Heading A** **Heading B**]: http://example.com/page.html
[DIW-Chef zum Grünen-Programm "Vermögenssteuer ist aus wirtschaftlicher Sicht klug"]: http://example.com/page.html "\"Vermögenssteuer ist aus wirtschaftlicher Sicht klug\""
6 changes: 5 additions & 1 deletion testdata/TestCommonmark/link/output.relative.golden
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ Second Text](http://multi.org/)

[first left](http://first_next.com) [second right](http://second_next.com)

Before [close](http://example_close.com) After
Before [close](http://example_close.com) After

[**Heading A** **Heading B**](/page.html)

[DIW-Chef zum Grünen-Programm "Vermögenssteuer ist aus wirtschaftlicher Sicht klug"](/page.html "\"Vermögenssteuer ist aus wirtschaftlicher Sicht klug\"")

0 comments on commit 9cd4bbd

Please sign in to comment.