MCPcopy Create free account
hub / github.com/Python-Markdown/markdown / Extension

Class Extension

markdown/extensions/__init__.py:37–145  ·  view source on GitHub ↗

Base class for extensions to subclass.

Source from the content-addressed store, hash-verified

35
36
37class Extension:
38 """ Base class for extensions to subclass. """
39
40 config: Mapping[str, list] = {}
41 """
42 Default configuration for an extension.
43
44 This attribute is to be defined in a subclass and must be of the following format:
45
46 ``` python
47 config = {
48 'key': ['value', 'description']
49 }
50 ```
51
52 Note that [`setConfig`][markdown.extensions.Extension.setConfig] will raise a [`KeyError`][]
53 if a default is not set for each option.
54 """
55
56 def __init__(self, **kwargs):
57 """ Initiate Extension and set up configs. """
58 self.setConfigs(kwargs)
59
60 def getConfig(self, key: str, default: Any = '') -> Any:
61 """
62 Return a single configuration option value.
63
64 Arguments:
65 key: The configuration option name.
66 default: Default value to return if key is not set.
67
68 Returns:
69 Value of stored configuration option.
70 """
71 if key in self.config:
72 return self.config[key][0]
73 else:
74 return default
75
76 def getConfigs(self) -> dict[str, Any]:
77 """
78 Return all configuration options.
79
80 Returns:
81 All configuration options.
82 """
83 return {key: self.getConfig(key) for key in self.config.keys()}
84
85 def getConfigInfo(self) -> list[tuple[str, str]]:
86 """
87 Return descriptions of all configuration options.
88
89 Returns:
90 All descriptions of configuration options.
91 """
92 return [(key, self.config[key][1]) for key in self.config.keys()]
93
94 def setConfig(self, key: str, value: Any) -> None:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected