CLI tool to export markdown to pdf using jinja2 templates.
Project description
Description
Mdexport is CLI tool to publish Markdown files as PDF using Jinja2 templates. You can use Frontmatter metadata as custom values to be filled into your template.
Designed to work with Obsidian.
Installation
pip3 install mdexport
Usage
Setup an html templates directory
Create a directory where you will store your templates. Each template should be a subdirectory named with the desired template name.
templates/
├──invoice/
│ ├──template.html
│ └──(any files or images that template.html depends on)
└── thesis/
├──template.html
└──(any files or images that template.html depends on)
Update the config of mdexport
Set the path of your template directory in the mdexport config.
mdexport settemplatedir /path/to/templates
Create your template
Create a template.html file with a Jinja2 template.
<html>
<body>
<section>
<b>Date: {{date}}</b>
<b>To: {{to}}</b>
</section>
<section>
<p>{{body}}</p>
</section>
</body>
</html>
Create your MD file
Write your Markdown file. Provide Frontmatter metadata(compatible with Obsidian properties) as the keys that shall be rendered in your template.
---
date: 14/10/2024
to: Bob
---
Body of my markdown file.
Generate pdf
mdexport publish file.md -o output.pdf -t invoice
Dependencies
Mdexport makes use of Weasyprint to generate PDF files. Installation of Weasyprint seems to be not straight forward on some systems. If you encounter issues please follow the steps in the link below.
[https://doc.courtbouillon.org/weasyprint/stable/first_steps.html#installation]
Issue with weasyprint on Mac
echo 'export DYLD_LIBRARY_PATH=$(brew --prefix)/lib' >> ~/.bashrc
sudo ln -s /opt/homebrew/opt/glib/lib/libgobject-2.0.0.dylib /usr/local/lib/gobject-2.0
sudo ln -s /opt/homebrew/opt/pango/lib/libpango-1.0.dylib /usr/local/lib/pango-1.0
sudo ln -s /opt/homebrew/opt/harfbuzz/lib/libharfbuzz.dylib /usr/local/lib/harfbuzz
sudo ln -s /opt/homebrew/opt/fontconfig/lib/libfontconfig.1.dylib /usr/local/lib/fontconfig-1
sudo ln -s /opt/homebrew/opt/pango/lib/libpangoft2-1.0.dylib /usr/local/lib/pangoft2-1.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file mdexport-0.1.1.tar.gz
.
File metadata
- Download URL: mdexport-0.1.1.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.12.1 Darwin/23.5.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5637c2a338f2f07cb839e1f7e14806f35b32e743a5f0f7c4bdf53a26a979a806 |
|
MD5 | e6787d0f080ad4b0e44fbc8f2cb3d1e4 |
|
BLAKE2b-256 | 13e587d3d135a2a424ff4f0f254d9ddb43bfd6263deb5d7f9612627821752464 |
File details
Details for the file mdexport-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: mdexport-0.1.1-py3-none-any.whl
- Upload date:
- Size: 8.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.12.1 Darwin/23.5.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | db43fdd744acd9048dc25d11a6fedaa8d898a4f583174dee2b11aa6232f845dd |
|
MD5 | 3b0f4436902bc109d05df8ef099df444 |
|
BLAKE2b-256 | 176f49814223a51183ed71e6e7c400fe19b9a647a5a52d3932202e71e88c7eb1 |