Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/markdown_it/parser_core.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

16 statements  

1""" 

2* class Core 

3* 

4* Top-level rules executor. Glues block/inline parsers and does intermediate 

5* transformations. 

6""" 

7 

8from __future__ import annotations 

9 

10from typing import Callable 

11 

12from .ruler import Ruler 

13from .rules_core import ( 

14 block, 

15 inline, 

16 linkify, 

17 normalize, 

18 replace, 

19 smartquotes, 

20 text_join, 

21) 

22from .rules_core.state_core import StateCore 

23 

24RuleFuncCoreType = Callable[[StateCore], None] 

25 

26_rules: list[tuple[str, RuleFuncCoreType]] = [ 

27 ("normalize", normalize), 

28 ("block", block), 

29 ("inline", inline), 

30 ("linkify", linkify), 

31 ("replacements", replace), 

32 ("smartquotes", smartquotes), 

33 ("text_join", text_join), 

34] 

35 

36 

37class ParserCore: 

38 def __init__(self) -> None: 

39 self.ruler = Ruler[RuleFuncCoreType]() 

40 for name, rule in _rules: 

41 self.ruler.push(name, rule) 

42 

43 def process(self, state: StateCore) -> None: 

44 """Executes core chain rules.""" 

45 for rule in self.ruler.getRules(""): 

46 rule(state)