Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
flags=re.M
)
fences = re.compile(
r'^ *(`{3,}|~{3,}) *(\S+)? *\n' # ```lang
r'([\s\S]+?)\s*'
r'\1 *(\n+|$)' # ```
)
paragraph = re.compile(
r'^((?:[^\n]+\n?(?!'
r'%s|%s|%s|%s|%s|%s|%s|%s|%s'
# including newlines.
r'))+\n*)' % (
_pure_pattern(fences).replace(r'\1', r'\2'),
_pure_pattern(BlockGrammar.list_block).replace(r'\1', r'\3'),
_pure_pattern(BlockGrammar.hrule),
_pure_pattern(heading),
_pure_pattern(lheading),
_pure_pattern(BlockGrammar.block_quote),
_pure_pattern(BlockGrammar.def_links),
_pure_pattern(BlockGrammar.def_footnotes),
'<' + _block_tag,
)
)
class HackedBlockLexer(BlockLexer):
def __init__(self, *args, **kwargs):
super(HackedBlockLexer, self).__init__(*args, **kwargs)
self.loc_manager = LOCStateManager()
fences = re.compile(
r'^ *(`{3,}|~{3,}) *(\S+)? *\n' # ```lang
r'([\s\S]+?)\s*'
r'\1 *(\n+|$)' # ```
)
paragraph = re.compile(
r'^((?:[^\n]+\n?(?!'
r'%s|%s|%s|%s|%s|%s|%s|%s|%s'
# including newlines.
r'))+\n*)' % (
_pure_pattern(fences).replace(r'\1', r'\2'),
_pure_pattern(BlockGrammar.list_block).replace(r'\1', r'\3'),
_pure_pattern(BlockGrammar.hrule),
_pure_pattern(heading),
_pure_pattern(lheading),
_pure_pattern(BlockGrammar.block_quote),
_pure_pattern(BlockGrammar.def_links),
_pure_pattern(BlockGrammar.def_footnotes),
'<' + _block_tag,
)
)
class HackedBlockLexer(BlockLexer):
def __init__(self, *args, **kwargs):
super(HackedBlockLexer, self).__init__(*args, **kwargs)
self.loc_manager = LOCStateManager()
self._block_level = 0
# We want to support the • as a tag for lists in markdown.
# To do this this [*+-•] is the list of supported tags
self.list_block = re.compile(
r"^( *)(?=[•*+-]|\d+\.)(([•*+-])?(?:\d+\.)?) [\s\S]+?"
r"(?:"
r"\n+(?=\1?(?:[-*_] *){3,}(?:\n+|$))" # hrule
r"|\n+(?=%s)" # def links
r"|\n+(?=%s)" # def footnotes\
r"|\n+(?=\1(?(3)\d+\.|[•*+-]) )" # heterogeneous bullet
r"|\n{2,}"
r"(?! )"
r"(?!\1(?:[•*+-]|\d+\.) )\n*"
r"|"
r"\s*$)"
% (
_pure_pattern(super().def_links),
_pure_pattern(super().def_footnotes),
)
)
self.list_item = re.compile(
r"^(( *)(?:[•*+-]|\d+\.) [^\n]*"
r"(?:\n(?!\2(?:[•*+-]|\d+\.) )[^\n]*)*)",
flags=re.M,
)
self.list_bullet = re.compile(r"^ *(?:[•*+-]|\d+\.) +")
self.block_code = re.compile(r"^( {3}[^\n]+\n*)+")
if text: # pragma: no cover
raise RuntimeError('Infinite loop at: %s' % text)
self.loc_manager.pop()
return self.tokens
class HackedInlineGrammar(InlineGrammar):
code = re.compile(r'^\s*(`+)\s*([\s\S]*?[^`])\s*\1(?!`)')
text = re.compile(
r'^[\s\S]+?'
r'(?=[\\
# To do this this [*+-•] is the list of supported tags
self.list_block = re.compile(
r"^( *)(?=[•*+-]|\d+\.)(([•*+-])?(?:\d+\.)?) [\s\S]+?"
r"(?:"
r"\n+(?=\1?(?:[-*_] *){3,}(?:\n+|$))" # hrule
r"|\n+(?=%s)" # def links
r"|\n+(?=%s)" # def footnotes\
r"|\n+(?=\1(?(3)\d+\.|[•*+-]) )" # heterogeneous bullet
r"|\n{2,}"
r"(?! )"
r"(?!\1(?:[•*+-]|\d+\.) )\n*"
r"|"
r"\s*$)"
% (
_pure_pattern(super().def_links),
_pure_pattern(super().def_footnotes),
)
)
self.list_item = re.compile(
r"^(( *)(?:[•*+-]|\d+\.) [^\n]*"
r"(?:\n(?!\2(?:[•*+-]|\d+\.) )[^\n]*)*)",
flags=re.M,
)
self.list_bullet = re.compile(r"^ *(?:[•*+-]|\d+\.) +")
self.block_code = re.compile(r"^( {3}[^\n]+\n*)+")
r')',
flags=re.M
)
fences = re.compile(
r'^ *(`{3,}|~{3,}) *(\S+)? *\n' # ```lang
r'([\s\S]+?)\s*'
r'\1 *(\n+|$)' # ```
)
paragraph = re.compile(
r'^((?:[^\n]+\n?(?!'
r'%s|%s|%s|%s|%s|%s|%s|%s|%s'
# including newlines.
r'))+\n*)' % (
_pure_pattern(fences).replace(r'\1', r'\2'),
_pure_pattern(BlockGrammar.list_block).replace(r'\1', r'\3'),
_pure_pattern(BlockGrammar.hrule),
_pure_pattern(heading),
_pure_pattern(lheading),
_pure_pattern(BlockGrammar.block_quote),
_pure_pattern(BlockGrammar.def_links),
_pure_pattern(BlockGrammar.def_footnotes),
'<' + _block_tag,
)
)
class HackedBlockLexer(BlockLexer):
def __init__(self, *args, **kwargs):
super(HackedBlockLexer, self).__init__(*args, **kwargs)
)
fences = re.compile(
r'^ *(`{3,}|~{3,}) *(\S+)? *\n' # ```lang
r'([\s\S]+?)\s*'
r'\1 *(\n+|$)' # ```
)
paragraph = re.compile(
r'^((?:[^\n]+\n?(?!'
r'%s|%s|%s|%s|%s|%s|%s|%s|%s'
# including newlines.
r'))+\n*)' % (
_pure_pattern(fences).replace(r'\1', r'\2'),
_pure_pattern(BlockGrammar.list_block).replace(r'\1', r'\3'),
_pure_pattern(BlockGrammar.hrule),
_pure_pattern(heading),
_pure_pattern(lheading),
_pure_pattern(BlockGrammar.block_quote),
_pure_pattern(BlockGrammar.def_links),
_pure_pattern(BlockGrammar.def_footnotes),
'<' + _block_tag,
)
)
class HackedBlockLexer(BlockLexer):
def __init__(self, *args, **kwargs):
super(HackedBlockLexer, self).__init__(*args, **kwargs)
self.loc_manager = LOCStateManager()
self._block_level = 0
fences = re.compile(
r'^ *(`{3,}|~{3,}) *(\S+)? *\n' # ```lang
r'([\s\S]+?)\s*'
r'\1 *(\n+|$)' # ```
)
paragraph = re.compile(
r'^((?:[^\n]+\n?(?!'
r'%s|%s|%s|%s|%s|%s|%s|%s|%s'
# including newlines.
r'))+\n*)' % (
_pure_pattern(fences).replace(r'\1', r'\2'),
_pure_pattern(BlockGrammar.list_block).replace(r'\1', r'\3'),
_pure_pattern(BlockGrammar.hrule),
_pure_pattern(heading),
_pure_pattern(lheading),
_pure_pattern(BlockGrammar.block_quote),
_pure_pattern(BlockGrammar.def_links),
_pure_pattern(BlockGrammar.def_footnotes),
'<' + _block_tag,
)
)
class HackedBlockLexer(BlockLexer):
def __init__(self, *args, **kwargs):
super(HackedBlockLexer, self).__init__(*args, **kwargs)
self.loc_manager = LOCStateManager()
self._block_level = 0
def parse_block_quote(self, m):
r'^ *(`{3,}|~{3,}) *(\S+)? *\n' # ```lang
r'([\s\S]+?)\s*'
r'\1 *(\n+|$)' # ```
)
paragraph = re.compile(
r'^((?:[^\n]+\n?(?!'
r'%s|%s|%s|%s|%s|%s|%s|%s|%s'
# including newlines.
r'))+\n*)' % (
_pure_pattern(fences).replace(r'\1', r'\2'),
_pure_pattern(BlockGrammar.list_block).replace(r'\1', r'\3'),
_pure_pattern(BlockGrammar.hrule),
_pure_pattern(heading),
_pure_pattern(lheading),
_pure_pattern(BlockGrammar.block_quote),
_pure_pattern(BlockGrammar.def_links),
_pure_pattern(BlockGrammar.def_footnotes),
'<' + _block_tag,
)
)
class HackedBlockLexer(BlockLexer):
def __init__(self, *args, **kwargs):
super(HackedBlockLexer, self).__init__(*args, **kwargs)
self.loc_manager = LOCStateManager()
self._block_level = 0
def parse_block_quote(self, m):
self._block_level += 1
r'([\s\S]+?)\s*'
r'\1 *(\n+|$)' # ```
)
paragraph = re.compile(
r'^((?:[^\n]+\n?(?!'
r'%s|%s|%s|%s|%s|%s|%s|%s|%s'
# including newlines.
r'))+\n*)' % (
_pure_pattern(fences).replace(r'\1', r'\2'),
_pure_pattern(BlockGrammar.list_block).replace(r'\1', r'\3'),
_pure_pattern(BlockGrammar.hrule),
_pure_pattern(heading),
_pure_pattern(lheading),
_pure_pattern(BlockGrammar.block_quote),
_pure_pattern(BlockGrammar.def_links),
_pure_pattern(BlockGrammar.def_footnotes),
'<' + _block_tag,
)
)
class HackedBlockLexer(BlockLexer):
def __init__(self, *args, **kwargs):
super(HackedBlockLexer, self).__init__(*args, **kwargs)
self.loc_manager = LOCStateManager()
self._block_level = 0
def parse_block_quote(self, m):
self._block_level += 1
super(HackedBlockLexer, self).parse_block_quote(m)