diff --git a/CHANGES.md b/CHANGES.md index 5bae00f1..df1e3808 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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 - [pull #463] Fix multilevel lists diff --git a/lib/markdown2.py b/lib/markdown2.py index ff760d97..e7ce931b 100755 --- a/lib/markdown2.py +++ b/lib/markdown2.py @@ -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): @@ -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) @@ -1864,14 +1864,20 @@ def _wrap_code(self, inner): yield tup yield 0, "" + def _add_newline(self, inner): + # Add newlines around the inner contents so that _strict_tag_block_re matches the outer div. + yield 0, "\n" + yield from inner + yield 0, "\n" + def wrap(self, source, outfile=None): """Return the source with a code, pre, and div.""" if outfile is None: # pygments >= 2.12 - return self._wrap_pre(self._wrap_code(source)) + return self._add_newline(self._wrap_pre(self._wrap_code(source))) else: # pygments < 2.12 - return self._wrap_div(self._wrap_pre(self._wrap_code(source))) + return self._wrap_div(self._add_newline(self._wrap_pre(self._wrap_code(source)))) formatter_opts.setdefault("cssclass", "codehilite") formatter = HtmlCodeFormatter(**formatter_opts) diff --git a/test/tm-cases/admonitions_with_fenced_code_blocks.html b/test/tm-cases/admonitions_with_fenced_code_blocks.html index 6946ba16..7428c571 100644 --- a/test/tm-cases/admonitions_with_fenced_code_blocks.html +++ b/test/tm-cases/admonitions_with_fenced_code_blocks.html @@ -1,25 +1,35 @@ -
# admonitions WITHIN fenced code blocks should NOT be rendered
+
+# admonitions WITHIN fenced code blocks should NOT be rendered
.. attention:: title
body
-
+
+some code block
-some code block
+
+yet another code block
diff --git a/test/tm-cases/fenced_code_blocks_issue426.html b/test/tm-cases/fenced_code_blocks_issue426.html
index 152711ba..66b1cb9c 100644
--- a/test/tm-cases/fenced_code_blocks_issue426.html
+++ b/test/tm-cases/fenced_code_blocks_issue426.html
@@ -14,18 +14,22 @@ generic.View) from django.forms.generic inherit from ContextMixinContextMixin defines the method get_context_data:
def get_context_data(self, **kwargs):
+
+def get_context_data(self, **kwargs):
kwargs.setdefault('view', self)
if self.extra_context is not None:
kwargs.update(self.extra_context)
return kwargs
-
+
+So when overriding one must be careful to extends super's kwargs:
def get_context_data(self, **kwargs):
+
+def get_context_data(self, **kwargs):
kwargs = super().get_context_data(**kwargs)
kwargs['page_title'] = "Documentation"
return kwargs
-
+
+x = 1
+
+if True:
+
+if True:
print "hi"
-
+
+if True:
+
+if True:
print "hi"
-
+
+That's using the fenced-code-blocks extra with Python
syntax coloring, if pygments is installed. See
http://github.github.com/github-flavored-markdown/.
def foo
+
+def foo
puts "hi"
end
-
+
+if True:
+
+if True:
print "hi"
-
+
+That's using the fenced-code-blocks extra with Python
syntax coloring, if pygments is installed. See
http://github.github.com/github-flavored-markdown/.
def foo
+
+def foo
puts "hi"
end
-
+
+def foo():
+
+def foo():
print "foo"
print "bar"
-
+
+empty codeblock just for sh*ts and giggles
-test with language set
-test with language set
+
+This is a regular code block
Multiline
diff --git a/test/tm-cases/issue3_bad_code_color_hack.html b/test/tm-cases/issue3_bad_code_color_hack.html
index 8aedb76c..2fff7bfb 100644
--- a/test/tm-cases/issue3_bad_code_color_hack.html
+++ b/test/tm-cases/issue3_bad_code_color_hack.html
@@ -6,7 +6,9 @@ заголовок
Some python code:
-# комментарий
+
+# комментарий
if True:
print "hi"
-
+
+
diff --git a/test/tm-cases/pyshell_and_fenced_code_blocks.html b/test/tm-cases/pyshell_and_fenced_code_blocks.html
index a9fc2cf6..28b13705 100644
--- a/test/tm-cases/pyshell_and_fenced_code_blocks.html
+++ b/test/tm-cases/pyshell_and_fenced_code_blocks.html
@@ -2,20 +2,36 @@ From Recipe 302035
Some examples:
->>> nprint(9876543210)
+
+>>> nprint(9876543210)
'9 876 543 210'
>>> nprint(987654321, period=1, delimiter=",")
'9,8,7,6,5,4,3,2,1,0'
-
+
+
Indented a bit:
->>> 1 + 1
+
+>>> 1 + 1
2
-
+
+
+
+Part of blockquote:
+
+
+
+>>> 1 + 1
+2
+
+
+
Cuddled to previous para (and at end of document):
->>> 2 + 2
+
+>>> 2 + 2
4
-
+
+
diff --git a/test/tm-cases/pyshell_and_fenced_code_blocks.text b/test/tm-cases/pyshell_and_fenced_code_blocks.text
index fc1eaae4..f718ec9e 100644
--- a/test/tm-cases/pyshell_and_fenced_code_blocks.text
+++ b/test/tm-cases/pyshell_and_fenced_code_blocks.text
@@ -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
diff --git a/test/tm-cases/quoted_fenced_code_blocks_whitespace_around_indented_lines.html b/test/tm-cases/quoted_fenced_code_blocks_whitespace_around_indented_lines.html
index 6f344f05..58d5d439 100644
--- a/test/tm-cases/quoted_fenced_code_blocks_whitespace_around_indented_lines.html
+++ b/test/tm-cases/quoted_fenced_code_blocks_whitespace_around_indented_lines.html
@@ -1,7 +1,8 @@
Example:
- if True:
+
+if True:
print()
print()
@@ -9,5 +10,6 @@ Example:
print()
print()
-
+
+
diff --git a/test/tm-cases/syntax_color.html b/test/tm-cases/syntax_color.html
index ae9ea34d..e2d77d6c 100644
--- a/test/tm-cases/syntax_color.html
+++ b/test/tm-cases/syntax_color.html
@@ -1,15 +1,19 @@
Here is some sample code:
-import sys
+
+import sys
def main(argv=sys.argv):
logging.basicConfig()
log.info('hi')
-
+
+
and:
-use 'zlib'
+
+use 'zlib'
sub main(argv)
puts 'hi'
end
-
+
+
diff --git a/test/tm-cases/syntax_color_opts.html b/test/tm-cases/syntax_color_opts.html
index a44e49d2..7ac05d15 100644
--- a/test/tm-cases/syntax_color_opts.html
+++ b/test/tm-cases/syntax_color_opts.html
@@ -1,15 +1,19 @@
Here is some sample code:
-import sys
+
+import sys
def main(argv=sys.argv):
logging.basicConfig()
log.info('hi')
-
+
+
and:
-use 'zlib'
+
+use 'zlib'
sub main(argv)
puts 'hi'
end
-
+
+