markdown-pdf 1.9__tar.gz → 1.10__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.
- {markdown_pdf-1.9/markdown_pdf.egg-info → markdown_pdf-1.10}/PKG-INFO +2 -2
- {markdown_pdf-1.9 → markdown_pdf-1.10}/README.md +1 -1
- {markdown_pdf-1.9 → markdown_pdf-1.10}/markdown_pdf/__init__.py +17 -6
- {markdown_pdf-1.9 → markdown_pdf-1.10/markdown_pdf.egg-info}/PKG-INFO +2 -2
- {markdown_pdf-1.9 → markdown_pdf-1.10}/pyproject.toml +1 -1
- {markdown_pdf-1.9 → markdown_pdf-1.10}/LICENSE +0 -0
- {markdown_pdf-1.9 → markdown_pdf-1.10}/MANIFEST.in +0 -0
- {markdown_pdf-1.9 → markdown_pdf-1.10}/markdown_pdf/py.typed +0 -0
- {markdown_pdf-1.9 → markdown_pdf-1.10}/markdown_pdf.egg-info/SOURCES.txt +0 -0
- {markdown_pdf-1.9 → markdown_pdf-1.10}/markdown_pdf.egg-info/dependency_links.txt +0 -0
- {markdown_pdf-1.9 → markdown_pdf-1.10}/markdown_pdf.egg-info/requires.txt +0 -0
- {markdown_pdf-1.9 → markdown_pdf-1.10}/markdown_pdf.egg-info/top_level.txt +0 -0
- {markdown_pdf-1.9 → markdown_pdf-1.10}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: markdown_pdf
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.10
|
|
4
4
|
Summary: Markdown to pdf renderer
|
|
5
5
|
Author-email: Vitaly Bogomolov <mail@vitaly-bogomolov.ru>
|
|
6
6
|
License: GNU Affero General Public License v3
|
|
@@ -156,7 +156,7 @@ The `Section` class can set the following attributes.
|
|
|
156
156
|
|
|
157
157
|
- toc: whether to include the headers `<h1>` - `<h6>` of this section in the TOC. Default is True.
|
|
158
158
|
- root: the name of the root directory from which the image file paths starts in markdown. Default ".".
|
|
159
|
-
- paper_size: name of paper size, [as described here](https://pymupdf.readthedocs.io/en/latest/functions.html#paper_size). Default "A4".
|
|
159
|
+
- paper_size: either the name of a paper size, [as described here](https://pymupdf.readthedocs.io/en/latest/functions.html#paper_size), or a list/tuple containing the width and height in mm. Default "A4".
|
|
160
160
|
- borders: size of borders. Default (36, 36, -36, -36).
|
|
161
161
|
|
|
162
162
|
The following document properties are available for assignment (dictionary `MarkdownPdf.meta`) with the default values indicated.
|
|
@@ -131,7 +131,7 @@ The `Section` class can set the following attributes.
|
|
|
131
131
|
|
|
132
132
|
- toc: whether to include the headers `<h1>` - `<h6>` of this section in the TOC. Default is True.
|
|
133
133
|
- root: the name of the root directory from which the image file paths starts in markdown. Default ".".
|
|
134
|
-
- paper_size: name of paper size, [as described here](https://pymupdf.readthedocs.io/en/latest/functions.html#paper_size). Default "A4".
|
|
134
|
+
- paper_size: either the name of a paper size, [as described here](https://pymupdf.readthedocs.io/en/latest/functions.html#paper_size), or a list/tuple containing the width and height in mm. Default "A4".
|
|
135
135
|
- borders: size of borders. Default (36, 36, -36, -36).
|
|
136
136
|
|
|
137
137
|
The following document properties are available for assignment (dictionary `MarkdownPdf.meta`) with the default values indicated.
|
|
@@ -6,9 +6,11 @@ import pathlib
|
|
|
6
6
|
import fitz
|
|
7
7
|
from markdown_it import MarkdownIt
|
|
8
8
|
from pymupdf import (
|
|
9
|
-
_as_pdf_document, mupdf, JM_embedded_clean, JM_ensure_identity, JM_new_output_fileptr, ASSERT_PDF,
|
|
9
|
+
_as_pdf_document, mupdf, JM_embedded_clean, JM_ensure_identity, JM_new_output_fileptr, ASSERT_PDF, Rect,
|
|
10
10
|
)
|
|
11
11
|
|
|
12
|
+
MM_2_PT = 2.835
|
|
13
|
+
|
|
12
14
|
|
|
13
15
|
class Section:
|
|
14
16
|
"""Markdown section."""
|
|
@@ -18,15 +20,25 @@ class Section:
|
|
|
18
20
|
text: str,
|
|
19
21
|
toc: bool = True,
|
|
20
22
|
root: str = ".",
|
|
21
|
-
paper_size: str = "A4",
|
|
23
|
+
paper_size: str or list or tuple = "A4",
|
|
22
24
|
borders: typing.Tuple[int, int, int, int] = (36, 36, -36, -36)
|
|
23
25
|
):
|
|
24
26
|
"""Create md section with given properties."""
|
|
25
27
|
self.text = text
|
|
26
28
|
self.toc = toc
|
|
27
29
|
self.root = root
|
|
28
|
-
|
|
30
|
+
|
|
29
31
|
self.paper_size = paper_size
|
|
32
|
+
if isinstance(paper_size, str):
|
|
33
|
+
# https://pymupdf.readthedocs.io/en/latest/functions.html#paper_size
|
|
34
|
+
self.rect = fitz.paper_rect(paper_size)
|
|
35
|
+
elif isinstance(paper_size, (list, tuple)):
|
|
36
|
+
# Other paper sizes are in pt, so need to times mm by 2.835.
|
|
37
|
+
width, height = paper_size
|
|
38
|
+
self.rect = Rect(0.0, 0.0, (width * MM_2_PT), (height * MM_2_PT))
|
|
39
|
+
else:
|
|
40
|
+
raise TypeError("paper_size must be 'str', 'tuple' or 'list'")
|
|
41
|
+
|
|
30
42
|
self.borders = borders
|
|
31
43
|
|
|
32
44
|
|
|
@@ -81,14 +93,13 @@ class MarkdownPdf:
|
|
|
81
93
|
|
|
82
94
|
def add_section(self, section: Section, user_css: typing.Optional[str] = None) -> str:
|
|
83
95
|
"""Add markdown section to pdf."""
|
|
84
|
-
|
|
85
|
-
where = rect + section.borders
|
|
96
|
+
where = section.rect + section.borders
|
|
86
97
|
html = self.m_d.render(section.text)
|
|
87
98
|
story = fitz.Story(html=html, archive=section.root, user_css=user_css)
|
|
88
99
|
more = 1
|
|
89
100
|
while more: # loop outputting the story
|
|
90
101
|
self.page_num += 1
|
|
91
|
-
device = self.writer.begin_page(rect)
|
|
102
|
+
device = self.writer.begin_page(section.rect)
|
|
92
103
|
more, _ = story.place(where) # layout into allowed rectangle
|
|
93
104
|
story.element_positions(self._recorder, {"toc": section.toc, "pdfile": self})
|
|
94
105
|
story.draw(device)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: markdown_pdf
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.10
|
|
4
4
|
Summary: Markdown to pdf renderer
|
|
5
5
|
Author-email: Vitaly Bogomolov <mail@vitaly-bogomolov.ru>
|
|
6
6
|
License: GNU Affero General Public License v3
|
|
@@ -156,7 +156,7 @@ The `Section` class can set the following attributes.
|
|
|
156
156
|
|
|
157
157
|
- toc: whether to include the headers `<h1>` - `<h6>` of this section in the TOC. Default is True.
|
|
158
158
|
- root: the name of the root directory from which the image file paths starts in markdown. Default ".".
|
|
159
|
-
- paper_size: name of paper size, [as described here](https://pymupdf.readthedocs.io/en/latest/functions.html#paper_size). Default "A4".
|
|
159
|
+
- paper_size: either the name of a paper size, [as described here](https://pymupdf.readthedocs.io/en/latest/functions.html#paper_size), or a list/tuple containing the width and height in mm. Default "A4".
|
|
160
160
|
- borders: size of borders. Default (36, 36, -36, -36).
|
|
161
161
|
|
|
162
162
|
The following document properties are available for assignment (dictionary `MarkdownPdf.meta`) with the default values indicated.
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|