示例#1
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        # This is an extention of the list block rule written in BlockGrammar
        # of mistune library:
        # https://github.com/lepture/mistune/blob/master/mistune.py#L120-L141
        # 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*)+")
示例#2
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        # This is an extention of the list block rule written in BlockGrammar
        # of mistune library:
        # https://github.com/lepture/mistune/blob/master/mistune.py#L120-L141
        # 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+\.) +")
示例#3
0
class HackedBlockGrammar(BlockGrammar):
    heading = re.compile(r'^ *(#{1,6}) *([^\n]+? *#* *(?:\n+|$))')
    lheading = re.compile(r'^([^\n]+\n) *(=|-)+ *(?:\n+|$)')

    list_item = re.compile(
        r'^('
        r'( *)(?:[*+-]|\d+\.) [^\n]*'
        r'(?:\n(?!\2(?:[*+-]|\d+\.) )[^\n]*)*'
        # including newlines.
        r'\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,
        ))
示例#4
0
class HackedInlineGrammar(InlineGrammar):

    code = re.compile(r'^\s*(`+)\s*([\s\S]*?[^`])\s*\1(?!`)')

    text = re.compile(r'^[\s\S]+?'
                      r'(?=[\\<!\[_*`~]|https?://| {2,}\n|$|%s)' %
                      (_pure_pattern(code), ))
)

mistune._block_quote_leading_pattern = re.compile(r'^ *\^ ?', flags=re.M)
mistune.BlockGrammar.block_quote = re.compile(r'^( *\^[^\n]+(\n[^\n]+)*\n*)+')
mistune.BlockGrammar.list_block = re.compile(
    r'^( *)([•*+-]|\d+\.)[\s\S]+?'
    r'(?:'
    r'\n+(?=\1?(?:[-*_] *){3,}(?:\n+|$))'  # hrule
    r'|\n+(?=%s)'  # def links
    r'|\n+(?=%s)'  # def footnotes
    r'|\n{2,}'
    r'(?! )'
    r'(?!\1(?:[•*+-]|\d+\.) )\n*'
    r'|'
    r'\s*$)' % (
        mistune._pure_pattern(mistune.BlockGrammar.def_links),
        mistune._pure_pattern(mistune.BlockGrammar.def_footnotes),
    ))
mistune.BlockGrammar.list_item = re.compile(
    r'^(( *)(?:[•*+-]|\d+\.)[^\n]*'
    r'(?:\n(?!\2(?:[•*+-]|\d+\.))[^\n]*)*)',
    flags=re.M)
mistune.BlockGrammar.list_bullet = re.compile(r'^ *(?:[•*+-]|\d+\.)')

govuk_not_a_link = re.compile(r'(?<!\.|\/)(GOV)\.(UK)(?!\/|\?)', re.IGNORECASE)

dvla_markup_tags = re.compile(
    str('|'.join('<{}>'.format(tag) for tag in
                 {'cr', 'h1', 'h2', 'p', 'normal', 'op', 'np', 'bul', 'tab'})),
    re.IGNORECASE)
示例#6
0
class BordeauxMarkdownBlockGrammar(object):
    """Grammars for block level tokens."""
    def_links = re.compile(
        r'^ *\[([^^\]]+)\]: *'  # [key]:
        r'<?([^\s>]+)>?'  # <link> or link
        r'(?: +["(]([^\n]+)[")])? *(?:\n+|$)'
    )
    def_footnotes = re.compile(
        r'^\[\^([^\]]+)\]: *('
        r'[^\n]*(?:\n+|$)'  # [^key]:
        r'(?: {1,}[^\n]*(?:\n+|$))*'
        r')'
    )

    newline = re.compile(r'^\n+')
    block_code = re.compile(r'^( {4}[^\n]+\n*)+')
    fences = re.compile(
        r'^ *(`{3,}|~{3,}) *([^`\s]+)? *\n'  # ```lang
        r'([\s\S]+?)\s*'
        r'\1 *(?:\n+|$)'  # ```
    )
    hrule = re.compile(r'^ {0,3}[-*_](?: *[-*_]){2,} *(?:\n+|$)')
    heading = re.compile(r'^ *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)')
    block_quote = re.compile(r'^( *>[^\n]+([^\n]+)*)+')
    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(def_links),
            _pure_pattern(def_footnotes),
        )
    )
    list_item = re.compile(
        r'^(( *)(?:[*+-]|\d+\.) [^\n]*'
        r'(?:\n(?!\2(?:[*+-]|\d+\.) )[^\n]*)*)',
        flags=re.M
    )
    list_bullet = re.compile(r'^ *(?:[*+-]|\d+\.) +')
    paragraph = re.compile(
        r'^((?:[^\n]+(?!'
        r'%s|%s|%s|%s|%s|%s|%s|%s'
        r'))+)\n*' % (
            _pure_pattern(fences).replace(r'\2', r'\3').replace(r'\1', r'\2'),
            _pure_pattern(list_block).replace(r'\1', r'\3'),
            _pure_pattern(hrule),
            _pure_pattern(heading),
            _pure_pattern(block_quote),
            _pure_pattern(def_links),
            _pure_pattern(def_footnotes),
            '<' + _block_tag,
        )
    )
    block_html = re.compile(
        r'^ *(?:%s|%s|%s) *(?:\n{2,}|\s*$)' % (
            r'<!--[\s\S]*?-->',
            r'<(%s)((?:%s)*?)>([\s\S]*?)<\/\1>' % (_block_tag, _valid_attr),
            r'<%s(?:%s)*?\s*\/?>' % (_block_tag, _valid_attr),
        )
    )
    text = re.compile(r'^[^\n]+')