diff --git a/CHANGES.md b/CHANGES.md index 93e5b900..5f39cc84 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -28,6 +28,7 @@ - [pull #743] Add a `strip-syntax` option to the `header-ids` extra that leaves link URLs, image paths, inline HTML tags and emphasis markers out of header ids (#192) - [pull #747] Fix `link-patterns` extra linking text inside Markdown links and images whose label wraps onto another line - [pull #759] Fix `fenced-code-blocks` extra not recognizing code blocks whose language name contains `#` or `.`, such as `c#`, `f#` and `vb.net` +- [pull #760] Fix `fenced-code-blocks` extra ending a code block early at a line inside it that ends with backticks, such as an indented fence in a docstring ## python-markdown2 2.5.5 diff --git a/lib/markdown2.py b/lib/markdown2.py index 9be0a262..0f11442c 100755 --- a/lib/markdown2.py +++ b/lib/markdown2.py @@ -3690,7 +3690,7 @@ class FencedCodeBlocks(Extra): (?:\n+|\A\n?|(?<=\n)) (^[ \t]*`{3,})\s{0,99}?([\w+\#.-]+)?\s{0,99}?\n # $1 = opening fence (captured for back-referencing), $2 = optional lang (.*?) # $3 = code block content - \1[ \t]*\n # closing fence + ^[ ]{0,3}\1`*[ \t]*\n # closing fence ''', re.M | re.X | re.S) def test(self, text: str): diff --git a/test/tm-cases/fenced_code_blocks_closing_fence.html b/test/tm-cases/fenced_code_blocks_closing_fence.html new file mode 100644 index 00000000..37777d01 --- /dev/null +++ b/test/tm-cases/fenced_code_blocks_closing_fence.html @@ -0,0 +1,19 @@ +
def greet():
+ """Say hello.
+
+ ```
+ greet()
+ ```
+ """
+
+
+Some text between the blocks.
+ +Wrap code in ```
+
+
+closing fence indented by three spaces
+
+
+closing fence longer than the opening one
+
diff --git a/test/tm-cases/fenced_code_blocks_closing_fence.opts b/test/tm-cases/fenced_code_blocks_closing_fence.opts
new file mode 100644
index 00000000..ba411ac7
--- /dev/null
+++ b/test/tm-cases/fenced_code_blocks_closing_fence.opts
@@ -0,0 +1 @@
+{"extras": ["fenced-code-blocks"]}
diff --git a/test/tm-cases/fenced_code_blocks_closing_fence.tags b/test/tm-cases/fenced_code_blocks_closing_fence.tags
new file mode 100644
index 00000000..673cfc84
--- /dev/null
+++ b/test/tm-cases/fenced_code_blocks_closing_fence.tags
@@ -0,0 +1 @@
+extra fenced-code-blocks
diff --git a/test/tm-cases/fenced_code_blocks_closing_fence.text b/test/tm-cases/fenced_code_blocks_closing_fence.text
new file mode 100644
index 00000000..075f6b67
--- /dev/null
+++ b/test/tm-cases/fenced_code_blocks_closing_fence.text
@@ -0,0 +1,23 @@
+```
+def greet():
+ """Say hello.
+
+ ```
+ greet()
+ ```
+ """
+```
+
+Some *text* between the blocks.
+
+```
+Wrap code in ```
+```
+
+```
+closing fence indented by three spaces
+ ```
+
+```
+closing fence longer than the opening one
+````