How to use the mistune._pure_pattern function in mistune

To help you get started, we’ve selected a few mistune examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github huntzhan / zhlint / zhlint / mistune_patch.py View on Github external
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()
github huntzhan / zhlint / zhlint / mistune_patch.py View on Github external
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
github canonical-web-and-design / snapcraft.io / webapp / markdown.py View on Github external
# 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*)+")
github huntzhan / zhlint / zhlint / mistune_patch.py View on Github external
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'(?=[\\
github canonical-web-and-design / snapcraft.io / webapp / markdown.py View on Github external
# 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*)+")
github huntzhan / zhlint / zhlint / mistune_patch.py View on Github external
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)
github huntzhan / zhlint / zhlint / mistune_patch.py View on Github external
)

    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
github huntzhan / zhlint / zhlint / mistune_patch.py View on Github external
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):
github huntzhan / zhlint / zhlint / mistune_patch.py View on Github external
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
github huntzhan / zhlint / zhlint / mistune_patch.py View on Github external
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)