Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/markdown_it/rules_inline/html_inline.py: 96%

28 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-07 06:15 +0000

1# Process html tags 

2from ..common.html_re import HTML_TAG_RE 

3from ..common.utils import isLinkClose, isLinkOpen 

4from .state_inline import StateInline 

5 

6 

7def isLetter(ch: int) -> bool: 

8 lc = ch | 0x20 # to lower case 

9 # /* a */ and /* z */ 

10 return (lc >= 0x61) and (lc <= 0x7A) 

11 

12 

13def html_inline(state: StateInline, silent: bool) -> bool: 

14 pos = state.pos 

15 

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

17 return False 

18 

19 # Check start 

20 maximum = state.posMax 

21 if state.src[pos] != "<" or pos + 2 >= maximum: 

22 return False 

23 

24 # Quick fail on second char 

25 ch = state.src[pos + 1] 

26 if ch not in ("!", "?", "/") and not isLetter(ord(ch)): # /* / */ 

27 return False 

28 

29 match = HTML_TAG_RE.search(state.src[pos:]) 

30 if not match: 

31 return False 

32 

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 += 1 

39 if isLinkClose(token.content): 

40 state.linkLevel -= 1 

41 

42 state.pos += len(match.group(0)) 

43 return True