
mdfusion
A Python module for merging and exporting Markdown files. Available for pip.
When I am studying for exams, I often end up with a lot of Markdown files in a folder hierarchy. For revising the content, I want to merge these files into one single file and have them in a nicely readable format.
When looking for a solution, I did not find a tool that would crawl the directory for me, merge the files and export them to a PDF or HTML file in one go. So I wrote a small Python module using Pandoc that does exactly that. Since I feel like this is a common use case, I decided to publish it on GitHub and PyPI.
I also added a feature for exporting the merged Markdown to a Powerpoint-like presentation. To do this, I use Pandoc's native support for the reveal.js framework. The presentation can then be viewed in a web browser or exported to a PDF file, which I implemented via the python library Playwright. I figured this would come in handy if I ever need to prepare a presentation quickly.
The code is available on GitHuband on PyPI.
Even though this is a small project, I manage it in a git repository using
Merge all Markdown files in a directory tree into a single PDF or HTML presentation with formatting via Pandoc + XeLaTeX.
.md files under a directory (natural sort order)For HTML presentations and PDF export from HTML, you may want to install:
pip install playwright and then playwright installpandoc is provided through the Python dependency pypandoc_binary, so you do not need a separate global Pandoc installation.
pip install mdfusion
git clone https://github.com/ejuet/mdfusion.git
cd mdfusion
pip install .
mdfusion [OPTIONS]
You can also pass extra Pandoc arguments at the end of the command; any unknown flags are forwarded to Pandoc.
--root_dir DIR Root directory for Markdown files (default: current directory, or config file directory)--output FILE Output filename (default: <root_dir>.pdf or .html for presentations)--toc Include table of contents (use --notoc to disable)--page_break_after_toc Insert a page break after the table of contents in PDF output (default: false)--title_page Include a title page (PDF only)--separate_title_page Put the title page on its own centered page (default: true; use --noseparate_title_page to disable)--title TITLE Set title for title page (default: directory name)--subtitle TEXT Set an optional subtitle for the title page--title_page_image PATH_OR_URL Add an optional local image or remote image URL to the title page--author AUTHOR Set author for title page (default: OS user)--document_date TEXT Set the date text shown in metadata/title page (default: current date)--date_format FORMAT strftime format used when --document_date is omitted (default: %d.%m.%Y)--pandoc_args ARGS Extra Pandoc arguments (whitespace-separated)--config_path FILE Path to a mdfusion.toml config file (default: mdfusion.toml in the current directory)--header_tex PATH Custom LaTeX header to include (defaults to ./header.tex if present)--merged_md DIR Write merged Markdown to this directory (uses a temp dir by default)--exclude PATHS Whitespace-separated files, directories, or glob patterns to skip while merging--remove_alt_texts TXT Comma-separated list of image alt texts to strip (default: alt text)--verbose Enable verbose Pandoc output--presentation Output as a reveal.js HTML presentation (also converts to PDF)--generate_handout After building a presentation, also build a non-presentation PDF handout (default: true; use --nogenerate_handout to disable)--footer_text TEXT Custom footer for presentations--animate_all_lines Add reveal.js fragment animation to each line--chromium_path PATH Path to Chromium for HTML→PDF conversion (default: /usr/bin/chromium)mdfusion --root_dir docs --title_page --title "My Book" --author "Jane Doe"
mdfusion --root_dir slides --presentation --title "My Talk" --author "Speaker" --footer_text "My Conference 2025"
You can create a mdfusion.toml file in your project directory to avoid long command lines. The [mdfusion] section supports all the same options as the CLI. Presentation-only settings live under [presentation] (these can also remain under [mdfusion] for backward compatibility).
[mdfusion]
root_dir = "docs"
output = "my-book.pdf"
toc = true
page_break_after_toc = false
title_page = true
separate_title_page = true
title = "My Book"
subtitle = "Working Draft"
title_page_image = "https://example.com/cover.png"
author = "Jane Doe"
date_format = "%d.%m.%Y"
pandoc_args = ["--number-sections", "--slide-level", "2", "--toc-depth", "4"]
exclude = ["drafts", "appendix/private.md", "notes/*.md"]
# header_tex = "header.tex" # Optional: custom LaTeX header
[mdfusion]
root_dir = "slides"
output = "my-presentation.html"
title = "My Talk"
author = "Speaker"
pandoc_args = ["--slide-level", "6", "--number-sections", "-V", "transition=fade", "-c", "custom.css"]
# You can add more reveal.js or pandoc options as needed with ["-V", "option=value"]
[presentation]
presentation = true
generate_handout = true
footer_text = "My Presentation 2025"
animate_all_lines = false
# chromium_path = "/usr/bin/chromium"
Then just run:
mdfusion
Run all tests with:
pytest
Feel free to leave your opinion or questions in the comment section below.