Quick start¶
This page uses two extensions, wikilink and keys, in three ways: from
Python, from the python -m markdown command and from MkDocs. The input is the
same each time:
Prerequisites¶
- The package is installed (see Installation).
From Python¶
-
Pass the extension names to
markdown.markdown(): -
Run the script. It prints:
What happened:
wikilinkreplaced[[Getting Started]]with the Markdown link[Getting Started](/Getting-Started/)before parsing. The defaultbase_urlandend_urlare both/, and spaces become-.keysturned++ctrl+s++into a<span class="keys">with one<kbd>per key and a<span>+</span>between them.
To change options, pass extension_configs:
html = markdown.markdown(
text,
extensions=["mdx_steroids.wikilink", "mdx_steroids.keys"],
extension_configs={
"mdx_steroids.wikilink": {"base_url": "/wiki/", "end_url": ".html"},
"mdx_steroids.keys": {"strict": True},
},
)
The link now points to /wiki/Getting-Started.html, and the keys are wrapped in
an outer <kbd class="keys"> instead of a <span>.
From the command line¶
Python-Markdown has a command-line interface. It reads extension options from a JSON or YAML file.
- Save the Markdown as
input.md. -
Save the options as
config.yml: -
Run:
output.html contains:
<h1>Notes</h1>
<p>See <a href="/wiki/Getting-Started.html">Getting Started</a> and press <kbd class="keys"><kbd class="key-control">Ctrl</kbd><span>+</span><kbd class="key-s">S</kbd></kbd> to save.</p>
Every extension named in config.yml must also be loaded with -x.
From MkDocs¶
- Install the package into the environment that runs MkDocs.
-
Add the extensions to
markdown_extensionsinmkdocs.yml: -
Run
mkdocs build.
MkDocs passes each page through the extensions. In the built page, the text reads "See Getting Started and press Ctrl+S to save", with a link and styled keys.
Note
MkDocs reports a link that starts with / as an absolute link and leaves it
unchanged. wikilink keeps the capital letters of the page name, so
[[Getting Started]] links to /Getting-Started/. Make sure the target
page has that URL; see wikilink.
Next steps¶
- Configuration lists the ways to pass options and the option types.
- The extension pages describe each extension.