38 lines
898 B
Python
38 lines
898 B
Python
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
|
|
|
|
from markdone_python.common import tag_pattern
|
|
|
|
|
|
class TagPattern(Pattern):
|
|
"""
|
|
Returns a !tag rendered as <em>[tag]</em>
|
|
|
|
"""
|
|
tag = 'em'
|
|
def __init__(self):
|
|
super().__init__(r'\!([\w_-]+\b)')
|
|
|
|
def handleMatch(self, m):
|
|
el = etree.Element(self.tag)
|
|
text = m.group(2)
|
|
# text = text.replace('!', '')
|
|
# el.text = '[{}]'.format(re.sub(r'[, ]+', ', ', text))
|
|
el.text = text
|
|
return el
|
|
|
|
|
|
class MarkdoneExtension(Extension):
|
|
def extendMarkdown(self, md, md_globals):
|
|
md.inlinePatterns.add(
|
|
'markdone_tag',
|
|
TagPattern(),
|
|
'_begin',
|
|
)
|
|
|