Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def handleMatch(self, m):
url = m.group(2)
if url.startswith('<'):
url = url[1:-1]
text = url
if not url.split('://')[0] in ('http','https','ftp'):
if '@' in url and not '/' in url:
url = 'mailto:' + url
else:
url = 'http://' + url
el = markdown.util.etree.Element("a")
el.set('href', url)
el.text = markdown.util.AtomicString(text)
return el
while len(elemsToInspect) > 0:
elem = elemsToInspect.pop()
for nelem in elem:
if nelem.tag in self.configs["PARENTS"]:
elemsToInspect.append(nelem)
elif nelem.tag == "p" and len(list(nelem.itertext())) == 0 :
lelems = list(nelem.iter())
if (len(lelems) == 1 or (len(lelems)==2 and lelems[0] is nelem)) \
and lelems[-1].tag == "img" \
and lelems[-1].attrib["alt"] != "" \
and not (lelems[-1].attrib["src"] in self.configs["IGNORING_IMG"]):
oldImg = lelems[-1]
nelem.remove(oldImg)
nFig = util.etree.Element("figure")
nFigCaption = util.etree.Element("figurecaption")
nFigCaption.text = oldImg.attrib["alt"]
oldImg.attrib["alt"]=""
nFig.append(oldImg)
nFig.append(nFigCaption)
nelem.append(nFig)
return root
def tk_span(cls_or_class, text=None, ignore=[], children=[], **kwargs):
"""
Helper function. Creates the "normal" TangleKit spans.
"""
kwargs = dict([('data-'+k, v) for k, v in kwargs.items() if v not in [None,""] and k not in ignore])
obj = markdown.util.etree.Element('span')
[obj.append(c) for c in children]
if text:
obj.text = text
if isinstance(cls_or_class, str):
obj.set('class', cls_or_class)
else:
obj.set('class', cls_or_class.__class__.__name__)
[obj.set(k, v) for k, v in kwargs.items()]
return obj
def handleMatch(self, m):
ret = LinkPattern.handleMatch(self, m)
if not isinstance(ret, basestring):
ret.text = markdown.util.AtomicString(ret.text)
return ret
def itertext(el):
' Reimplement Element.itertext for older python versions '
tag = el.tag
if not isinstance(tag, util.string_type) and tag is not None:
return
if el.text:
yield el.text
for e in el:
for s in itertext(e):
yield s
if e.tail:
yield e.tail
def get_stash(m):
def handleMatch(self, m):
subsc = m.group(3)
text = subsc
el = markdown.util.etree.Element("sub")
el.text = markdown.util.AtomicString(text)
return el
)
RE_TABS = re.compile(r'((?:<p>.*?</p>\s*)+)', re.DOTALL)
TAB = (
''
'<input id="__tabbed_%%(index)s_%%(tab_index)s" type="radio" name="__tabbed_%%(index)s">'
'<label for="__tabbed_%%(index)s_%%(tab_index)s">%(title)s</label>'
'<div class="%(content)s">%(code)s</div>'
''
)
NESTED_FENCE_END = r'%s[ \t]*$'
FENCED_BLOCK_RE = re.compile(
r'^([\> ]*)%s(%s)%s$' % (
md_util.HTML_PLACEHOLDER[0],
md_util.HTML_PLACEHOLDER[1:-1] % r'([0-9]+)',
md_util.HTML_PLACEHOLDER[-1]
)
)
MSG_TAB_DEPRECATION = """
The tab option in SuperFences has been deprecated in favor of the general purpose 'pymdownx.tabbed' extension.
While you can continue to use this feature for now, it will be removed in the future.
Also be mindful of the class changes, if you require old style classes, please enable the 'legacy_tab_classes' option.
"""
def _escape(txt):
"""Basic html escaping."""
txt = txt.replace('&', '&')
'fieldset', 'figcaption', 'figure', 'footer', 'form', 'h1', 'h2', 'h3',
'h4', 'h5', 'h6', 'header', 'hr', 'main', 'menu', 'nav', 'ol', 'p', 'pre',
'section', 'table', 'ul',
# Other elements which Markdown should not be mucking up the contents of.
'canvas', 'dd', 'dt', 'group', 'iframe', 'li', 'math', 'noscript', 'output',
'progress', 'script', 'style', 'tbody', 'td', 'th', 'thead', 'tr', 'video'
]
self.registeredExtensions = []
self.docType = ""
self.stripTopLevelTags = True
self.build_parser()
self.references = {}
self.htmlStash = util.HtmlStash()
self.registerExtensions(extensions=kwargs.get('extensions', []),
configs=kwargs.get('extension_configs', {}))
self.set_output_format(kwargs.get('output_format', 'xhtml'))
self.reset()
def handleMatch(self, m):
node = markdown.util.etree.Element('mathjax')
node.text = markdown.util.AtomicString(m.group(2) + m.group(3) + m.group(2))
return node
stack = [tree]
while stack:
currElement = stack.pop()
insertQueue = []
for child in currElement.getchildren():
if child.text and not isinstance(child.text, util.AtomicString):
text = child.text
child.text = None
lst = self.__processPlaceholders(self.__handleInline(
text), child)
stack += lst
insertQueue.append((child, lst))
if child.tail:
tail = self.__handleInline(child.tail)
dumby = util.etree.Element('d')
tailResult = self.__processPlaceholders(tail, dumby)
if dumby.text:
child.tail = dumby.text
else:
child.tail = None
pos = currElement.getchildren().index(child) + 1
tailResult.reverse()
for newChild in tailResult:
currElement.insert(pos, newChild)
if child.getchildren():
stack.append(child)
for element, lst in insertQueue:
if self.markdown.enable_attributes:
if element.text and isString(element.text):
element.text = \