Skip to content

Commit

Permalink
Merge branch 'add-codeblock-type'
Browse files Browse the repository at this point in the history
* add-codeblock-type:
  Add message for 4.0.1
  Add test for ~~~ code block
  Support code block with ~~~ pattern #146
  Fix tests
  • Loading branch information
naokazuterada committed Feb 23, 2020
2 parents 48741e4 + 6a6e537 commit 49b7cd0
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 11 deletions.
2 changes: 1 addition & 1 deletion markdowntoc/markdowntoc_insert.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ def get_attributes_from(self, tag_str):

def remove_items_in_codeblock(self, items):

codeblocks = self.view.find_all("^\s*`{3,}[^`]*$")
codeblocks = self.view.find_all("^\s*(`{3,}|~{3,})\S*")
codeblockAreas = [] # [[area_begin, area_end], ..]
i = 0
while i < len(codeblocks) - 1:
Expand Down
13 changes: 13 additions & 0 deletions messages/4.0.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# MarkdownTOC - 4.0.1

---

**NOTE: 4.x may have "breaking changes"**

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.

---

## Changes

- Fix the problem in ignoring comments in blocks of code Ref: [#146](https://github.com/naokazuterada/MarkdownTOC/issues/146)
51 changes: 41 additions & 10 deletions tests/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,27 +50,58 @@ def test_ignore_inside_codeblock(self):
"""
# Outside1
# heading1
```
# Inseide
# heading2
```
# Outside2
```markdown
# heading3
```
```
# Inseide2
# Inseide3
# heading4
# heading5
```
"""
toc = self.init_insert(text)
self.assert_In('Outside1', toc)
self.assert_In('Outside2', toc)
self.assert_NotIn('Inside1', toc)
self.assert_NotIn('Inside2', toc)
self.assert_NotIn('Inside3', toc)
self.assert_In('heading1', toc)
self.assert_NotIn('heading3', toc)
self.assert_NotIn('heading2', toc)
self.assert_NotIn('heading4', toc)
self.assert_NotIn('heading5', toc)

def test_ignore_inside_codeblock_alt(self):
text = \
"""
# heading1
~~~
# heading2
~~~
~~~markdown
# heading3
~~~
~~~
# heading4
# heading5
~~~
"""
toc = self.init_insert(text)
self.assert_In('heading1', toc)
self.assert_NotIn('heading3', toc)
self.assert_NotIn('heading2', toc)
self.assert_NotIn('heading4', toc)
self.assert_NotIn('heading5', toc)

def test_escape_link(self):
text = \
Expand Down

0 comments on commit 49b7cd0

Please sign in to comment.