Skip to content

Commit

Permalink
fix trimming of em in lists close #43
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesKaufmann committed Jan 22, 2022
1 parent c20436c commit 8bd3628
Show file tree
Hide file tree
Showing 6 changed files with 233 additions and 14 deletions.
7 changes: 6 additions & 1 deletion commonmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ var commonmark = []Rule{
text = escape.MarkdownCharacters(text)

// if its inside a list, trim the spaces to not mess up the indentation
if IndexWithText(selec) == 0 && (selec.Parent().Is("li") || selec.Parent().Is("ol") || selec.Parent().Is("ul")) {
parent := selec.Parent()
next := selec.Next()
if IndexWithText(selec) == 0 &&
(parent.Is("li") || parent.Is("ol") || parent.Is("ul")) &&
(next.Is("ul") || next.Is("ol")) {
// trim only spaces and not new lines
text = strings.Trim(text, ` `)
}

Expand Down
65 changes: 60 additions & 5 deletions testdata/TestCommonmark/list/goldmark.golden
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,49 @@
</li>
</ol>
<ul>
<li>Link:<a href="https://example.com">example</a> works</li>
<li>Link:
<li>
<p>Link: <a href="https://example.com">example</a> works</p>
</li>
<li>
<p>Link:
<a href="https://example.com">example</a>
works</p>
</li>
<li>
<p>Link:
<a href="https://example.com">example</a>
works</p>
</li>
<li>
<p>Link:
<a href="https://example.com">example</a>
works</p>
</li>
<li>
<p>Link:
<a href="https://example.com">example</a>
works</li>
works</p>
</li>
</ul>
<ol>
<li>First Thing
<li>
<p>Link: <a href="https://example.com">example</a> works</p>
</li>
<li>
<p>Link:
<a href="https://example.com">example</a>
works</p>
</li>
<li>
<p>First Thing</p>
<ul>
<li>Some Thing</li>
<li>Another Thing</li>
</ul>
</li>
<li>Second Thing</li>
<li>
<p>Second Thing</p>
</li>
</ol>
<ul>
<li>
Expand Down Expand Up @@ -129,3 +159,28 @@ with two lines.</p>
</blockquote>
</li>
</ol>
<ul>
<li>
<p><a href="http://example.com/icon"><img src="http://example.com/icon.png" alt=""></a></p>
<h3>Title</h3>
<p>Description</p>
</li>
<li>
<p>All manually reviewed <em>Drosophila melanogaster</em> entries</p>
</li>
<li>
<p>All manually reviewed <em>Drosophila pseudoobscura pseudoobscura</em> entries</p>
</li>
<li>
<p>before <em>middle</em> after</p>
</li>
<li>
<p>before <em>middle</em> after</p>
</li>
<li>
<p>before <em>middle</em> after</p>
</li>
<li>
<p>before <em>middle</em> after</p>
</li>
</ul>
55 changes: 53 additions & 2 deletions testdata/TestCommonmark/list/input.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,41 @@
</ol>


<!--list with link inside-->
<!--ul list with link inside-->
<ul>
<li>Link: <a href="https://example.com" target="_blank">example</a> works</li>
<li>
Link:
<a href="https://example.com" target="_blank">example</a>
works
</li>
<li>
Link:
<a href="https://example.com" target="_blank">example</a>
works
</li>
<li>
Link:
<a href="https://example.com" target="_blank">example</a>
works
</li>
<li>
Link:
<a href="https://example.com" target="_blank">example</a>
works
</li>
</ul>

<!--ul list with link inside-->
<ol>
<li>Link: <a href="https://example.com" target="_blank">example</a> works</li>
<li>
Link:
<a href="https://example.com" target="_blank">example</a>
works
</li>
</ol>

<!--ol with a ul inside-->
<ol>
<li>
Expand Down Expand Up @@ -112,4 +137,30 @@
<p>A block quote.</p>
</blockquote>
</li>
</ol>
</ol>


<!--list with img, heading-->
<ul>
<li>
<a href="/icon">
<img src="/icon.png" />
</a>
<div class="content">
<h3>Title</h3>
<p>Description</p>
</div>
</li>
</ul>


<!--with em-->
<ul style="list-style-type:disc">
<li>All manually reviewed <em>Drosophila melanogaster</em> entries</li>
<li>All manually reviewed <em>Drosophila pseudoobscura pseudoobscura</em> entries</li>

<li>before <em>middle</em> after</li>
<li>before<em>middle</em>after</li>
<li>before<em>middle</em> after</li>
<li>before <em>middle</em>after</li>
</ul>
40 changes: 38 additions & 2 deletions testdata/TestCommonmark/list/output.asterisks.golden
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,30 @@
24. ![](http://example.com/example.png)
25. 22

* Link:[example](https://example.com) works
* Link: [example](https://example.com) works
* Link:
[example](https://example.com)
works

* Link:
[example](https://example.com)
works

* Link:
[example](https://example.com)
works

* Link:
[example](https://example.com)
works


1. Link: [example](https://example.com) works
2. Link:
[example](https://example.com)
works


1. First Thing
* Some Thing
* Another Thing
Expand Down Expand Up @@ -66,4 +84,22 @@



> A block quote.
> A block quote.


* [![](http://example.com/icon.png)](http://example.com/icon)


### Title



Description


* All manually reviewed _Drosophila melanogaster_ entries
* All manually reviewed _Drosophila pseudoobscura pseudoobscura_ entries
* before _middle_ after
* before _middle_ after
* before _middle_ after
* before _middle_ after
40 changes: 38 additions & 2 deletions testdata/TestCommonmark/list/output.dash.golden
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,30 @@
24. ![](http://example.com/example.png)
25. 22

- Link:[example](https://example.com) works
- Link: [example](https://example.com) works
- Link:
[example](https://example.com)
works

- Link:
[example](https://example.com)
works

- Link:
[example](https://example.com)
works

- Link:
[example](https://example.com)
works


1. Link: [example](https://example.com) works
2. Link:
[example](https://example.com)
works


1. First Thing
- Some Thing
- Another Thing
Expand Down Expand Up @@ -66,4 +84,22 @@



> A block quote.
> A block quote.


- [![](http://example.com/icon.png)](http://example.com/icon)


### Title



Description


- All manually reviewed _Drosophila melanogaster_ entries
- All manually reviewed _Drosophila pseudoobscura pseudoobscura_ entries
- before _middle_ after
- before _middle_ after
- before _middle_ after
- before _middle_ after
40 changes: 38 additions & 2 deletions testdata/TestCommonmark/list/output.plus.golden
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,30 @@
24. ![](http://example.com/example.png)
25. 22

+ Link:[example](https://example.com) works
+ Link: [example](https://example.com) works
+ Link:
[example](https://example.com)
works

+ Link:
[example](https://example.com)
works

+ Link:
[example](https://example.com)
works

+ Link:
[example](https://example.com)
works


1. Link: [example](https://example.com) works
2. Link:
[example](https://example.com)
works


1. First Thing
+ Some Thing
+ Another Thing
Expand Down Expand Up @@ -66,4 +84,22 @@



> A block quote.
> A block quote.


+ [![](http://example.com/icon.png)](http://example.com/icon)


### Title



Description


+ All manually reviewed _Drosophila melanogaster_ entries
+ All manually reviewed _Drosophila pseudoobscura pseudoobscura_ entries
+ before _middle_ after
+ before _middle_ after
+ before _middle_ after
+ before _middle_ after

0 comments on commit 8bd3628

Please sign in to comment.