Skip to main content

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.

Video deomo

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 options set template_dir /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.

If you want to have mdexport generate an empty Markdown file with the metadata keys your template expects you can run the following:

mdexport emptymd test.md -t templatename

Generate pdf

mdexport publish file.md -o output.pdf -t invoice

Custom attachments folder

In case you are using Obsidian or some other tool that places images in a seperate folder you can set the name of this folder as:

mdexport options set attachments images_folder

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mdexport-0.9.0.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mdexport-0.9.0-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file mdexport-0.9.0.tar.gz.

File metadata

  • Download URL: mdexport-0.9.0.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.1 Darwin/23.5.0

File hashes

Hashes for mdexport-0.9.0.tar.gz
Algorithm Hash digest
SHA256 0447e5c01c6eb70918100b9f18f7162cbedc4f9afdedfbabf31314b8f01f12b7
MD5 9fba1e23249b227174afa76f2c4e987e
BLAKE2b-256 1e01a3bc8156f9a86bf67e856b3e8277c6872fb38d3ac3e1da65accfb976f07a

See more details on using hashes here.

File details

Details for the file mdexport-0.9.0-py3-none-any.whl.

File metadata

  • Download URL: mdexport-0.9.0-py3-none-any.whl
  • Upload date:
  • Size: 10.3 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

Hashes for mdexport-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ebbda9af854c75e6807da8d1dd078bc67c81bbccf0add9ac2e5b955cc0445092
MD5 5c0f7880c6febdef6240b8a3a30f7848
BLAKE2b-256 9cfc279bcaa2d4963d22d550fc8e3cb0de2c4e962477d150f6fee78f1247b645

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page