Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def shorten_diff(self, link, class_name, label, user_repo, value, hash_size):
"""Shorten diff/compare links."""
repo_label = self.repo_labels.get('compare', 'Compare')
if self.my_repo:
text = '%s...%s' % (value[0][0:hash_size], value[1][0:hash_size])
elif self.my_user:
text = '%s@%s...%s' % (user_repo.split('/')[1], value[0][0:hash_size], value[1][0:hash_size])
else:
text = '%s@%s...%s' % (user_repo, value[0][0:hash_size], value[1][0:hash_size])
link.text = md_util.AtomicString(text)
if 'magiclink-compare' not in class_name:
class_name.append('magiclink-compare')
link.set(
'title',
'%s %s: %s@%s...%s' % (
label, repo_label, user_repo.rstrip('/'), value[0][0:hash_size], value[1][0:hash_size]
)
linkText(node)
strartIndex = phEndIndex
continue
strartIndex = phEndIndex
result.append(node)
else: # wrong placeholder
end = index + len(self.__placeholder_prefix)
linkText(data[strartIndex:end])
strartIndex = end
else:
text = data[strartIndex:]
if isinstance(data, util.AtomicString):
# We don't want to loose the AtomicString
text = util.AtomicString(text)
linkText(text)
data = ""
return result
def handleMatch(self, m, data=None):
el = markdown.util.etree.Element("a")
try:
el.set('href', self.url(m.group('id')))
el.text = markdown.util.AtomicString(m.group('title'))
except ObjectDoesNotExist:
el.text = markdown.util.AtomicString(_('[missing link]'))
__, index, __ = self.getText(data, m.end(0))
__, __, index, __ = self.getLink(data, index)
return el, m.start(0), index
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
def handleMatch(self, m):
supr = m.group(3)
text = supr
el = markdown.util.etree.Element("sup")
el.text = markdown.util.AtomicString(text)
return el
def handleMatch(self, m, data):
"""Handle email link patterns."""
el = etree.Element("a")
email = self.unescape(m.group('mail'))
href = "mailto:%s" % email
el.text = md_util.AtomicString(''.join([self.email_encode(ord(c)) for c in email]))
el.set("href", ''.join([md_util.AMP_SUBSTITUTE + '#%d;' % ord(c) for c in href]))
return el, m.start(0), m.end(0)
def handle_match(m):
node = etree.Element('script')
node.set('type', '%s; mode=display' % self._get_content_type())
if '\\begin' in m.group(2):
node.text = AtomicString(''.join(m.group(2, 4, 5)))
return _wrap_node(node, ''.join(m.group(1, 2, 4, 5, 6)), 'div')
else:
node.text = AtomicString(m.group(3))
return _wrap_node(node, ''.join(m.group(2, 3, 4)), 'div')
def handleMatch(self, m):
username = self.unescape(m.group(2))
"""Makesure `username` is registered and actived."""
if MARTOR_ENABLE_CONFIGS['mention'] == 'true':
if username in [u.username for u in User.objects.exclude(is_active=False)]:
url = '{0}{1}/'.format(MARTOR_MARKDOWN_BASE_MENTION_URL, username)
el = markdown.util.etree.Element('a')
el.set('href', url)
el.set('class', 'direct-mention-link')
el.text = markdown.util.AtomicString('@' + username)
return el
def handleMatch(self, m):
subsc = m.group(3)
text = subsc
el = markdown.util.etree.Element("sub")
el.text = markdown.util.AtomicString(text)
return el
def handleMatch(self, m):
el = util.etree.Element('a')
email = self.unescape(m.group(2))
if email.startswith("mailto:"):
email = email[len("mailto:"):]
def codepoint2name(code):
"""Return entity definition by code, or the code if not defined."""
entity = entities.codepoint2name.get(code)
if entity:
return "%s%s;" % (util.AMP_SUBSTITUTE, entity)
else:
return "%s#%d;" % (util.AMP_SUBSTITUTE, code)
letters = [codepoint2name(ord(letter)) for letter in email]
el.text = util.AtomicString(''.join(letters))
mailto = "mailto:" + email
mailto = "".join([util.AMP_SUBSTITUTE + '#%d;' %
ord(letter) for letter in mailto])
el.set('href', mailto)
return el