Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setUp(self):
# Create comment node
self.comment = markdown.util.etree.Comment('foo')
if hasattr(markdown.util.etree, 'test_comment'):
self.test_comment = markdown.util.etree.test_comment
else:
self.test_comment = markdown.util.etree.Comment
def handleMatch(self, m):
url = m.group(3)
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
def handleMatch(self, m):
node = etree.Element(None)
text = ''
for group in self.groups:
text += m.group(group)
node.text = AtomicString(text)
return node
def handleMatch(self, m):
id = m.group(2)
if id in list(self.footnotes.footnotes.keys()):
sup = etree.Element("sup")
a = etree.SubElement(sup, "a")
sup.set('id', self.footnotes.makeFootnoteRefId(id))
a.set('href', '#' + self.footnotes.makeFootnoteId(id))
if self.footnotes.md.output_format not in ['html5', 'xhtml5']:
a.set('rel', 'footnote') # invalid in HTML5
a.set('class', 'footnote-ref')
a.text = str(self.footnotes.footnotes.index(id) + 1)
return sup
else:
return None
def handleMatch(self, m):
"""
Handles user input into [magic] tag, processes it,
and inserts the returned URL into an <img> tag
through a Python ElementTree <img> Element.
"""
userStr = m.group(3)
# print(userStr)
imgURL = processString(userStr)
# print(imgURL)
el = etree.Element('img')
# Sets imgURL to 'src' attribute of <img> tag element
el.set('src', imgURL)
el.set('alt', userStr)
el.set('title', userStr)
return el
def twitter_link(self, url: str) -> Optional[Element]:
tweet_id = get_tweet_id(url)
if tweet_id is None:
return None
try:
res = fetch_tweet_data(tweet_id)
if res is None:
return None
user = res['user'] # type: Dict[str, Any]
tweet = markdown.util.etree.Element("div")
tweet.set("class", "twitter-tweet")
img_a = markdown.util.etree.SubElement(tweet, 'a')
img_a.set("href", url)
img_a.set("target", "_blank")
profile_img = markdown.util.etree.SubElement(img_a, 'img')
profile_img.set('class', 'twitter-avatar')
# For some reason, for, e.g. tweet 285072525413724161,
# python-twitter does not give us a
# profile_image_url_https, but instead puts that URL in
# profile_image_url. So use _https if available, but fall
# back gracefully.
image_url = user.get('profile_image_url_https', user['profile_image_url'])
profile_img.set('src', image_url)
text = html.unescape(res['full_text'])
urls = res.get('urls', [])
def handleMatch(self, m):
link, title = m.group(2).strip(), m.group(3).strip()
if link and title:
base_url, end_url, html_class = self._getMeta()
url = self.config['build_url'](title, base_url, end_url)
a = markdown.util.etree.Element('a')
a.text = title
a.set('href', link)
if html_class:
a.set('class', html_class)
else:
a = ''
return a
def run(self, root):
'''
Find and remove all id specs references from the text,
and add them as the id attribute of the element.
ROOT is div#section_content.
'''
if isBlockLevel(root.tag) and root.tag not in ['code', 'pre']:
self._parseID(root)
child = etree.Element("style")
for k,v in {
'type': 'text/css',
}.iteritems():
child.set(k, v)
# Note upstream doc bug: it's not called markdown.AtomicString().
self.css += 'dt:hover > .elementid-permalink { visibility: visible }'
child.text = markdown.util.AtomicString(self.css)
root.insert(0, child)
self.css = CSS
self.seen_block_tag = {}
# child.tail = root.text; root.text = None;
return root
def handleMatch(self, m):
kwargs = {}
children = []
text = ""
bits = m.groupdict()
kwargs['var'] = bits['var']
for op_text in [bits['op0'], bits['op1']]:
op = markdown.util.etree.Element('span')
op.text = op_text
children.append(op)
kwargs = bits
return tk_span('TKToggle TKSwitch', children=children, ignore=['op0', 'op1'], **kwargs)