Skip to content

Commit debb56e

Browse files
Fix Tests (#4)
* Fix tests * only one test * no coverage for now * change name
1 parent 090acb7 commit debb56e

File tree

15 files changed

+182
-209
lines changed

15 files changed

+182
-209
lines changed

.github/workflows/go.yml

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Go
1+
name: Tests
22

33
on:
44
push:
@@ -7,19 +7,15 @@ on:
77
branches: [ master ]
88

99
jobs:
10-
11-
# Test the latest go version
12-
# and upload the test coverage.
13-
test_latest:
14-
name: Go latest stable
10+
tests:
11+
name: Run tests
1512

1613
runs-on: ubuntu-latest
1714
steps:
1815
- name: Setup Go
1916
uses: actions/setup-go@v5
2017
with:
21-
go-version: 'stable'
22-
check-latest: true
18+
go-version: '1.24'
2319

2420
- name: Checkout code
2521
uses: actions/checkout@v4
@@ -28,33 +24,4 @@ jobs:
2824
run: go build -v .
2925

3026
- name: Test
31-
run: go test ./... -v -race -coverprofile=coverage.txt -covermode=atomic
32-
33-
- uses: codecov/codecov-action@v4
34-
with:
35-
files: ./coverage.txt
36-
token: ${{ secrets.CODECOV_TOKEN }}
37-
38-
# Test the latest three golang version
39-
# on different operating systems.
40-
test_versions:
41-
strategy:
42-
matrix:
43-
go: ['1.20', '1.21', '1.22']
44-
# TODO: also test on 'windows-latest'
45-
os: [ubuntu-latest, macos-latest]
46-
name: Go ${{ matrix.go }} on ${{ matrix.os }}
47-
48-
runs-on: ${{ matrix.os }}
49-
steps:
50-
- name: Setup Go
51-
uses: actions/setup-go@v5
52-
with:
53-
go-version: ${{ matrix.go }}
54-
55-
- name: Checkout code
56-
uses: actions/checkout@v4
57-
58-
- name: Test
59-
run: go test ./... -v -race -cover
60-
27+
run: go test ./... -v -race

markdown.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ var indentR = regexp.MustCompile(`(?m)\n`)
178178

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

213217
selec.Contents().Each(func(i int, s *goquery.Selection) {
218+
nodeName := goquery.NodeName(s)
219+
220+
// Check if this element should be removed before processing
221+
conv.mutex.RLock()
222+
_, shouldRemove := conv.remove[nodeName]
223+
conv.mutex.RUnlock()
224+
225+
if shouldRemove {
226+
// Skip processing removed elements entirely
227+
return
228+
}
229+
214230
content := conv.selecToMD(s, opt)
215231
result.accumulate(content)
216232

217-
ruleResult, useOriginal := conv.applyRules(goquery.NodeName(s), content.Markdown, s, opt)
233+
ruleResult, useOriginal := conv.applyRules(nodeName, content.Markdown, s, opt)
218234
result.accumulate(ruleResult)
219235

220236
if !useOriginal {
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
<p><!-- raw HTML omitted --><!-- raw HTML omitted -->Content<!-- raw HTML omitted --><!-- raw HTML omitted --></p>
1+
<p><!-- raw HTML omitted --><!-- raw HTML omitted -->Content<!-- raw HTML omitted --><!-- raw HTML omitted -->
2+
Please enable Javascript!!!</p>
3+
<!-- raw HTML omitted -->
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
<keep-tag><p>Content</p></keep-tag>
1+
<keep-tag><p>Content</p></keep-tag>
2+
Please enable Javascript!!!
3+
4+
<img src="https://example.cm/funny.gif">
5+
[iframe](https://www.w3schools.com)

testdata/TestCommonmark/list/output.asterisks.golden

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
13. 13
2020
14. 14
2121
15. 15
22+
2223
19. 16
2324
20. 17
2425
21. 18

testdata/TestCommonmark/list/output.dash.golden

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
13. 13
2020
14. 14
2121
15. 15
22+
2223
19. 16
2324
20. 17
2425
21. 18

testdata/TestCommonmark/list/output.plus.golden

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
13. 13
2020
14. 14
2121
15. 15
22+
2223
19. 16
2324
20. 17
2425
21. 18

testdata/TestCommonmark/pre_code/goldmark.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ The tag is used to embed an image.
4444

4545
</code></pre>
4646
<pre><code>
47-
47+
[![](http://bla.bla/img/img.svg)](http://example.com#Blabla)
4848

4949
</code></pre>
5050
<p>We can do this like so:</p>

testdata/TestCommonmark/pre_code/output.fenced_backtick.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ The tag is used to embed an image.
8181

8282
```
8383

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

8686
```
8787

testdata/TestCommonmark/pre_code/output.fenced_tilde.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ The tag is used to embed an image.
8181

8282
~~~
8383

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

8686
~~~
8787

0 commit comments

Comments
 (0)