Skip to content

Commit d43141d

Browse files
authored
Fix omitted language case (#2472)
* Fix omitted language case Fixes #2471 * Update pattern to account for non-word chars in language * Add test for non-word boundary * Fix lint
1 parent 79dabb1 commit d43141d

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

docs/src/markdown/about/changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 10.11.1
4+
5+
- **Fix**: SuperFences: Fix regression where an omitted language in conjunction with options in the fenced header
6+
can cause a fence to not be parsed.
7+
38
## 10.11
49

510
- **NEW**: SuperFences: Allow fenced code to be parsed in the form ` ```lang {.class #id} `.

pymdownx/__meta__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,5 +185,5 @@ def parse_version(ver, pre=False):
185185
return Version(major, minor, micro, release, pre, post, dev)
186186

187187

188-
__version_info__ = Version(10, 11, 0, "final")
188+
__version_info__ = Version(10, 11, 1, "final")
189189
__version__ = __version_info__._get_canonical()

pymdownx/superfences.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
RE_NESTED_FENCE_START = re.compile(
4545
r'''(?x)
4646
(?P<fence>~{3,}|`{3,})
47-
(?:[ \t]*\.?(?P<lang>[\w#.+-]+))? # Language
47+
(?:[ \t]*\.?(?P<lang>[\w#.+-]+)(?=[\t ]|$))? # Language
4848
(?:
4949
[ \t]*(\{(?P<attrs>[^\n]*)\}) | # Optional attributes or
5050
(?P<options>

tests/test_extensions/test_superfences.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,40 @@ def __init__(self):
609609
True
610610
)
611611

612+
def test_nonword_boundary_language(self):
613+
"""Test language with non-word boundary."""
614+
615+
self.check_markdown(
616+
"""
617+
```c++ hl_lines="1"
618+
#include <iostream>
619+
```
620+
""",
621+
"""
622+
<div class="highlight"><pre><span></span><code><span class="hll"><span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;iostream&gt;</span>
623+
</span></code></pre></div>
624+
""", # noqa: E501
625+
True
626+
)
627+
628+
def test_omitted_language(self):
629+
"""Test when language is omitted."""
630+
631+
self.check_markdown(
632+
"""
633+
```hl_lines="1"
634+
some
635+
code
636+
```
637+
""",
638+
"""
639+
<div class="highlight"><pre><span></span><code><span class="hll">some
640+
</span>code
641+
</code></pre></div>
642+
""",
643+
True
644+
)
645+
612646

613647
class TestSuperFencesClassesIds(util.MdCase):
614648
"""Test classes and ids without attribute lists."""

0 commit comments

Comments
 (0)