Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 5 additions & 38 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Go
name: Tests

on:
push:
Expand All @@ -7,19 +7,15 @@ on:
branches: [ master ]

jobs:

# Test the latest go version
# and upload the test coverage.
test_latest:
name: Go latest stable
tests:
name: Run tests

runs-on: ubuntu-latest
steps:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: 'stable'
check-latest: true
go-version: '1.24'

- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -28,33 +24,4 @@ jobs:
run: go build -v .

- name: Test
run: go test ./... -v -race -coverprofile=coverage.txt -covermode=atomic

- uses: codecov/codecov-action@v4
with:
files: ./coverage.txt
token: ${{ secrets.CODECOV_TOKEN }}

# Test the latest three golang version
# on different operating systems.
test_versions:
strategy:
matrix:
go: ['1.20', '1.21', '1.22']
# TODO: also test on 'windows-latest'
os: [ubuntu-latest, macos-latest]
name: Go ${{ matrix.go }} on ${{ matrix.os }}

runs-on: ${{ matrix.os }}
steps:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}

- name: Checkout code
uses: actions/checkout@v4

- name: Test
run: go test ./... -v -race -cover

run: go test ./... -v -race
18 changes: 17 additions & 1 deletion markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ var indentR = regexp.MustCompile(`(?m)\n`)

func (conv *Converter) applyRules(nodeName, markdown string, selec *goquery.Selection, opt *Options) (AdvancedResult, bool) {
rules := conv.getRuleFuncs(nodeName)
if rules == nil {
// Tag is in remove map, return empty result
return AdvancedResult{}, false
}
for i := len(rules) - 1; i >= 0; i-- {
res, skip := rules[i](markdown, selec, opt)
if !skip {
Expand Down Expand Up @@ -211,10 +215,22 @@ func (conv *Converter) selecToMD(selec *goquery.Selection, opt *Options) Advance
var builder strings.Builder

selec.Contents().Each(func(i int, s *goquery.Selection) {
nodeName := goquery.NodeName(s)

// Check if this element should be removed before processing
conv.mutex.RLock()
_, shouldRemove := conv.remove[nodeName]
conv.mutex.RUnlock()

if shouldRemove {
// Skip processing removed elements entirely
return
}

content := conv.selecToMD(s, opt)
result.accumulate(content)

ruleResult, useOriginal := conv.applyRules(goquery.NodeName(s), content.Markdown, s, opt)
ruleResult, useOriginal := conv.applyRules(nodeName, content.Markdown, s, opt)
result.accumulate(ruleResult)

if !useOriginal {
Expand Down
4 changes: 3 additions & 1 deletion testdata/TestCommonmark/keep_remove_tag/goldmark.golden
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
<p><!-- raw HTML omitted --><!-- raw HTML omitted -->Content<!-- raw HTML omitted --><!-- raw HTML omitted --></p>
<p><!-- raw HTML omitted --><!-- raw HTML omitted -->Content<!-- raw HTML omitted --><!-- raw HTML omitted -->
Please enable Javascript!!!</p>
<!-- raw HTML omitted -->
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
<keep-tag><p>Content</p></keep-tag>
<keep-tag><p>Content</p></keep-tag>
Please enable Javascript!!!

<img src="https://example.cm/funny.gif">
[iframe](https://www.w3schools.com)
1 change: 1 addition & 0 deletions testdata/TestCommonmark/list/output.asterisks.golden
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
13. 13
14. 14
15. 15

19. 16
20. 17
21. 18
Expand Down
1 change: 1 addition & 0 deletions testdata/TestCommonmark/list/output.dash.golden
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
13. 13
14. 14
15. 15

19. 16
20. 17
21. 18
Expand Down
1 change: 1 addition & 0 deletions testdata/TestCommonmark/list/output.plus.golden
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
13. 13
14. 14
15. 15

19. 16
20. 17
21. 18
Expand Down
2 changes: 1 addition & 1 deletion testdata/TestCommonmark/pre_code/goldmark.golden
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ The tag is used to embed an image.

</code></pre>
<pre><code>

[![](http://bla.bla/img/img.svg)](http://example.com#Blabla)

</code></pre>
<p>We can do this like so:</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ The tag is used to embed an image.

```


[![](http://bla.bla/img/img.svg)](http://example.com#Blabla)

```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ The tag is used to embed an image.

~~~


[![](http://bla.bla/img/img.svg)](http://example.com#Blabla)

~~~

Expand Down
2 changes: 1 addition & 1 deletion testdata/TestCommonmark/pre_code/output.indented.golden
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ The tag is used to embed an image.

```


[![](http://bla.bla/img/img.svg)](http://example.com#Blabla)

```

Expand Down
1 change: 1 addition & 0 deletions testdata/TestRealWorld/golang.org/goldmark.golden
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Binary distributions available for<br>
<br>
Linux, Mac OS X, Windows, and more.</a></p>
<p>Featured video</p>
<p><a href="http://www.youtube.com/embed/ytEkHepK08c">iframe</a></p>
<p>Featured articles</p>
<p><a href="http://blog.golang.org/">Read more</a></p>
<p>Build version go1.10.2.</p>
Expand Down
2 changes: 2 additions & 0 deletions testdata/TestRealWorld/golang.org/output.default.golden
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ Linux, Mac OS X, Windows, and more.](http://golang.org/dl/)

Featured video

[iframe](http://www.youtube.com/embed/ytEkHepK08c)

Featured articles

[Read more](http://blog.golang.org/)
Expand Down
Loading
Loading