summaryrefslogtreecommitdiffstats
path: root/markdown_it/rules_inline/html_inline.py
blob: 295cc5c7109de761e0540476f1971dfc3015d5b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# Process html tags
from ..common.html_re import HTML_TAG_RE
from .state_inline import StateInline


def isLetter(ch: int):
    lc = ch | 0x20  # to lower case
    # /* a */ and /* z */
    return (lc >= 0x61) and (lc <= 0x7A)


def html_inline(state: StateInline, silent: bool):

    pos = state.pos

    if not state.md.options.get("html", None):
        return False

    # Check start
    maximum = state.posMax
    if state.srcCharCode[pos] != 0x3C or pos + 2 >= maximum:  # /* < */
        return False

    # Quick fail on second char
    ch = state.srcCharCode[pos + 1]
    if (
        ch != 0x21
        and ch != 0x3F  # /* ! */
        and ch != 0x2F  # /* ? */
        and not isLetter(ch)  # /* / */
    ):
        return False

    match = HTML_TAG_RE.search(state.src[pos:])
    if not match:
        return False

    if not silent:
        token = state.push("html_inline", "", 0)
        token.content = state.src[pos : pos + len(match.group(0))]

    state.pos += len(match.group(0))
    return True