1"""
2 * class Core
3 *
4 * Top-level rules executor. Glues block/inline parsers and does intermediate
5 * transformations.
6"""
7from __future__ import annotations
8
9from typing import Callable
10
11from .ruler import Ruler
12from .rules_core import (
13 block,
14 inline,
15 linkify,
16 normalize,
17 replace,
18 smartquotes,
19 text_join,
20)
21from .rules_core.state_core import StateCore
22
23RuleFuncCoreType = Callable[[StateCore], None]
24
25_rules: list[tuple[str, RuleFuncCoreType]] = [
26 ("normalize", normalize),
27 ("block", block),
28 ("inline", inline),
29 ("linkify", linkify),
30 ("replacements", replace),
31 ("smartquotes", smartquotes),
32 ("text_join", text_join),
33]
34
35
36class ParserCore:
37 def __init__(self) -> None:
38 self.ruler = Ruler[RuleFuncCoreType]()
39 for name, rule in _rules:
40 self.ruler.push(name, rule)
41
42 def process(self, state: StateCore) -> None:
43 """Executes core chain rules."""
44 for rule in self.ruler.getRules(""):
45 rule(state)