md2pdf 2.0.0__tar.gz → 3.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. {md2pdf-2.0.0 → md2pdf-3.0.0}/.github/workflows/chore.yml +1 -1
  2. {md2pdf-2.0.0 → md2pdf-3.0.0}/.github/workflows/docker-publish.yml +2 -2
  3. {md2pdf-2.0.0 → md2pdf-3.0.0}/.github/workflows/quality.yml +4 -0
  4. {md2pdf-2.0.0 → md2pdf-3.0.0}/CHANGELOG.md +23 -1
  5. {md2pdf-2.0.0 → md2pdf-3.0.0}/Dockerfile +1 -1
  6. {md2pdf-2.0.0 → md2pdf-3.0.0}/Dockerfile.alpine +1 -1
  7. {md2pdf-2.0.0 → md2pdf-3.0.0}/Makefile +7 -1
  8. {md2pdf-2.0.0 → md2pdf-3.0.0}/PKG-INFO +33 -21
  9. {md2pdf-2.0.0 → md2pdf-3.0.0}/README.md +28 -19
  10. {md2pdf-2.0.0 → md2pdf-3.0.0}/pyproject.toml +17 -3
  11. md2pdf-3.0.0/src/md2pdf/cli.py +150 -0
  12. {md2pdf-2.0.0 → md2pdf-3.0.0}/src/md2pdf/core.py +4 -1
  13. {md2pdf-2.0.0 → md2pdf-3.0.0}/src/md2pdf/exceptions.py +0 -2
  14. md2pdf-3.0.0/tests/conftest.py +24 -0
  15. {md2pdf-2.0.0 → md2pdf-3.0.0}/tests/defaults.py +1 -0
  16. md2pdf-3.0.0/tests/test_cli.py +156 -0
  17. md2pdf-3.0.0/tests/test_core.py +100 -0
  18. {md2pdf-2.0.0 → md2pdf-3.0.0}/uv.lock +241 -6
  19. md2pdf-2.0.0/src/md2pdf/cli.py +0 -26
  20. md2pdf-2.0.0/tests/test_cli.py +0 -68
  21. md2pdf-2.0.0/tests/test_core.py +0 -39
  22. {md2pdf-2.0.0 → md2pdf-3.0.0}/.dockerignore +0 -0
  23. {md2pdf-2.0.0 → md2pdf-3.0.0}/.github/pull_request_template.md +0 -0
  24. {md2pdf-2.0.0 → md2pdf-3.0.0}/.github/workflows/docker-images.yml +0 -0
  25. {md2pdf-2.0.0 → md2pdf-3.0.0}/.github/workflows/package.yml +0 -0
  26. {md2pdf-2.0.0 → md2pdf-3.0.0}/.gitignore +0 -0
  27. {md2pdf-2.0.0 → md2pdf-3.0.0}/.python-version +0 -0
  28. {md2pdf-2.0.0 → md2pdf-3.0.0}/LICENSE +0 -0
  29. {md2pdf-2.0.0 → md2pdf-3.0.0}/assets/md2pdf-logo.png +0 -0
  30. {md2pdf-2.0.0 → md2pdf-3.0.0}/examples/custom-styles-with-pygments.css +0 -0
  31. {md2pdf-2.0.0 → md2pdf-3.0.0}/examples/custom-styles.css +0 -0
  32. {md2pdf-2.0.0 → md2pdf-3.0.0}/examples/gutenberg-modern.min.css +0 -0
  33. {md2pdf-2.0.0 → md2pdf-3.0.0}/examples/my-music.md.j2 +0 -0
  34. {md2pdf-2.0.0 → md2pdf-3.0.0}/renovate.json +0 -0
  35. {md2pdf-2.0.0 → md2pdf-3.0.0}/src/md2pdf/__init__.py +0 -0
  36. {md2pdf-2.0.0 → md2pdf-3.0.0}/src/md2pdf/__main__.py +0 -0
  37. {md2pdf-2.0.0 → md2pdf-3.0.0}/src/md2pdf/conf.py +0 -0
  38. {md2pdf-2.0.0 → md2pdf-3.0.0}/tests/__init__.py +0 -0
  39. {md2pdf-2.0.0 → md2pdf-3.0.0}/tests/assets/input.css +0 -0
  40. {md2pdf-2.0.0 → md2pdf-3.0.0}/tests/assets/input.md +0 -0
