rendering ¤
Markdown extensions and helpers.
Classes:
-
MarkdownConfig
–This class returns a singleton used to store Markdown extensions configuration.
-
MarkdownConverter
–Helper class to avoid breaking the original Markdown instance state.
Functions:
-
add_source
–Add source code block to the output.
-
code_block
–Format code as a code block.
-
tabbed
–Format tabs using
pymdownx.tabbed
extension.
Attributes:
-
markdown_config
–This object can be used to save the configuration of your Markdown extensions.
markdown_config module-attribute
¤
markdown_config = MarkdownConfig()
This object can be used to save the configuration of your Markdown extensions.
For example, since we provide a MkDocs plugin, we use it to store the configuration that was read from mkdocs.yml
:
from markdown_exec.rendering import markdown_config
# ...in relevant events/hooks, access and modify extensions and their configs, then:
markdown_config.save(extensions, extensions_config)
See the actual event hook: on_config
. See the save
and reset
methods.
Without it, Markdown Exec will rely on the registeredExtensions
attribute of the original Markdown instance, which does not forward everything that was configured, notably extensions like tables
. Other extensions such as attr_list
are visible, but fail to register properly when reusing their instances. It means that the rendered HTML might differ from what you expect (tables not rendered, attribute lists not injected, emojis not working, etc.).
MarkdownConfig ¤
MarkdownConfig()
This class returns a singleton used to store Markdown extensions configuration.
You don't have to instantiate the singleton yourself: we provide it as markdown_config
.
Methods:
-
reset
–Reset Markdown extensions and their configuration.
-
save
–Save Markdown extensions and their configuration.
MarkdownConverter ¤
Helper class to avoid breaking the original Markdown instance state.
Methods:
-
convert
–Convert Markdown text to safe HTML.
add_source ¤
add_source(
*,
source: str,
location: str,
output: str,
language: str,
tabs: tuple[str, str],
result: str = "",
**extra: str
) -> str
Add source code block to the output.
Parameters:
-
source
(str
) –The source code block.
-
location
(str
) –Where to add the source (above, below, tabbed-left, tabbed-right, console).
-
output
(str
) –The current output.
-
language
(str
) –The code language.
-
tabs
(tuple[str, str]
) –Tabs titles (if used).
-
result
(str
, default:''
) –Syntax to use when concatenating source and result with "console" location.
-
**extra
(str
, default:{}
) –Extra options added back to source code block.
Raises:
-
ValueError
–When the given location is not supported.
Returns:
-
str
–The updated output.