Skip to content

Commit 49b7cd0

Browse files
committed
Merge branch 'add-codeblock-type'
* add-codeblock-type: Add message for 4.0.1 Add test for ~~~ code block Support code block with ~~~ pattern #146 Fix tests
2 parents 48741e4 + 6a6e537 commit 49b7cd0

File tree

3 files changed

+55
-11
lines changed

3 files changed

+55
-11
lines changed

markdowntoc/markdowntoc_insert.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ def get_attributes_from(self, tag_str):
389389

390390
def remove_items_in_codeblock(self, items):
391391

392-
codeblocks = self.view.find_all("^\s*`{3,}[^`]*$")
392+
codeblocks = self.view.find_all("^\s*(`{3,}|~{3,})\S*")
393393
codeblockAreas = [] # [[area_begin, area_end], ..]
394394
i = 0
395395
while i < len(codeblocks) - 1:

messages/4.0.1.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# MarkdownTOC - 4.0.1
2+
3+
---
4+
5+
**NOTE: 4.x may have "breaking changes"**
6+
7+
If you are using 4.x for the first time and have any problems, please check [Upgrade Guide](https://github.com/naokazuterada/MarkdownTOC/releases/tag/4.0.0) at first.
8+
9+
---
10+
11+
## Changes
12+
13+
- Fix the problem in ignoring comments in blocks of code Ref: [#146](https://github.com/naokazuterada/MarkdownTOC/issues/146)

tests/default.py

+41-10
Original file line numberDiff line numberDiff line change
@@ -50,27 +50,58 @@ def test_ignore_inside_codeblock(self):
5050
"""
5151
5252
53-
# Outside1
53+
# heading1
5454
5555
```
56-
# Inseide
56+
# heading2
5757
```
5858
59-
# Outside2
59+
```markdown
60+
# heading3
61+
```
6062
6163
```
6264
63-
# Inseide2
64-
# Inseide3
65+
# heading4
66+
# heading5
6567
6668
```
6769
"""
6870
toc = self.init_insert(text)
69-
self.assert_In('Outside1', toc)
70-
self.assert_In('Outside2', toc)
71-
self.assert_NotIn('Inside1', toc)
72-
self.assert_NotIn('Inside2', toc)
73-
self.assert_NotIn('Inside3', toc)
71+
self.assert_In('heading1', toc)
72+
self.assert_NotIn('heading3', toc)
73+
self.assert_NotIn('heading2', toc)
74+
self.assert_NotIn('heading4', toc)
75+
self.assert_NotIn('heading5', toc)
76+
77+
def test_ignore_inside_codeblock_alt(self):
78+
text = \
79+
"""
80+
81+
82+
# heading1
83+
84+
~~~
85+
# heading2
86+
~~~
87+
88+
~~~markdown
89+
# heading3
90+
~~~
91+
92+
~~~
93+
94+
# heading4
95+
# heading5
96+
97+
~~~
98+
"""
99+
toc = self.init_insert(text)
100+
self.assert_In('heading1', toc)
101+
self.assert_NotIn('heading3', toc)
102+
self.assert_NotIn('heading2', toc)
103+
self.assert_NotIn('heading4', toc)
104+
self.assert_NotIn('heading5', toc)
74105

75106
def test_escape_link(self):
76107
text = \

0 commit comments

Comments
 (0)