@@ -39,4 +39,4 @@ jobs:
39
39
  - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
40
40
  - name: Check CHANGELOG max line length
41
41
  run: |
42
- test $(cat CHANGELOG.md | grep -Ev "^\[.*\]: https://github.com/jmaupetit/data7" | wc -L) -le 80
42
+ test $(cat CHANGELOG.md | grep -Ev "^\[.*\]: https://github.com/jmaupetit/md2pdf" | wc -L) -le 80
@@ -18,7 +18,7 @@ jobs:
18
18
  - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
19
19
 
20
20
  - name: Log in to Docker Hub
21
- uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
21
+ uses: docker/login-action@0567fa5ae8c9a197cb207537dc5cbb43ca3d803f
22
22
  with:
23
23
  username: ${{ secrets.DOCKER_USERNAME }}
24
24
  password: ${{ secrets.DOCKER_PASSWORD }}
@@ -38,7 +38,7 @@ jobs:
38
38
 
39
39
  - name: Extract metadata (tags, labels) for Docker
40
40
  id: meta
41
- uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
41
+ uses: docker/metadata-action@ed95091677497158a9ff38b314264cd965388d5e
42
42
  with:
43
43
  images: jmaupetit/md2pdf
44
44
  tags: ${{ steps.version.outputs.version }}
@@ -55,6 +55,8 @@ jobs:
55
55
  run: make lint-black-check
56
56
  - name: Lint with Ruff
57
57
  run: make lint-ruff
58
+ - name: Lint with Mypy
59
+ run: make lint-mypy
58
60
 
59
61
  test:
60
62
  needs: build
@@ -78,4 +80,6 @@ jobs:
78
80
  - name: Initialize the project for testing
79
81
  run: make bootstrap
80
82
  - name: Test with pytest
83
+ env:
84
+ TERM: dumb
81
85
  run: make test
@@ -8,6 +8,26 @@ and this project adheres to
8
8
 
9
9
  ## [Unreleased]
10
10
 
