Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# Override defaults with user settings
for key, value in configs :
self.setConfig(key, value)
def extendMarkdown(self, md, md_globals):
self.md = md
# append to end of inline patterns
WIKILINK_RE = r'\[\[([\w0-9_ -]+)\]\]'
wikilinkPattern = WikiLinks(WIKILINK_RE, self.getConfigs())
wikilinkPattern.md = md
md.inlinePatterns.add('wikilink', wikilinkPattern, "
def __init__(self, md):
markdown.inlinepatterns.Pattern.__init__(
self, r'(?
continue
if settings.USING_EMBEDLY:
if embedly_client.is_supported(url):
embedly_urls.append(url)
continue
# NOTE: The youtube code below is inactive at least on
# staging because embedy.ly is currently handling those
youtube = self.youtube_image(url)
if youtube is not None:
add_a(root, youtube, url)
continue
if settings.USING_EMBEDLY:
self.do_embedly(root, embedly_urls)
class Gravatar(markdown.inlinepatterns.Pattern):
def handleMatch(self, match):
img = markdown.util.etree.Element('img')
img.set('class', 'message_body_gravatar img-rounded')
img.set('src', 'https://secure.gravatar.com/avatar/%s?d=identicon&s=30'
% (gravatar_hash(match.group('email')),))
return img
path_to_emoji = os.path.join(os.path.dirname(__file__), '..', '..', '..',
# This should be the root
'static', 'third', 'gemoji', 'images', 'emoji', '*.png')
emoji_list = [os.path.splitext(os.path.basename(fn))[0] for fn in glob.glob(path_to_emoji)]
def make_emoji(emoji_name, src, display_string):
elt = markdown.util.etree.Element('img')
elt.set('src', src)
elt.set('class', 'emoji')
def __init__(self):
markdown.inlinepatterns.Pattern.__init__(self, r'(?
def handle_match(m):
node = markdown.util.etree.Element('script')
node.set('type', 'math/tex; mode=display')
if '\\begin' in m.group(2):
node.text = markdown.util.AtomicString(m.group(2) + m.group(4) + m.group(5))
else:
node.text = markdown.util.AtomicString(m.group(3))
return node
inlinemathpatterns = (
markdown.inlinepatterns.Pattern(r'(?
def __init__(self, pattern, tag):
Pattern.__init__(self, pattern)
self.tag = tag
Keyword arguments:
* m: A re match object containing a match of the pattern.
* data: The buffer current under analysis
Returns:
* el: The ElementTree element, text or None.
* start: The start of the region that has been matched or None.
* end: The end of the region that has been matched or None.
"""
pass # pragma: no cover
class SimpleTextPattern(Pattern): # pragma: no cover
""" Return a simple text of group(2) of a Pattern. """
def handleMatch(self, m):
return m.group(2)
class SimpleTextInlineProcessor(InlineProcessor):
""" Return a simple text of group(1) of a Pattern. """
def handleMatch(self, m, data):
return m.group(1), m.start(0), m.end(0)
class EscapeInlineProcessor(InlineProcessor):
""" Return an escaped character. """
def handleMatch(self, m, data):
char = m.group(1)
import markdown
import cgi
class MathJaxPattern(markdown.inlinepatterns.Pattern):
def __init__(self, md):
markdown.inlinepatterns.Pattern.__init__(self, r'(?
namespace, repo, user = _get_ns_repo_user()
except RuntimeError:
return text
issue = _issue_exists(user, namespace, repo, idx)
if issue:
return _obj_anchor_tag(user, namespace, repo, issue, text)
request = _pr_exists(user, namespace, repo, idx)
if request:
return _obj_anchor_tag(user, namespace, repo, request, text)
return text
class ImplicitCommitPattern(markdown.inlinepatterns.Pattern):
""" Implicit commit pattern. """
def handleMatch(self, m):
""" When the pattern matches, update the text. """
githash = markdown.util.AtomicString(m.group(2))
text = "%s" % githash
try:
namespace, repo, user = _get_ns_repo_user()
except RuntimeError:
return text
if pagure.lib.query.search_projects(
flask.g.session, username=user, namespace=namespace, pattern=repo
) and _commit_exists(user, namespace, repo, githash):