Skip to main content

Print PDFs from Markdown Files using Weasyprint

Project description

md2weasypdf

Print PDFs from Markdown Files and a HTML template/layout using Weasyprint.

Installation

pip install md2weasypdf

Usage

python -m md2weasypdf <input_folder_or_file> <output_path>

When a layout is not specified in the files frontmatter (see below), the --layout option has to be passed.

Watch Mode

The watch mode is intended for creation of layouts. The given layouts directory and input directory will be watched for changes.

For VSCode the extension vscode-pdf can be recommended, as it refreshes the displayed PDF automatically.

python -m md2weasypdf <input_folder_or_file> <output_path> --watch

Layout

The document layout must be given via the command option --layout or in the frontmatter of the single file. As layout a directory name inside the ./layouts directory (default, can be changed using --layouts-dir) is expected. In the layout directory, a index.html.j2 or index.html file is expected, which is loaded as entrypoint. The file is parsed using Jinja2.

Input

Input files are expected in markdown format with several markdown extensions. The markdown documents can utilize Jinja2 for templating inside the document (e. g. reusing texts).

Bundling

The bundling feature allows to bundle multiple documents into one PDF. This is useful when you want to create one PDF file from multiple source files. The bundling feature is enabled by adding the --bundle flag to the command. The specified input folder will be searched recursively for *.md files, files starting with an underscore will be ignored.

When using the bundle option, a layout has to be specified using --layout and a title for the whole document using --title.

Options

YAML Frontmatter can be used to customize the document layout or add other options which will be passed to the template. The following example shows how a document with frontmatter section could look like:

---
title: My Document Title
layout: doc1
---
Lorem ipsum...

Markdown Extensions

Table of Contents

Insert a table of contents using [TOC]. The table of contents will be generated automatically based on the headlines (lines starting with one or multiple #) in the document.

Table of Abbreviations

Insert a table of abbreviations using [TOA]. The table of abbreviations will be generated automatically based on defined abbreviations (using *[Abbreviation]: Explanation) in the document.

Footnotes

Footnotes let you reference relevant information without disrupting the flow of what you're trying to say:

Here's a simple footnote,[^1] and here's a longer one.[^bignote]

[^1]: This is the first footnote.

[^bignote]: Here's one with multiple paragraphs and code.

    Indent paragraphs to include them in the footnote.

    `{ my code }`

    Add as many paragraphs as you like.

It is possible to reference to the same footnote by using the same footnote label.

Subscript

Use tildes ~ around text to create a subscript formatting.

Checkboxes

Use [ ] to create a checkbox. Use [x] to mark a checkbox as checked.

Fields

Use [>input_id] to create a text input. To create a textarea, add |textbox after the input id. To create a date field, add |YYYY-MM-DD after the input id.

To add a placeholder, append the placeholder text within parens to the end of the input id: [>input_id] (placeholder text).

Mermaid.js

Mermaid.js can be used in code blocks with the language mermaid. To convert the mermaid code into an image, mermaid-cli is required to be installed on the system.

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

md2weasypdf-0.0.22.tar.gz (23.1 kB view details)

Uploaded Source

Built Distribution

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

md2weasypdf-0.0.22-py3-none-any.whl (24.6 kB view details)

Uploaded Python 3

File details

Details for the file md2weasypdf-0.0.22.tar.gz.

File metadata

  • Download URL: md2weasypdf-0.0.22.tar.gz
  • Upload date:
  • Size: 23.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for md2weasypdf-0.0.22.tar.gz
Algorithm Hash digest
SHA256 adf08d305c7b02652c99e0646b90c42e59023b805009fe3404583fb15cc77d50
MD5 8a5310bbb3d10206189cca3574e7b236
BLAKE2b-256 610b133e81d2c5ad382bd8880c0b53a1d8036638a4e3ade754e2a49642459cc5

See more details on using hashes here.

File details

Details for the file md2weasypdf-0.0.22-py3-none-any.whl.

File metadata

  • Download URL: md2weasypdf-0.0.22-py3-none-any.whl
  • Upload date:
  • Size: 24.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for md2weasypdf-0.0.22-py3-none-any.whl
Algorithm Hash digest
SHA256 c93ba390d289d1281925d2d4ee79677f3cbe4262d8e1a13aab977779fc7feb2e
MD5 7690ebe0efb4717395a7f744363b50b3
BLAKE2b-256 619144836727b85b9c22d73879e1bf3fa0c33f8d894fd81543a401d7ab846c00

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