diff --git a/CHANGES.md b/CHANGES.md index cee783ed..afb0be54 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -26,6 +26,7 @@ - [pull #737] Fix XSS from code spans that the span gamut doesn't treat as code spans in safe mode (#726) - [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` ## python-markdown2 2.5.5 diff --git a/lib/markdown2.py b/lib/markdown2.py index 3632a54e..e35bf5d2 100755 --- a/lib/markdown2.py +++ b/lib/markdown2.py @@ -3685,7 +3685,7 @@ 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,})\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 ''', re.M | re.X | re.S) diff --git a/test/tm-cases/fenced_code_blocks_lang_with_symbols.html b/test/tm-cases/fenced_code_blocks_lang_with_symbols.html new file mode 100644 index 00000000..0f9e14f1 --- /dev/null +++ b/test/tm-cases/fenced_code_blocks_lang_with_symbols.html @@ -0,0 +1,18 @@ +
+
#region Setup
+var x = 1;
+#endregion
+
+
+ +

Some text between the blocks.

+ +
+
let x = 1
+
+
+ +
+
Dim x As Integer
+
+
diff --git a/test/tm-cases/fenced_code_blocks_lang_with_symbols.opts b/test/tm-cases/fenced_code_blocks_lang_with_symbols.opts new file mode 100644 index 00000000..ba411ac7 --- /dev/null +++ b/test/tm-cases/fenced_code_blocks_lang_with_symbols.opts @@ -0,0 +1 @@ +{"extras": ["fenced-code-blocks"]} diff --git a/test/tm-cases/fenced_code_blocks_lang_with_symbols.tags b/test/tm-cases/fenced_code_blocks_lang_with_symbols.tags new file mode 100644 index 00000000..7fa5d6a0 --- /dev/null +++ b/test/tm-cases/fenced_code_blocks_lang_with_symbols.tags @@ -0,0 +1 @@ +extra fenced-code-blocks pygments pygments>=2.21 diff --git a/test/tm-cases/fenced_code_blocks_lang_with_symbols.text b/test/tm-cases/fenced_code_blocks_lang_with_symbols.text new file mode 100644 index 00000000..98e2cea7 --- /dev/null +++ b/test/tm-cases/fenced_code_blocks_lang_with_symbols.text @@ -0,0 +1,15 @@ +```c# +#region Setup +var x = 1; +#endregion +``` + +Some *text* between the blocks. + +```f# +let x = 1 +``` + +```vb.net +Dim x As Integer +```