Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/markdown_it/rules_inline/text.py: 100%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

18 statements  

1import functools 

2import re 

3 

4# Skip text characters for text token, place those to pending buffer 

5# and increment current pos 

6from .state_inline import StateInline 

7 

8# Rule to skip pure text 

9# '{}$%@~+=:' reserved for extensions 

10 

11# !!!! Don't confuse with "Markdown ASCII Punctuation" chars 

12# http://spec.commonmark.org/0.15/#ascii-punctuation-character 

13 

14 

15_TerminatorChars = { 

16 "\n", 

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@functools.cache 

43def _terminator_char_regex() -> re.Pattern[str]: 

44 return re.compile("[" + re.escape("".join(_TerminatorChars)) + "]") 

45 

46 

47def text(state: StateInline, silent: bool) -> bool: 

48 pos = state.pos 

49 posMax = state.posMax 

50 

51 terminator_char = _terminator_char_regex().search(state.src, pos) 

52 pos = terminator_char.start() if terminator_char else posMax 

53 

54 if pos == state.pos: 

55 return False 

56 

57 if not silent: 

58 state.pending += state.src[state.pos : pos] 

59 

60 state.pos = pos 

61 

62 return True