# Path: wikitextparser/_config.py
# def _plant_trie(strings: _Iterable[str]) -> dict:
# def _pattern(trie: dict) -> str:
# def regex_pattern(words: _Iterable[str]) -> bytes:
# _HTML_TAG_NAME = regex_pattern(_valid_html_tag_names) + br'\b'


from functools import partial
from typing import Callable, Dict, Optional
from regex import DOTALL, REVERSE, compile as regex_compile, IGNORECASE
from ._config import (
    _HTML_TAG_NAME, _bare_external_link_schemes, _parsable_tag_extensions,
    _parser_functions, _unparsable_tag_extensions, regex_pattern)
SPACE_CHARS = rb' \t\n\u000C\r'  # \s - \v
# http://stackoverflow.com/a/93029/2705757
# chrs = (chr(i) for i in range(sys.maxunicode))
# control_chars = ''.join(c for c in chrs if unicodedata.category(c) == 'Cc')
CONTROL_CHARS = rb'\x00-\x1f\x7f-\x9f'
# https://www.w3.org/TR/html5/syntax.html#syntax-attributes
ATTR_NAME = (
    rb'(?<attr_name>[^' + SPACE_CHARS + CONTROL_CHARS + rb'"\'>/=]++)')
EQ_WS = rb'=[' + SPACE_CHARS + rb']*+'
UNQUOTED_ATTR_VAL = (
    rb'(?<attr_value>[^' + SPACE_CHARS + rb'"\'=<>`]++)')
QUOTED_ATTR_VAL = rb'(?<quote>[\'"])(?<attr_value>.*?)(?P=quote)'
# May include character references, but for now, ignore the fact that they
# cannot contain an ambiguous ampersand.
ATTR_VAL = (
    # If an empty attribute is to be followed by the optional
    # "/" character, then there must be a space character separating
    # the two. This rule is ignored here.
    rb'(?>[' + SPACE_CHARS + rb']*+'  # noqa
        + EQ_WS + rb'(?>' + UNQUOTED_ATTR_VAL + rb'|' + QUOTED_ATTR_VAL + rb')'
        + rb'|(?<attr_value>)'  # empty attribute
    + rb')')
# Ignore ambiguous ampersand for the sake of simplicity.
ATTRS_PATTERN = ( # noqa
    rb'(?<attr>'
        rb'[' + SPACE_CHARS + rb']++(?>' + ATTR_NAME + ATTR_VAL + rb')'
        # Invalid attribute. Todo: could the / be removed? see
        # https://stackoverflow.com/a/3558200/2705757
        + rb'|(?>[^>/]++|/(?!\s*+>))++'
    rb')*+(?<attr_insert>)')

# Path: wikitextparser/_config.py
# def _plant_trie(strings: _Iterable[str]) -> dict:
# def _pattern(trie: dict) -> str:
# def regex_pattern(words: _Iterable[str]) -> bytes:
# _HTML_TAG_NAME = regex_pattern(_valid_html_tag_names) + br'\b'


# Path: wikitextparser/_spans.py
from functools import partial
from typing import Callable, Dict, Optional
from regex import DOTALL, REVERSE, compile as regex_compile, IGNORECASE
from ._config import (
    _HTML_TAG_NAME, _bare_external_link_schemes, _parsable_tag_extensions,
    _parser_functions, _unparsable_tag_extensions, regex_pattern)

SPACE_CHARS = rb' \t\n\u000C\r'  # \s - \v
# http://stackoverflow.com/a/93029/2705757
# chrs = (chr(i) for i in range(sys.maxunicode))
# control_chars = ''.join(c for c in chrs if unicodedata.category(c) == 'Cc')
CONTROL_CHARS = rb'\x00-\x1f\x7f-\x9f'
# https://www.w3.org/TR/html5/syntax.html#syntax-attributes
ATTR_NAME = (
    rb'(?<attr_name>[^' + SPACE_CHARS + CONTROL_CHARS + rb'"\'>/=]++)')
EQ_WS = rb'=[' + SPACE_CHARS + rb']*+'
UNQUOTED_ATTR_VAL = (
    rb'(?<attr_value>[^' + SPACE_CHARS + rb'"\'=<>`]++)')
QUOTED_ATTR_VAL = rb'(?<quote>[\'"])(?<attr_value>.*?)(?P=quote)'
# May include character references, but for now, ignore the fact that they
# cannot contain an ambiguous ampersand.
ATTR_VAL = (
    # If an empty attribute is to be followed by the optional
    # "/" character, then there must be a space character separating
    # the two. This rule is ignored here.
    rb'(?>[' + SPACE_CHARS + rb']*+'  # noqa
        + EQ_WS + rb'(?>' + UNQUOTED_ATTR_VAL + rb'|' + QUOTED_ATTR_VAL + rb')'
        + rb'|(?<attr_value>)'  # empty attribute
    + rb')')
# Ignore ambiguous ampersand for the sake of simplicity.
ATTRS_PATTERN = ( # noqa
    rb'(?<attr>'
        rb'[' + SPACE_CHARS + rb']++(?>' + ATTR_NAME + ATTR_VAL + rb')'
        # Invalid attribute. Todo: could the / be removed? see
        # https://stackoverflow.com/a/3558200/2705757
        + rb'|(?>[^>/]++|/(?!\s*+>))++'
    rb')*+(?<attr_insert>)')

ATTRS_MATCH = regex_compile(