mdsphinx
Convert markdown to any output format that Sphinx supports.
In contrast to something like pandoc, this tool is useful if you want to...
- Use Jinja2 templating.
- Use MyST Markdown syntax.
- Use other Sphinx extensions.
- Push Markdown to a Confluence page.
Installation
pipx install mdsphinx
Usage
- Create a markdown file or directory with markdown files.
- Run
mdsphinx env createto create the default environment. - Optionally, create a
conf.py.jinjafile to customize the Sphinxconf.py. - Optionally, create a
context.ymlfile with variables to be injected via Jinja2. - Run
mdsphinx process <inp> --to <fmt> --using <preset> --as <out>to convert the markdown.
TLDR
mdsphinx env create
mdsphinx process input.md --to pdf --using latex
You can also process a directory of markdown files.
mdsphinx process ./inputs --to pdf --using latex --as output.pdf
Output Formats
There are a few different formats you can convert to:
mdsphinx process input.md --to pdf --using latex
mdsphinx process input.md --to html --using default
mdsphinx process input.md --to confluence --using single.page
Environments
The default environment installs the following packages:
sphinxnbsphinxmyst-parsersphinxcontrib-confluencebuilder
However, you can register any virtual environment you want to use as long as it contains sphinx.
mdsphinx env add --name my_custom_env --path /path/to/my_custom_env
mdsphinx process input.md --to pdf --using latex --env-name my_custom_env
Environments and metadata are stored in the $MDSPHINX_CONFIG_ROOT, which defaults to ~/.config/mdsphinx.
You can safely delete this directory at any time.
Jinja2 Templating
Create a file named context.yml parallel to the input file or directory.
a: 1
b: 2
You can then reference these variables in your markdown files.
{{ a }} + {{ b }} = {{ a + b }}
Support for Mermaid diagrams is available as a custom jinja2 block.
You must have
dockerinstalled and ideally be using theMySTparser.
{% mermaid -%}
ext: .png
mode: myst
scale: 3
width: 75
align: center
caption: |
An example mermaid diagram!
diagram: |
graph TD
A --> B
B --> C
A --> C
{% endmermaid %}
Likewise, you can use the tikz block to render LaTeX diagrams.
You must have
tectonicinstalled and ideally be using theMySTparser.
{% tikz -%}
ext: .png
mode: myst
diagram: |
\documentclass[margin=0pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (0,0) -- (1,1);
\end{tikzpicture}
\end{document}
{% endtikz %}
Sphinx Configuration
Create a file named conf.py.jinja parallel to the input file or directory.
{% include main_sphinx_config %}
html_theme = "alabaster"
You can generate a copy of the default conf.py.jinja file.
mdsphinx generate conf.py.jinja
This file will be used by sphinx-quickstart to generate the Sphinx configuration file.
Confluence Configuration
The default Sphinx conf.py sets up a confluence connection by reading your ~/.netrc and environment variables.
Sphinx conf.py Variable |
Default Source | Environment Variable Name | Example Value |
|---|---|---|---|
confluence_publish_dryrun |
env |
CONFLUENCE_PUBLISH_DRYRUN |
1 |
confluence_server_url |
env |
CONFLUENCE_SERVER_URL |
https://example.atlassian.net/wiki |
confluence_server_user |
netrc[url].login |
example@gmail.com |
|
confluence_api_token |
netrc[url].password |
api-token |
|
confluence_space_key |
env |
CONFLUENCE_SPACE_KEY |
~MySpace |
confluence_parent_page |
env |
CONFLUENCE_PARENT_PAGE |
ParentPage |
Obtain an API token from your Atlassian account settings and configure your ~/.netrc file:
machine <confluence_server_url>
login <confluence_server_user>
password <confluence_api_token>
Create a parent page manually on your confluence space and configure the environment variables.
export CONFLUENCE_PUBLISH_DRYRUN="0"
export CONFLUENCE_SERVER_URL="https://example.atlassian.net/wiki"
export CONFLUENCE_SPACE_KEY="~MySpace"
export CONFLUENCE_PARENT_PAGE="ParentPage"
mdsphinx process input.md --to confluence --using single.page
LaTeX Configuration
The default LaTeX configuration is set up to use tectonic as the LaTeX engine.
However, you can set MDSPHINX_LATEX_COMMAND to be a ; delimited list of commands to run instead.
export MDSPHINX_LATEX_COMMAND="xelatex {tex}"
Metadata
Release files for mdsphinx 1.11.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mdsphinx-1.11.0.tar.gz | 14.7 kB | Without provenance | Details for mdsphinx-1.11.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mdsphinx-1.11.0-py3-none-any.whl | Python 3 | none | any | Details for mdsphinx-1.11.0-py3-none-any.whl |
Total release size: 32.8 kB
Release files / mdsphinx-1.11.0.tar.gz
| Download URL | mdsphinx-1.11.0.tar.gz |
|---|---|
| Size | 14.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
42e36997020d10a94bf131c036f6a8630e19d7c4d180a456c2cd764f5f263b68
|
|
BLAKE2b-256 checksum How to use checksums |
cdab0494406dfbf16931062ba0b76b77a5706e30a260500c738a8f4666e262d5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.2.1 CPython/3.13.5 Linux/6.14.0-33-generic
|
Release files / mdsphinx-1.11.0-py3-none-any.whl
| Download URL | mdsphinx-1.11.0-py3-none-any.whl |
|---|---|
| Size | 18.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
123fc6e2d8e3b07aec8042ba89dab604dfde7b3aa71470dc2537238bdbca40d3
|
|
BLAKE2b-256 checksum How to use checksums |
5450f937936038a256ba7568934b7ed7694b90fd66565f628a5c3803696c9742
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.2.1 CPython/3.13.5 Linux/6.14.0-33-generic
|
Security for mdsphinx 1.11.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.