Skip to content

Commit

Permalink
fix pyshell blocks in blockquotes, refs mitmproxy/pdoc#429
Browse files Browse the repository at this point in the history
  • Loading branch information
mhils committed Aug 11, 2022
1 parent 71c94f5 commit f1634cc
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
- [pull #455] Fix code block indentation in lists
- [pull #434] Fix filter bypass leading to XSS (#362)
- [pull #464] Fix html-classes extra not applying to code spans
- [pull #462] Fix pygments block matching
- [pull #462] Fix pyshell blocks in blockquotes


## python-markdown2 2.4.3
Expand Down
4 changes: 2 additions & 2 deletions lib/markdown2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,7 @@ def _pyshell_block_sub(self, match):
indent = ' ' * self.tab_width
s = ('\n' # separate from possible cuddled paragraph
+ indent + ('\n'+indent).join(lines)
+ '\n\n')
+ '\n')
return s

def _prepare_pyshell_blocks(self, text):
Expand All @@ -1070,7 +1070,7 @@ def _prepare_pyshell_blocks(self, text):
_pyshell_block_re = re.compile(r"""
^([ ]{0,%d})>>>[ ].*\n # first line
^(\1[^\S\n]*\S.*\n)* # any number of subsequent lines with at least one character
^\n # ends with a blank line
(?=^\1?\n|\Z) # ends with a blank line or end of document
""" % less_than_tab, re.M | re.X)

return _pyshell_block_re.sub(self._pyshell_block_sub, text)
Expand Down
10 changes: 10 additions & 0 deletions test/tm-cases/pyshell_and_fenced_code_blocks.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ <h1>From Recipe 302035</h1>
</code></pre>
</div>

<p>Part of blockquote:</p>

<blockquote>
<div class="codehilite">
<pre><span></span><code><span class="gp">&gt;&gt;&gt; </span><span class="mi">1</span> <span class="o">+</span> <span class="mi">1</span>
<span class="go">2</span>
</code></pre>
</div>
</blockquote>

<p>Cuddled to previous para (and at end of document):</p>

<div class="codehilite">
Expand Down
5 changes: 5 additions & 0 deletions test/tm-cases/pyshell_and_fenced_code_blocks.text
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ Indented a bit:
>>> 1 + 1
2

Part of blockquote:

> >>> 1 + 1
> 2

Cuddled to previous para (and at end of document):
>>> 2 + 2
4

0 comments on commit f1634cc

Please # to comment.