diff --git a/CHANGES.md b/CHANGES.md index 10aabd33..abf4a7cd 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,7 @@ ## python-markdown2 2.5.6 (not yet released) +- [pull #776] Support `~~~` fences in the `fenced-code-blocks` extra - [pull #762] Speed up documents with many links by skipping the backslash-escape scan for text without a backslash - [pull #748] Speed up `_unescape_special_chars` by skipping text with no hashes and dropping the full-text comparison per pass (#635) - [pull #749] URL-encode destinations generated by the `link-patterns` extra (#55) diff --git a/lib/markdown2.py b/lib/markdown2.py index d6285404..839f8063 100755 --- a/lib/markdown2.py +++ b/lib/markdown2.py @@ -3704,13 +3704,13 @@ class FencedCodeBlocks(Extra): fenced_code_block_re = re.compile(r''' (?:\n+|\A\n?|(?<=\n)) - (^[ \t]*`{3,})\s{0,99}?([\w+\#.-]+)?\s{0,99}?\n # $1 = opening fence (captured for back-referencing), $2 = optional lang + (^[ \t]*(?:`{3,}|~{3,}))\s{0,99}?([\w+\#.-]+)?\s{0,99}?\n # $1 = opening fence (captured for back-referencing), $2 = optional lang (.*?) # $3 = code block content - ^[ ]{0,3}\1`*[ \t]*\n # closing fence + ^[ ]{0,3}\1[`~]*[ \t]*\n # closing fence ''', re.M | re.X | re.S) def test(self, text: str): - if '```' not in text: + if '```' not in text and '~~~' not in text: return False if self.md.stage == Stage.PREPROCESS and not self.md.safe_mode: # if safe mode is off then run before HASH_HTML and not worry about the tags getting messed up diff --git a/test/tm-cases/fenced_code_blocks_tilde.html b/test/tm-cases/fenced_code_blocks_tilde.html new file mode 100644 index 00000000..38bf4831 --- /dev/null +++ b/test/tm-cases/fenced_code_blocks_tilde.html @@ -0,0 +1,11 @@ +

Run:

+ +
ls ~/x
+
+ +

And with backticks inside:

+ +
```
+not a fence
+```
+
diff --git a/test/tm-cases/fenced_code_blocks_tilde.opts b/test/tm-cases/fenced_code_blocks_tilde.opts new file mode 100644 index 00000000..c02a10d8 --- /dev/null +++ b/test/tm-cases/fenced_code_blocks_tilde.opts @@ -0,0 +1 @@ +{"extras": ["fenced-code-blocks", "strike"]} diff --git a/test/tm-cases/fenced_code_blocks_tilde.tags b/test/tm-cases/fenced_code_blocks_tilde.tags new file mode 100644 index 00000000..0edfe9c0 --- /dev/null +++ b/test/tm-cases/fenced_code_blocks_tilde.tags @@ -0,0 +1 @@ +extra fenced-code-blocks strike diff --git a/test/tm-cases/fenced_code_blocks_tilde.text b/test/tm-cases/fenced_code_blocks_tilde.text new file mode 100644 index 00000000..30ca335d --- /dev/null +++ b/test/tm-cases/fenced_code_blocks_tilde.text @@ -0,0 +1,13 @@ +Run: + +~~~ +ls ~/x +~~~ + +And with backticks inside: + +~~~ +``` +not a fence +``` +~~~