Skip to content

Commit

Permalink
Fix max nested level for block parser
Browse files Browse the repository at this point in the history
  • Loading branch information
lepture committed Jul 7, 2022
1 parent de3390b commit b117a18
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
max-parallel: 6
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python: ["2.7", "3.6", "3.7", "3.8", "3.9", "3.10", "pypy2", "pypy3"]
python: ["3.7", "3.8", "3.9", "3.10", "pypy3"]

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion mistune3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def create_markdown(escape=True, hard_wrap=False, renderer='html', plugins=None)
__cached_parsers = {}


def markdown(text, escape=True, renderer=None, plugins=None):
def markdown(text, escape=True, renderer='html', plugins=None):
key = (escape, renderer, plugins)
if key in __cached_parsers:
return __cached_parsers[key](text)
Expand Down
2 changes: 1 addition & 1 deletion mistune3/block_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def parse_block_quote(self, m, state):

# scan children state
child = state.child_state(text)
if state.depth() >= self.max_nested_level:
if state.depth() >= self.max_nested_level - 1:
rules = list(self.block_quote_rules)
rules.remove('block_quote')
else:
Expand Down
2 changes: 1 addition & 1 deletion mistune3/list_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
def parse_list(block, attrs, groups, state):
depth = state.depth()
attrs['depth'] = depth
if depth >= block.max_nested_level:
if depth >= block.max_nested_level - 1:
rules = list(block.list_rules)
rules.remove('list')
else:
Expand Down
55 changes: 55 additions & 0 deletions tests/fixtures/fix-commonmark.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,58 @@ CommonMark would still be a mess:
```
<p>*a *<em>b c</em> d</p>
```


## Max depth


```````````````````````````````` example
> > > > > > > > b
.
<blockquote>
<blockquote>
<blockquote>
<blockquote>
<blockquote>
<blockquote>
<p>&gt; &gt; b</p>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
````````````````````````````````


```````````````````````````````` example
- a
- b
- c
- d
- e
- f
- g
- h
.
<ul>
<li>a<ul>
<li>b<ul>
<li>c<ul>
<li>d<ul>
<li>e<ul>
<li>f
- g
- h</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
````````````````````````````````
9 changes: 9 additions & 0 deletions tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,12 @@ def test_use_plugin(self):
from mistune3.plugins.url import url
md = mistune.Markdown(mistune.HTMLRenderer())
md.use(url)

def test_markdown_func(self):
result = mistune.markdown('**b**')
expected = '<p><strong>b</strong></p>\n'
self.assertEqual(result, expected)

# trigger to use cached parser
result = mistune.markdown('**b**')
self.assertEqual(result, expected)

0 comments on commit b117a18

Please sign in to comment.