@@ -154,6 +154,41 @@ def test_use_plugin(self):
154154 md = mistune .Markdown (mistune .HTMLRenderer ())
155155 md .use (url )
156156
157+ def test_inline_plugin_refreshes_fast_trigger_cache (self ):
158+ def parse_at (inline , m , state ):
159+ state .append_token ({"type" : "at" , "raw" : m .group (0 )})
160+ return m .end ()
161+
162+ def render_at (renderer , text ):
163+ return "<at>" + text + "</at>"
164+
165+ def plugin (md ):
166+ md .inline .register ("at" , r"@+" , parse_at )
167+ md .renderer .register ("at" , render_at )
168+
169+ md = mistune .create_markdown (escape = False )
170+ md ("plain text" )
171+ md .use (plugin )
172+
173+ self .assertEqual (md ("@@" ).strip (), "<p><at>@@</at></p>" )
174+
175+ def test_inline_plugin_with_untracked_trigger_uses_regex_scanner (self ):
176+ def parse_x (inline , m , state ):
177+ state .append_token ({"type" : "xword" , "raw" : m .group (0 )})
178+ return m .end ()
179+
180+ def render_x (renderer , text ):
181+ return "<x>" + text + "</x>"
182+
183+ def plugin (md ):
184+ md .inline .register ("xword" , r"(?=x)x+" , parse_x )
185+ md .renderer .register ("xword" , render_x )
186+
187+ md = mistune .create_markdown (escape = False )
188+ md .use (plugin )
189+
190+ self .assertEqual (md ("xx" ).strip (), "<p><x>xx</x></p>" )
191+
157192 def test_markdown_func (self ):
158193 result = mistune .markdown ("**b**" )
159194 expected = "<p><strong>b</strong></p>\n "
@@ -248,11 +283,18 @@ def test_html_tag_text_following_list(self):
248283 expected = "<p>foo</p>\n <ul>\n <li>bar</li>\n </ul>\n <p>table</p>"
249284 self .assertEqual (result .strip (), expected )
250285
286+ def test_max_nested_level_setting (self ):
287+ self .assertEqual (mistune .BlockParser ().max_nested_level , 20 )
288+ self .assertEqual (mistune .create_markdown ().block .max_nested_level , 20 )
289+ md = mistune .Markdown (block = mistune .BlockParser (max_nested_level = 7 ))
290+ self .assertEqual (md .block .max_nested_level , 7 )
291+
251292 def test_deeply_nested_block_quote_and_list (self ):
252293 # Block quotes and lists each capped their own nesting at the limit but
253294 # not each other's, so alternating them recursed without bound. This
254295 # must terminate instead of raising RecursionError.
255- text = "" .join (">" * i + " " + "- " * i + "item\n " for i in range (1 , 300 ))
296+ max_level = mistune .create_markdown ().block .max_nested_level
297+ text = "" .join (">" * i + " " + "- " * i + "item\n " for i in range (1 , max_level + 80 ))
256298 md = mistune .create_markdown ()
257299 md (text )
258300 ast = mistune .create_markdown (renderer = "ast" )
0 commit comments