Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
parser_core.py47 linesDownload Raw Back to markdown_it
1"""2* class Core3*4* Top-level rules executor. Glues block/inline parsers and does intermediate5* transformations.6"""7 8from __future__ import annotations9 10from collections.abc import Callable11 12from .ruler import Ruler13from .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 StateCore23 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)47 
codekingpro/portable-devtools · Team Ai