Some tweaks of regex
This commit is contained in:
parent
e808570f76
commit
e454b3eb62
@ -2,7 +2,7 @@ import re
|
||||
|
||||
|
||||
section_pattern = re.compile(r'^#')
|
||||
tag_pattern = re.compile(r'(\![\w]+\b)')
|
||||
tag_pattern = re.compile(r'\![\w_-]+\b')
|
||||
task_pattern = re.compile(r'^[\s]*[*]?[\s]*\[[ xX]?\]')
|
||||
|
||||
|
||||
|
@ -42,6 +42,7 @@ if __name__ == '__main__':
|
||||
|
||||
## Subheader
|
||||
Got some !tags !here
|
||||
More !tags with !stuff-here,!and, !there
|
||||
|
||||
* [] task1 !tag
|
||||
* [ ] task2
|
||||
|
@ -1,4 +1,7 @@
|
||||
import re
|
||||
|
||||
from markdown.extensions import Extension
|
||||
from markdown.inlinepatterns import Pattern
|
||||
from markdown.inlinepatterns import SimpleTagPattern
|
||||
from markdown.inlinepatterns import SimpleTextPattern
|
||||
from markdown.util import etree
|
||||
@ -6,19 +9,21 @@ from markdown.util import etree
|
||||
from markdone_python.common import tag_pattern
|
||||
|
||||
|
||||
class SimpleTagPattern(Pattern): # pragma: no cover
|
||||
class TagPattern(Pattern):
|
||||
"""
|
||||
Return element of type `tag` with a text attribute of group(3)
|
||||
of a Pattern.
|
||||
Returns a !tag rendered as <em>[tag]</em>
|
||||
|
||||
"""
|
||||
def __init__(self, pattern, tag):
|
||||
Pattern.__init__(self, pattern)
|
||||
self.tag = tag
|
||||
tag = 'em'
|
||||
def __init__(self):
|
||||
super().__init__(r'\!([\w_-]+\b)')
|
||||
|
||||
def handleMatch(self, m):
|
||||
el = util.etree.Element(self.tag)
|
||||
el.text = m.group(3)
|
||||
el = etree.Element(self.tag)
|
||||
text = m.group(2)
|
||||
# text = text.replace('!', '')
|
||||
# el.text = '[{}]'.format(re.sub(r'[, ]+', ', ', text))
|
||||
el.text = text
|
||||
return el
|
||||
|
||||
|
||||
@ -26,7 +31,7 @@ class MarkdoneExtension(Extension):
|
||||
def extendMarkdown(self, md, md_globals):
|
||||
md.inlinePatterns.add(
|
||||
'markdone_tag',
|
||||
SimpleTagPattern(tag_pattern.pattern, 'em'),
|
||||
TagPattern(),
|
||||
'_begin',
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user