Skip to content

Latest commit

 

History

History
150 lines (100 loc) · 3.02 KB

README.md

File metadata and controls

150 lines (100 loc) · 3.02 KB

md2pdf logo

Convert Markdown files to PDF with styles.

GitHub Actions Workflow Status GitHub Actions Workflow Status

Installation

The easiest way to go is to use pip:

$ pip install md2pdf

Nota bene: ensure, Weasyprint is fully functional before using md2pdf. You will find installation instructions in the project documentation: https://doc.courtbouillon.org/weasyprint/stable/first_steps.html#installation

Usage

As a CLI

Usage: md2pdf [OPTIONS] MD PDF

  md2pdf command line tool.

Options:
  --css PATH
  -e, --extras TEXT
  --version          Show the version and exit.
  --help             Show this message and exit.

For example, try to generate the project documentation with:

$ md2pdf README.md README.pdf

Optionally, you may load an external style:

$ md2pdf --css tests/assets/input.css README.md README.pdf

And/or activate markdown extras:

$ md2pdf --css pygments.css -e fenced-code-blocks README.md README.pdf

As a library

You can use md2pdf in your python code, like:

from md2pdf.core import md2pdf

md2pdf(pdf,
       md=None,
       raw=None,
       css=None,
       base_url=None,
       extras=[],
)

Function arguments:

  • pdf: output PDF file path
  • raw: input markdown raw string content
  • md: input markdown file path
  • css: input styles path (CSS)
  • base_url: absolute base path for markdown linked content (as images)
  • extras: markdown extras that should be activated

With Docker

Install Docker

Pull the image:

$ docker pull jmaupetit/md2pdf

Now run your image:

$ docker run --rm \
    -v $PWD:/app \
    -u "$(id -u):$(id -g)" \
    jmaupetit/md2pdf --css styles.css INPUT.MD OUTPUT.PDF

Contributing

Hacking

Clone this project first:

$ git clone [email protected]:jmaupetit/md2pdf.git

Install md2pdf along with its dependencies (using Poetry):

$ cd md2pdf
$ poetry install

Running the test suite

To run the test suite with your active python version (virtual environment):

$ poetry run pytest

Lint the code via:

$ poetry run ruff md2pdf

Release a new version

Upload a new release to PyPI:

$ poetry build
$ poetry publish

Ease your life

If you are familiar with GNU Make, we also automate daily tasks using this lovely tool:

$ make help

License

md2pdf is released under the MIT License. See the bundled LICENSE file for details.