codekingpro/portable-devtools
115k
1# Process html tags2from ..common.html_re import HTML_TAG_RE3from ..common.utils import isLinkClose, isLinkOpen4from .state_inline import StateInline5 6 7def isLetter(ch: int) -> bool:8 lc = ch | 0x20 # to lower case9 # /* a */ and /* z */10 return (lc >= 0x61) and (lc <= 0x7A)11 12 13def html_inline(state: StateInline, silent: bool) -> bool:14 pos = state.pos15 16 if not state.md.options.get("html", None):17 return False18 19 # Check start20 maximum = state.posMax21 if state.src[pos] != "<" or pos + 2 >= maximum:22 return False23 24 # Quick fail on second char25 ch = state.src[pos + 1]26 if ch not in ("!", "?", "/") and not isLetter(ord(ch)): # /* / */27 return False28 29 match = HTML_TAG_RE.search(state.src[pos:])30 if not match:31 return False32 33 if not silent:34 token = state.push("html_inline", "", 0)35 token.content = state.src[pos : pos + len(match.group(0))]36 37 if isLinkOpen(token.content):38 state.linkLevel += 139 if isLinkClose(token.content):40 state.linkLevel -= 141 42 state.pos += len(match.group(0))43 return True44 