Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions lib/markdown2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions test/tm-cases/fenced_code_blocks_tilde.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<p>Run:</p>

<pre><code>ls ~/x
</code></pre>

<p>And with backticks inside:</p>

<pre><code>```
not a fence
```
</code></pre>
1 change: 1 addition & 0 deletions test/tm-cases/fenced_code_blocks_tilde.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"extras": ["fenced-code-blocks", "strike"]}
1 change: 1 addition & 0 deletions test/tm-cases/fenced_code_blocks_tilde.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
extra fenced-code-blocks strike
13 changes: 13 additions & 0 deletions test/tm-cases/fenced_code_blocks_tilde.text
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Run:

~~~
ls ~/x
~~~

And with backticks inside:

~~~
```
not a fence
```
~~~