11
+ ## [3.0.0] - 2026-01-22
12
+
13
+ ### Added
14
+
15
+ - CLI: allow multiple input markdown files (converted using multiple threads)
16
+ - CLI: add the `--workers` option to adapt parallelisation
17
+
18
+ ### Changed
19
+
20
+ - Add dependency groups to handle project flavors (`cli` and `latex`) [BC]
21
+ - CLI: switched to [Typer](https://typer.tiangolo.com/)
22
+ - CLI: moved to a no-arguments command (only options) [BC]
23
+
24
+ ## [2.1.0] - 2026-01-12
25
+
26
+ ### Added
27
+
28
+ - Allow extra markdown extensions configuration using a JSON string (CLI) or a
29
+ dict (API)
30
+
11
31
  ## [2.0.0] - 2026-01-09
12
32
 
13
33
  ### Added
@@ -67,7 +87,9 @@ and this project adheres to
67
87
 
68
88
  - Add current directory as `base_url` to md2pdf script (Fix #6)
69
89
 
70
- [unreleased]: https://github.com/jmaupetit/md2pdf/compare/2.0.0...main
90
+ [unreleased]: https://github.com/jmaupetit/md2pdf/compare/3.0.0...main
91
+ [3.0.0]: https://github.com/jmaupetit/md2pdf/compare/2.1.0...3.0.0
92
+ [2.1.0]: https://github.com/jmaupetit/md2pdf/compare/2.0.0...2.1.0
71
93
  [2.0.0]: https://github.com/jmaupetit/md2pdf/compare/1.0.1...2.0.0
72
94
  [1.0.1]: https://github.com/jmaupetit/md2pdf/compare/1.0.0...1.0.1
73
95
  [1.0.0]: https://github.com/jmaupetit/md2pdf/compare/0.6...1.0.0
@@ -27,7 +27,7 @@ COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
27
27
  RUN --mount=type=cache,target=/root/.cache/uv \
28
28
  --mount=type=bind,source=uv.lock,target=uv.lock \
29
29
  --mount=type=bind,source=pyproject.toml,target=pyproject.toml \
30
- uv sync --locked --no-install-project --no-editable
30
+ uv sync --extra cli --extra latex --locked --no-install-project --no-editable
31
31
 
32
32
  # Copy the project into the intermediate image
33
33
  COPY . /app
@@ -29,7 +29,7 @@ COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
29
29
  RUN --mount=type=cache,target=/root/.cache/uv \
30
30
  --mount=type=bind,source=uv.lock,target=uv.lock \
31
31
  --mount=type=bind,source=pyproject.toml,target=pyproject.toml \
32
- uv sync --locked --no-install-project --no-editable
32
+ uv sync --extra cli --extra latex --locked --no-install-project --no-editable
33
33
 
34
34
  # Copy the project into the intermediate image
35
35
  COPY . /app
@@ -36,7 +36,8 @@ build-docker-alpine: ## build Docker (alpine) image
36
36
  lint: ## lint all sources
37
37
  lint: \
38
38
  lint-black \
39
- lint-ruff
39
+ lint-ruff \
40
+ lint-mypy
40
41
  .PHONY: lint
41
42
 
42
43
  lint-black: ## lint python sources with black
@@ -59,6 +60,11 @@ lint-ruff-fix: ## lint and fix python sources with ruff
59
60
  uv run ruff check --fix src/md2pdf tests
60
61
  .PHONY: lint-ruff-fix
61
62
 
63
+ lint-mypy: ## lint python sources with mypy
64
+ @echo 'lint:mypy started…'
65
+ uv run mypy src/md2pdf tests
66
+ .PHONY: lint-mypy
67
+
62
68
  test: ## run the test suite
63
69
  $(UV_RUN) pytest
64
70
  .PHONY: test
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: md2pdf
3
- Version: 2.0.0
3
+ Version: 3.0.0
4
4
  Summary: The Markdown to PDF conversion tool with styles
5
5
  Project-URL: Homepage, https://github.com/jmaupetit/md2pdf
6
6
  Project-URL: Repository, https://github.com/jmaupetit/md2pdf
@@ -23,13 +23,16 @@ Classifier: Programming Language :: Python :: 3.14
23
23
  Classifier: Topic :: Office/Business
24
24
  Classifier: Topic :: Utilities
25
25
  Requires-Python: >=3.10
26
- Requires-Dist: click>=8.1
27
26
  Requires-Dist: jinja2>=3
28
27
  Requires-Dist: markdown>=3.5
29
28
  Requires-Dist: pygments>=2.17
30
29
  Requires-Dist: pymdown-extensions>=10
31
30
  Requires-Dist: python-frontmatter>=1.1
32
31
  Requires-Dist: weasyprint>=60
32
+ Provides-Extra: cli
33
+ Requires-Dist: typer>=0.21.1; extra == 'cli'
34
+ Provides-Extra: latex
35
+ Requires-Dist: markdown-katex>=202406.1035; extra == 'latex'
33
36
  Description-Content-Type: text/markdown
34
37
 
35
38
  ![md2pdf logo](https://github.com/jmaupetit/md2pdf/raw/main/assets/md2pdf-logo.png)
@@ -45,7 +48,7 @@ Convert Markdown files to PDF with styles.
45
48
  The easiest way to test `md2pdf` is to use `uv`:
46
49
 
47
50
  ```bash
48
- $ uv tool install md2pdf
51
+ $ uv tool install md2pdf[cli]
49
52
  ```
50
53
 
51
54
  _Nota bene:_ ensure, Weasyprint is fully functional before using md2pdf. You
@@ -57,30 +60,40 @@ will find installation instructions in the project documentation:
57
60
  ### As a CLI
58
61
 
59
62
  ```
60
- Usage: md2pdf [OPTIONS] MD PDF
61
-
62
- md2pdf command line tool.
63
-
64
- Options:
65
- --css PATH
66
- -e, --extras TEXT
67
- --version Show the version and exit.
68
- --help Show this message and exit.
63
+ Usage: md2pdf [OPTIONS]
64
+
65
+ Markdown to PDF conversion tool with styles… and templates!
66
+
67
+ ╭─ Options ──────────────────────────────────────────────────────────────────────────────────────────╮
68
+ │ --input -i PATH Markdown source file path (can be used multiple times). │
69
+ │ --output -o PATH PDF output file path (when a single md input is used). │
70
+ │ --css -c PATH Input CSS file. │
71
+ │ --extras -e TEXT Extra markdown extension to activate (cam be used multiple │
72
+ │ times). │
73
+ │ --config -C TEXT Markdown extensions configuration (as a JSON string). │
74
+ │ --workers -W INTEGER Number of parallel workers to start. [default: 4] │
75
+ │ --version -V Display program version. │
76
+ │ --install-completion Install completion for the current shell. │
77
+ │ --show-completion Show completion for the current shell, to copy it or │
78
+ │ customize the installation. │
79
+ │ --help Show this message and exit. │
80
+ ╰────────────────────────────────────────────────────────────────────────────────────────────────────╯
69
81
  ```
70
82
 
71
83
  For example, try to generate the project documentation with:
72
84
 
73
85
  ```bash
74
- $ md2pdf README.md README.pdf
86
+ $ md2pdf -i README.md
75
87
  ```
76
88
 
77
- Optionally, you may load an external style:
89
+ A `README.pdf` should have been generated.
90
+
91
+ Optionally, you may load an external style sheet:
78
92
 
79
93
  ```bash
80
94
  $ md2pdf \
81
95
  --css examples/custom-styles.css \
82
- README.md \
83
- README.pdf
96
+ -i README.md
84
97
  ```
85
98
 
86
99
  And activate [markdown extensions from
@@ -90,8 +103,7 @@ PyMdown](https://facelessuser.github.io/pymdown-extensions/):
90
103
  $ md2pdf \
91
104
  --css examples/custom-styles-with-pygments.css \
92
105
  --extras 'pymdownx.emoji' \
93
- README.md \
94
- README.pdf
106
+ -i README.md
95
107
  ```
96
108
 
97
109
  > Code blocks should be properly rendered when this extension is active.
@@ -142,7 +154,7 @@ Now run your image:
142
154
  $ docker run --rm \
143
155
  -v $PWD:/app \
144
156
  -u "$(id -u):$(id -g)" \
145
- jmaupetit/md2pdf --css styles.css INPUT.MD OUTPUT.PDF
157
+ jmaupetit/md2pdf --css styles.css -i INPUT.MD -o OUTPUT.PDF
146
158
  ```
147
159
 
148
160
  ### Use Jinja templates as input
@@ -179,8 +191,8 @@ You can test this example using:
179
191
  ```bash
180
192
  $ md2pdf \
181
193
  --css examples/gutenberg-modern.min.css \
182
- examples/my-music.md.j2 \
183
- examples/my-music.pdf
194
+ -i examples/my-music.md.j2 \
195
+ -o examples/my-music.pdf
184
196
  ```
185
197
 
186
198
  ## Contributing
@@ -11,7 +11,7 @@ Convert Markdown files to PDF with styles.
11
11
  The easiest way to test `md2pdf` is to use `uv`:
12
12
 
13
13
  ```bash
14
- $ uv tool install md2pdf
14
+ $ uv tool install md2pdf[cli]
15
15
  ```
16
16
 
17
17
  _Nota bene:_ ensure, Weasyprint is fully functional before using md2pdf. You
@@ -23,30 +23,40 @@ will find installation instructions in the project documentation:
23
23
  ### As a CLI
24
24
 
25
25
  ```
26
- Usage: md2pdf [OPTIONS] MD PDF
27
-
28
- md2pdf command line tool.
29
-
30
- Options:
31
- --css PATH
32
- -e, --extras TEXT
33
- --version Show the version and exit.
34
- --help Show this message and exit.
26
+ Usage: md2pdf [OPTIONS]
27
+
28
+ Markdown to PDF conversion tool with styles… and templates!
29
+
30
+ ╭─ Options ──────────────────────────────────────────────────────────────────────────────────────────╮
31
+ │ --input -i PATH Markdown source file path (can be used multiple times). │
32
+ │ --output -o PATH PDF output file path (when a single md input is used). │
33
+ │ --css -c PATH Input CSS file. │
34
+ │ --extras -e TEXT Extra markdown extension to activate (cam be used multiple │
35
+ │ times). │
36
+ │ --config -C TEXT Markdown extensions configuration (as a JSON string). │
37
+ │ --workers -W INTEGER Number of parallel workers to start. [default: 4] │
38
+ │ --version -V Display program version. │
39
+ │ --install-completion Install completion for the current shell. │
40
+ │ --show-completion Show completion for the current shell, to copy it or │
41
+ │ customize the installation. │
42
+ │ --help Show this message and exit. │
43
+ ╰────────────────────────────────────────────────────────────────────────────────────────────────────╯
35
44
  ```
36
45
 
37
46
  For example, try to generate the project documentation with:
38
47
 
39
48
  ```bash
40
- $ md2pdf README.md README.pdf
49
+ $ md2pdf -i README.md
41
50
  ```
42
51
 
43
- Optionally, you may load an external style:
52
+ A `README.pdf` should have been generated.
53
+
54
+ Optionally, you may load an external style sheet:
44
55
 
45
56
  ```bash
46
57
  $ md2pdf \
47
58
  --css examples/custom-styles.css \
48
- README.md \
49
- README.pdf
59
+ -i README.md
50
60
  ```
51
61
 
52
62
  And activate [markdown extensions from
@@ -56,8 +66,7 @@ PyMdown](https://facelessuser.github.io/pymdown-extensions/):
56
66
  $ md2pdf \
57
67
  --css examples/custom-styles-with-pygments.css \
58
68
  --extras 'pymdownx.emoji' \
59
- README.md \
60
- README.pdf
69
+ -i README.md
61
70
  ```
62
71
 
63
72
  > Code blocks should be properly rendered when this extension is active.
@@ -108,7 +117,7 @@ Now run your image:
108
117
  $ docker run --rm \
109
118
  -v $PWD:/app \
110
119
  -u "$(id -u):$(id -g)" \
111
- jmaupetit/md2pdf --css styles.css INPUT.MD OUTPUT.PDF
120
+ jmaupetit/md2pdf --css styles.css -i INPUT.MD -o OUTPUT.PDF
112
121
  ```
113
122
 
114
123
  ### Use Jinja templates as input
@@ -145,8 +154,8 @@ You can test this example using:
145
154
  ```bash
146
155
  $ md2pdf \
147
156
  --css examples/gutenberg-modern.min.css \
148
- examples/my-music.md.j2 \
149
- examples/my-music.pdf
157
+ -i examples/my-music.md.j2 \
158
+ -o examples/my-music.pdf
150
159
  ```
151
160
 
152
161
  ## Contributing
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "md2pdf"
3
- version = "2.0.0"
3
+ version = "3.0.0"
4
4
  description = "The Markdown to PDF conversion tool with styles"
5
5
  authors = [
6
6
  {name="Julien Maupetit", email="julien@maupetit.net"},
@@ -26,7 +26,6 @@ classifiers = [
26
26
  "Topic :: Utilities",
27
27
  ]
28
28
  dependencies = [
29
- "click>=8.1",
30
29
  "jinja2>=3",
31
30
  "markdown>=3.5",
32
31
  "pygments>=2.17",
@@ -35,12 +34,23 @@ dependencies = [
35
34
  "weasyprint>=60",
36
35
  ]
37
36
 
37
+ [project.optional-dependencies]
38
+ cli = [
39
+ "typer>=0.21.1",
40
+ ]
41
+ latex = [
42
+ "markdown-katex>=202406.1035",
43
+ ]
44
+
38
45
  [dependency-groups]
39
46
  dev = [
40
47
  "black>=25.12.0",
48
+ "mypy>=1.19.1",
49
+ "pypdf>=6.6.0",
41
50
  "pytest>=9.0.2",
42
51
  "pytest-cov>=7.0.0",
43
52
  "ruff>=0.14.10",
53
+ "types-markdown>=3.10.0.20251106",
44
54
  ]
45
55
 
46
56
  [project.urls]
@@ -56,7 +66,7 @@ build-backend = "hatchling.build"
56
66
 
57
67
  # Third party packages configuration
58
68
  [tool.pytest.ini_options]
59
- addopts = "-vs --cov=md2pdf --cov-report term-missing"
69
+ addopts = "-v --cov=md2pdf --cov-report term-missing"
60
70
  python_files = [
61
71
  "test_*.py",
62
72
  "tests.py",
@@ -96,3 +106,7 @@ convention = "google"
96
106
  "S101",
97
107
  "PLR2004", # Pylint magic-value-comparison
98
108
  ]
109
+
110
+ [tool.mypy]
111
+ files = "./**/*.py"
112
+ ignore_missing_imports = true
@@ -0,0 +1,150 @@
1
+ """md2pdf CLI."""
2
+
3
+ import json
4
+ import logging
5
+ from concurrent.futures import ThreadPoolExecutor
6
+ from importlib.metadata import version as metadata_version
7
+ from pathlib import Path
8
+ from time import time
9
+ from typing import Annotated, Optional
10
+
11
+ import typer
12
+ from rich.console import Console
13
+ from rich.progress import (
14
+ Progress,
15
+ SpinnerColumn,
16
+ TaskID,
17
+ TextColumn,
18
+ TimeElapsedColumn,
19
+ )
20
+
21
+ from .core import md2pdf
22
+ from .exceptions import ValidationError
23
+
24
+ logger = logging.getLogger(__name__)
25
+
26
+ cli = typer.Typer(name="md2pdf", no_args_is_help=True, pretty_exceptions_short=True)
27
+ console = Console()
28
+
29
+
30
+ def parse_config(config: str) -> dict:
31
+ """Parse configuration input as a JSON string."""
32
+ try:
33
+ parsed = json.loads(config)
34
+ except json.decoder.JSONDecodeError as err:
35
+ raise ValidationError(
36
+ "Invalid input configuration string (should be valid JSON)"
37
+ ) from err
38
+ return parsed
39
+
40
+
41
+ @cli.command(no_args_is_help=True)
42
+ def main(
43
+ md: Annotated[
44
+ Optional[list[Path]],
45
+ typer.Option(
46
+ "--input",
47
+ "-i",
48
+ help="Markdown source file path (can be used multiple times).",
49
+ exists=True,
50
+ ),
51
+ ] = None,
52
+ pdf: Annotated[
53
+ Optional[Path],
54
+ typer.Option(
55
+ "--output",
56
+ "-o",
57
+ help="PDF output file path (when a single md input is used).",
58
+ ),
59
+ ] = None,
60
+ css: Annotated[
61
+ Optional[Path], typer.Option("--css", "-c", help="Input CSS file.", exists=True)
62
+ ] = None,
63
+ extras: Annotated[
64
+ Optional[list[str]],
65
+ typer.Option(
66
+ "--extras",
67
+ "-e",
68
+ help="Extra markdown extension to activate (cam be used multiple times).",
69
+ ),
70
+ ] = None,
71
+ config: Annotated[
72
+ Optional[str],
73
+ typer.Option(
74
+ "--config",
75
+ "-C",
76
+ help="Markdown extensions configuration (as a JSON string).",
77
+ ),
78
+ ] = None,
79
+ workers: Annotated[
80
+ int,
81
+ typer.Option("--workers", "-W", help="Number of parallel workers to start."),
82
+ ] = 4,
83
+ version: Annotated[
84
+ bool, typer.Option("--version", "-V", help="Display program version.")
85
+ ] = False,
86
+ ):
87
+ """Markdown to PDF conversion tool with styles… and templates!"""
88
+ if version:
89
+ console.print(f"{metadata_version('md2pdf')}")
90
+ raise typer.Exit()
91
+
92
+ if md is None or not len(md):
93
+ console.print("🤷‍♂️ No markdown input file. See `--help`")
94
+ raise typer.Exit(code=2)
95
+
96
+ if pdf is not None and len(md) > 1:
97
+ console.print(
98
+ "❌ PDF output option `[red]--output/-o[/red]`"
99
+ " cannot be used with multiple input."
100
+ )
101
+ raise typer.Exit(code=2)
102
+
103
+ if css is not None:
104
+ console.print(f"💅 CSS file: [blue]{css}[/blue]")
105
+ css = Path(css)
106
+
107
+ if extras is not None:
108
+ console.print(f"🔧 Extras: [blue]{extras}[/blue]")
109
+
110
+ extras_config = None
111
+ if config is not None:
112
+ extras_config = parse_config(config)
113
+ console.print(f"🔧 Configuration: [blue]{extras_config}[/blue]")
114
+
115
+ progress = Progress(
116
+ SpinnerColumn(finished_text="✅"),
117
+ TextColumn(
118
+ "Converting: [blue]{task.fields[md]}[/blue] "
119
+ "→ [green]{task.fields[pdf]}[/green]"
120
+ ),
121
+ "·",
122
+ TimeElapsedColumn(),
123
+ console=console,
124
+ )
125
+
126
+ def wrapper(task: TaskID, md_: Path, pdf: Path):
127
+ """A wrapper for md2pdf thread execution with task progress update."""
128
+ progress.start_task(task)
129
+ md2pdf(
130
+ pdf,
131
+ md=md_,
132
+ css=css,
133
+ base_url=Path.cwd(),
134
+ extras=extras if extras else None,
135
+ extras_config=extras_config,
136
+ )
137
+ progress.update(task, completed=True)
138
+
139
+ started_at = time()
140
+ with progress:
141
+ with ThreadPoolExecutor(max_workers=workers) as pool:
142
+ for md_ in md:
143
+ if pdf is None:
144
+ pdf = md_.with_suffix(".pdf")
145
+ task = progress.add_task(
146
+ "convert", md=md_, pdf=pdf, total=1, start=False
147
+ )
148
+ pool.submit(wrapper, task, md_, pdf)
149
+
150
+ console.print(f"🚀 Output files generated in [blue]{(time() - started_at):.3f}s[/]")
@@ -22,6 +22,7 @@ def md2pdf(
22
22
  css: Optional[Path] = None,
23
23
  base_url: Optional[Path] = None,
24
24
  extras: Optional[List[str]] = None,
25
+ extras_config: Optional[dict] = None,
25
26
  context: Optional[dict] = None,
26
27
  ):
27
28
  """Converts input markdown to styled HTML and renders it to a PDF file.
@@ -33,6 +34,7 @@ def md2pdf(
33
34
  css: input styles path (CSS).
34
35
  base_url: absolute base path for markdown linked content (as images).
35
36
  extras: supplementary markdown extensions to activate
37
+ extras_config: a configuration dictionnary for active markdown extensions
36
38
  context: input context to use for jinja template rendering
37
39
 
38
40
  Returns:
@@ -42,6 +44,7 @@ def md2pdf(
42
44
  ValidationError: if md_content and md_file_path are empty.
43
45
  """
44
46
  context = context if context else {}
47
+ extras_config = extras_config if extras_config else {}
45
48
 
46
49
  # Merge base extensions with extras extensions
47
50
  extras = extras if extras and len(extras) else []
@@ -68,7 +71,7 @@ def md2pdf(
68
71
  raw = Template(raw).render(context)
69
72
 
70
73
  extensions = MARKDOWN_BASE_EXTENSIONS + extras
71
- raw_html = markdown(raw, extensions=extensions)
74
+ raw_html = markdown(raw, extensions=extensions, extension_configs=extras_config)
72
75
 
73
76
  # Weasyprint HTML object
74
77
  if base_url is None:
@@ -3,5 +3,3 @@
3
3
 
4
4
  class ValidationError(Exception):
5
5
  """md2pdf validation error."""
6
-
7
- ...
@@ -0,0 +1,24 @@
1
+ """Tests configuration."""
2
+
3
+ import pytest
4
+ from typer.testing import CliRunner
5
+
6
+ from .defaults import DEFAULT_OUTPUT_PDF, OUTPUT_PDF
7
+
8
+
9
+ @pytest.fixture(scope="function", autouse=True)
10
+ def remove_generated_pdf():
11
+ """Remove test-generated PDF file."""
12
+ yield
13
+
14
+ # Teardown
15
+ if OUTPUT_PDF.exists():
16
+ OUTPUT_PDF.unlink()
17
+ if DEFAULT_OUTPUT_PDF.exists():
18
+ DEFAULT_OUTPUT_PDF.unlink()
19
+
20
+
21
+ @pytest.fixture
22
+ def cli_runner():
23
+ """CLI runner."""
24
+ yield CliRunner()
@@ -6,3 +6,4 @@ from pathlib import Path
6
6
  INPUT_CSS = Path("tests/assets/input.css")
7
7
  INPUT_MD = Path("tests/assets/input.md")
8
8
  OUTPUT_PDF = Path("tests/assets/output.pdf")
9
+ DEFAULT_OUTPUT_PDF = Path("tests/assets/input.pdf")