Skip to content

Commit

Permalink
Fix omitted language case (#2472)
Browse files Browse the repository at this point in the history
* Fix omitted language case

Fixes #2471

* Update pattern to account for non-word chars in language

* Add test for non-word boundary

* Fix lint
  • Loading branch information
facelessuser authored Sep 29, 2024
1 parent 79dabb1 commit d43141d
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
5 changes: 5 additions & 0 deletions docs/src/markdown/about/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 10.11.1

- **Fix**: SuperFences: Fix regression where an omitted language in conjunction with options in the fenced header
can cause a fence to not be parsed.

## 10.11

- **NEW**: SuperFences: Allow fenced code to be parsed in the form ` ```lang {.class #id} `.
Expand Down
2 changes: 1 addition & 1 deletion pymdownx/__meta__.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,5 +185,5 @@ def parse_version(ver, pre=False):
return Version(major, minor, micro, release, pre, post, dev)


__version_info__ = Version(10, 11, 0, "final")
__version_info__ = Version(10, 11, 1, "final")
__version__ = __version_info__._get_canonical()
2 changes: 1 addition & 1 deletion pymdownx/superfences.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
RE_NESTED_FENCE_START = re.compile(
r'''(?x)
(?P<fence>~{3,}|`{3,})
(?:[ \t]*\.?(?P<lang>[\w#.+-]+))? # Language
(?:[ \t]*\.?(?P<lang>[\w#.+-]+)(?=[\t ]|$))? # Language
(?:
[ \t]*(\{(?P<attrs>[^\n]*)\}) | # Optional attributes or
(?P<options>
Expand Down
34 changes: 34 additions & 0 deletions tests/test_extensions/test_superfences.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,40 @@ def __init__(self):
True
)

def test_nonword_boundary_language(self):
"""Test language with non-word boundary."""

self.check_markdown(
"""
```c++ hl_lines="1"
#include <iostream>
```
""",
"""
<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>
</span></code></pre></div>
""", # noqa: E501
True
)

def test_omitted_language(self):
"""Test when language is omitted."""

self.check_markdown(
"""
```hl_lines="1"
some
code
```
""",
"""
<div class="highlight"><pre><span></span><code><span class="hll">some
</span>code
</code></pre></div>
""",
True
)


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

0 comments on commit d43141d

Please sign in to comment.