| 31 | |
| 32 | |
| 33 | class MarkdownIt: |
| 34 | def __init__( |
| 35 | self, |
| 36 | config: str | PresetType = "commonmark", |
| 37 | options_update: Mapping[str, Any] | None = None, |
| 38 | *, |
| 39 | renderer_cls: Callable[[MarkdownIt], RendererProtocol] = RendererHTML, |
| 40 | ): |
| 41 | """Main parser class |
| 42 | |
| 43 | :param config: name of configuration to load or a pre-defined dictionary |
| 44 | :param options_update: dictionary that will be merged into ``config["options"]`` |
| 45 | :param renderer_cls: the class to load as the renderer: |
| 46 | ``self.renderer = renderer_cls(self) |
| 47 | """ |
| 48 | # add modules |
| 49 | self.utils = utils |
| 50 | self.helpers = helpers |
| 51 | |
| 52 | # initialise classes |
| 53 | self.inline = ParserInline() |
| 54 | self.block = ParserBlock() |
| 55 | self.core = ParserCore() |
| 56 | self.renderer = renderer_cls(self) |
| 57 | self.linkify = linkify_it.LinkifyIt() if linkify_it else None |
| 58 | |
| 59 | # set the configuration |
| 60 | if options_update and not isinstance(options_update, Mapping): |
| 61 | # catch signature change where renderer_cls was not used as a key-word |
| 62 | raise TypeError( |
| 63 | f"options_update should be a mapping: {options_update}" |
| 64 | "\n(Perhaps you intended this to be the renderer_cls?)" |
| 65 | ) |
| 66 | self.configure(config, options_update=options_update) |
| 67 | |
| 68 | def __repr__(self) -> str: |
| 69 | return f"{self.__class__.__module__}.{self.__class__.__name__}()" |
| 70 | |
| 71 | @overload |
| 72 | def __getitem__(self, name: Literal["inline"]) -> ParserInline: ... |
| 73 | |
| 74 | @overload |
| 75 | def __getitem__(self, name: Literal["block"]) -> ParserBlock: ... |
| 76 | |
| 77 | @overload |
| 78 | def __getitem__(self, name: Literal["core"]) -> ParserCore: ... |
| 79 | |
| 80 | @overload |
| 81 | def __getitem__(self, name: Literal["renderer"]) -> RendererProtocol: ... |
| 82 | |
| 83 | @overload |
| 84 | def __getitem__(self, name: str) -> Any: ... |
| 85 | |
| 86 | def __getitem__(self, name: str) -> Any: |
| 87 | return { |
| 88 | "inline": self.inline, |
| 89 | "block": self.block, |
| 90 | "core": self.core, |
no outgoing calls
searching dependent graphs…