MCPcopy Create free account
hub / github.com/executablebooks/markdown-it-py / MarkdownIt

Class MarkdownIt

markdown_it/main.py:33–351  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31
32
33class 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,

Callers 15

convert_stdinFunction · 0.90
convert_fileFunction · 0.90
interactiveFunction · 0.90
profiler.pyFile · 0.90
test_fuzzingFunction · 0.90
test_token_levelsFunction · 0.90
test_typeFunction · 0.90
test_sibling_traverseFunction · 0.90
test_prettyFunction · 0.90
test_pretty_text_specialFunction · 0.90

Calls

no outgoing calls

Tested by 15

test_fuzzingFunction · 0.72
test_token_levelsFunction · 0.72
test_typeFunction · 0.72
test_sibling_traverseFunction · 0.72
test_prettyFunction · 0.72
test_pretty_text_specialFunction · 0.72
test_walkFunction · 0.72
test_highlight_argumentsFunction · 0.72
test_ordered_list_infoFunction · 0.72
test_linkifyFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…