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

Method registerExtensions

markdown/core.py:161–195  ·  view source on GitHub ↗

Load a list of extensions into an instance of the `Markdown` class. Arguments: extensions (list[Extension | str]): A list of extensions. If an item is an instance of a subclass of [`markdown.extensions.Extension`][], the instance will be

(
        self,
        extensions: Sequence[Extension | str],
        configs: Mapping[str, dict[str, Any]]
    )

Source from the content-addressed store, hash-verified

159 return self
160
161 def registerExtensions(
162 self,
163 extensions: Sequence[Extension | str],
164 configs: Mapping[str, dict[str, Any]]
165 ) -> Markdown:
166 """
167 Load a list of extensions into an instance of the `Markdown` class.
168
169 Arguments:
170 extensions (list[Extension | str]): A list of extensions.
171
172 If an item is an instance of a subclass of [`markdown.extensions.Extension`][],
173 the instance will be used as-is. If an item is of type `str`, it is passed
174 to [`build_extension`][markdown.Markdown.build_extension] with its corresponding `configs` and the
175 returned instance of [`markdown.extensions.Extension`][] is used.
176 configs (dict[str, dict[str, Any]]): Configuration settings for extensions.
177
178 """
179 for ext in extensions:
180 if isinstance(ext, str):
181 ext = self.build_extension(ext, configs.get(ext, {}))
182 if isinstance(ext, Extension):
183 ext.extendMarkdown(self)
184 logger.debug(
185 'Successfully loaded extension "%s.%s".'
186 % (ext.__class__.__module__, ext.__class__.__name__)
187 )
188 elif ext is not None:
189 raise TypeError(
190 'Extension "{}.{}" must be of type: "{}.{}"'.format(
191 ext.__class__.__module__, ext.__class__.__name__,
192 Extension.__module__, Extension.__name__
193 )
194 )
195 return self
196
197 def build_extension(self, ext_name: str, configs: Mapping[str, Any]) -> Extension:
198 """

Callers 2

__init__Method · 0.95
extendMarkdownMethod · 0.80

Calls 2

build_extensionMethod · 0.95
extendMarkdownMethod · 0.45

Tested by

no test coverage detected