# 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)
    REVERSE).finditer

# these characters interfere with detection of (args|tls|wlinks|wlists)
pbba_tt = b''.maketrans(b"|[]'{}", b'\1\2\3\7\5\6')
blank_sensitive_chars = partial(regex_compile(br'[\|\{\}\n]').sub, br' ')
blank_brackets = partial(regex_compile(br'[\[\]]').sub, br' ')

PARSABLE_TAG_EXTENSION_NAME = regex_pattern(
    _parsable_tag_extensions)
UNPARSABLE_TAG_EXTENSION_NAME = regex_pattern(
    _unparsable_tag_extensions)

# The idea of the following regex is to detect innermost HTML tags. From
# http://blog.stevenlevithan.com/archives/match-innermost-html-element
# But it's not bullet proof:
# https://stackoverflow.com/questions/3076219/
CONTENT_AND_END = (  # noqa
    rb'\b[^>]*+'
    rb'(?>'
        rb'(?<=/)>'  # self-closing
        # group c captures contents
        rb'|>(?<c>'
            rb'.*?'
        rb')</\g<n>\s*+>'
    rb')')
EXTENSION_TAGS_FINDITER = regex_compile(  # noqa
    rb'<(?>'
        # group m captures comments
        rb'(?<m>!--[\s\S]*?(?>-->|(?=</\g<n>\s*+>)|\Z))'
        # u captures unparsable tag extensions and n captures the name

# 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)

    REVERSE).finditer

# these characters interfere with detection of (args|tls|wlinks|wlists)
pbba_tt = b''.maketrans(b"|[]'{}", b'\1\2\3\7\5\6')
blank_sensitive_chars = partial(regex_compile(br'[\|\{\}\n]').sub, br' ')
blank_brackets = partial(regex_compile(br'[\[\]]').sub, br' ')

PARSABLE_TAG_EXTENSION_NAME = regex_pattern(
    _parsable_tag_extensions)
UNPARSABLE_TAG_EXTENSION_NAME = regex_pattern(
    _unparsable_tag_extensions)

# The idea of the following regex is to detect innermost HTML tags. From
# http://blog.stevenlevithan.com/archives/match-innermost-html-element
# But it's not bullet proof:
# https://stackoverflow.com/questions/3076219/
CONTENT_AND_END = (  # noqa
    rb'\b[^>]*+'
    rb'(?>'
        rb'(?<=/)>'  # self-closing
        # group c captures contents
        rb'|>(?<c>'
            rb'.*?'
        rb')</\g<n>\s*+>'
    rb')')
EXTENSION_TAGS_FINDITER = regex_compile(  # noqa
    rb'<(?>'
        # group m captures comments
        rb'(?<m>!--[\s\S]*?(?>-->|(?=</\g<n>\s*+>)|\Z))'
        # u captures unparsable tag extensions and n captures the name

        rb'|(?<u>(?<n>' + UNPARSABLE_TAG_EXTENSION_NAME + rb')'