Skip to content

Commit

Permalink
Merge pull request #1 from jeremyfelder/master
Browse files Browse the repository at this point in the history
♻️ Update regex to be lazy and handle `!` in text
  • Loading branch information
Lars Wilhelmer authored Jan 10, 2023
2 parents e1b14c4 + d038c69 commit 8b2793d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion custom-span-class.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from markdown.inlinepatterns import Pattern


CUSTOM_CLS_RE = r'[!]{2}(?P<class>[^!]+)[|\^](?P<text>[^!]+)[!]{2}'
CUSTOM_CLS_RE = r'[!]{2}(?P<class>.+?)[|\^](?P<text>.+?(?=[!]{2}))(?=(?P<lookahead>[!]{3}))?(?(lookahead)(?P<exclaim>!))[!]{2}'


class CustomSpanClassExtension(Extension):
Expand All @@ -55,6 +55,9 @@ def handleMatch(self, matched):

cls = matched.group("class")
text = matched.group("text")
exclaim_ending = matched.group("exclaim")
if exclaim_ending is not None:
text += "!"

elem = markdown.util.etree.Element("span")
elem.set("class", cls)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from setuptools import setup
setup(
name='mdx-custom-span-class',
version='1.1.3',
version='1.1.4',
author='Konrad Wasowicz',
author_email='exaroth@gmail.com',
description='Markdown extension which allows inserting span elements with custom class',
Expand Down

0 comments on commit 8b2793d

Please sign in to comment.