markdown-pdf 1.3__tar.gz → 1.3.2__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.3/markdown_pdf.egg-info → markdown_pdf-1.3.2}/PKG-INFO +5 -3
- {markdown_pdf-1.3 → markdown_pdf-1.3.2}/README.md +4 -2
- {markdown_pdf-1.3 → markdown_pdf-1.3.2}/markdown_pdf/__init__.py +15 -6
- {markdown_pdf-1.3 → markdown_pdf-1.3.2/markdown_pdf.egg-info}/PKG-INFO +5 -3
- {markdown_pdf-1.3 → markdown_pdf-1.3.2}/setup.cfg +1 -1
- {markdown_pdf-1.3 → markdown_pdf-1.3.2}/LICENSE +0 -0
- {markdown_pdf-1.3 → markdown_pdf-1.3.2}/MANIFEST.in +0 -0
- {markdown_pdf-1.3 → markdown_pdf-1.3.2}/markdown_pdf.egg-info/SOURCES.txt +0 -0
- {markdown_pdf-1.3 → markdown_pdf-1.3.2}/markdown_pdf.egg-info/dependency_links.txt +0 -0
- {markdown_pdf-1.3 → markdown_pdf-1.3.2}/markdown_pdf.egg-info/requires.txt +0 -0
- {markdown_pdf-1.3 → markdown_pdf-1.3.2}/markdown_pdf.egg-info/top_level.txt +0 -0
- {markdown_pdf-1.3 → markdown_pdf-1.3.2}/pyproject.toml +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: markdown_pdf
|
|
3
|
-
Version: 1.3
|
|
3
|
+
Version: 1.3.2
|
|
4
4
|
Summary: Markdown to pdf renderer
|
|
5
5
|
Home-page: https://github.com/vb64/markdown-pdf
|
|
6
6
|
Author: Vitaly Bogomolov
|
|
@@ -18,7 +18,7 @@ Requires-Dist: markdown-it-py==3.0.0
|
|
|
18
18
|
# Module markdown-pdf
|
|
19
19
|
|
|
20
20
|
[](https://github.com/vb64/markdown-pdf/actions?query=workflow%3Apep257)
|
|
21
|
-
[](https://github.com/vb64/markdown-pdf/actions?query=workflow%3Apy3)
|
|
22
22
|
[](https://app.codacy.com/gh/vb64/markdown-pdf/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
|
|
23
23
|
[](https://app.codacy.com/gh/vb64/markdown-pdf/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_coverage)
|
|
24
24
|
[](https://pypistats.org/packages/markdown-pdf)
|
|
@@ -93,7 +93,9 @@ text = """# Section with Table
|
|
|
93
93
|
|ListCell|<ul><li>FirstBullet</li><li>SecondBullet</li></ul>|
|
|
94
94
|
"""
|
|
95
95
|
|
|
96
|
-
|
|
96
|
+
css = "table, th, td {border: 1px solid black;}"
|
|
97
|
+
|
|
98
|
+
pdf.add_section(Section(text), user_css=css)
|
|
97
99
|
```
|
|
98
100
|
|
|
99
101
|
Set the properties of the pdf document.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Module markdown-pdf
|
|
2
2
|
|
|
3
3
|
[](https://github.com/vb64/markdown-pdf/actions?query=workflow%3Apep257)
|
|
4
|
-
[](https://github.com/vb64/markdown-pdf/actions?query=workflow%3Apy3)
|
|
5
5
|
[](https://app.codacy.com/gh/vb64/markdown-pdf/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
|
|
6
6
|
[](https://app.codacy.com/gh/vb64/markdown-pdf/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_coverage)
|
|
7
7
|
[](https://pypistats.org/packages/markdown-pdf)
|
|
@@ -76,7 +76,9 @@ text = """# Section with Table
|
|
|
76
76
|
|ListCell|<ul><li>FirstBullet</li><li>SecondBullet</li></ul>|
|
|
77
77
|
"""
|
|
78
78
|
|
|
79
|
-
|
|
79
|
+
css = "table, th, td {border: 1px solid black;}"
|
|
80
|
+
|
|
81
|
+
pdf.add_section(Section(text), user_css=css)
|
|
80
82
|
```
|
|
81
83
|
|
|
82
84
|
Set the properties of the pdf document.
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"""Markdown to pdf converter based on markdown_it and fitz."""
|
|
2
2
|
import io
|
|
3
|
+
import typing
|
|
4
|
+
import pathlib
|
|
3
5
|
from markdown_it import MarkdownIt
|
|
4
6
|
import fitz
|
|
5
7
|
|
|
@@ -7,7 +9,14 @@ import fitz
|
|
|
7
9
|
class Section:
|
|
8
10
|
"""Markdown section."""
|
|
9
11
|
|
|
10
|
-
def __init__(
|
|
12
|
+
def __init__(
|
|
13
|
+
self,
|
|
14
|
+
text: str,
|
|
15
|
+
toc: bool = True,
|
|
16
|
+
root: str = ".",
|
|
17
|
+
paper_size: str = "A4",
|
|
18
|
+
borders: tuple = (36, 36, -36, -36)
|
|
19
|
+
):
|
|
11
20
|
"""Create md section with given properties."""
|
|
12
21
|
self.text = text
|
|
13
22
|
self.toc = toc
|
|
@@ -31,7 +40,7 @@ class MarkdownPdf:
|
|
|
31
40
|
"keywords": None,
|
|
32
41
|
}
|
|
33
42
|
|
|
34
|
-
def __init__(self, toc_level=6, mode='commonmark'):
|
|
43
|
+
def __init__(self, toc_level: int = 6, mode: str = 'commonmark'):
|
|
35
44
|
"""Create md -> pdf converter with given TOC level and mode of md parsing."""
|
|
36
45
|
self.toc_level = toc_level
|
|
37
46
|
self.toc = []
|
|
@@ -45,7 +54,7 @@ class MarkdownPdf:
|
|
|
45
54
|
self.page = 0
|
|
46
55
|
|
|
47
56
|
@staticmethod
|
|
48
|
-
def
|
|
57
|
+
def _recorder(elpos):
|
|
49
58
|
"""Call function invoked during story.place() for making a TOC."""
|
|
50
59
|
if not elpos.open_close & 1: # only consider "open" items
|
|
51
60
|
return
|
|
@@ -60,7 +69,7 @@ class MarkdownPdf:
|
|
|
60
69
|
elpos.rect[1], # top of written rectangle (use for TOC)
|
|
61
70
|
))
|
|
62
71
|
|
|
63
|
-
def add_section(self, section, user_css=None):
|
|
72
|
+
def add_section(self, section: Section, user_css: typing.Optional[str] = None) -> None:
|
|
64
73
|
"""Add markdown section to pdf."""
|
|
65
74
|
rect = fitz.paper_rect(section.paper_size)
|
|
66
75
|
where = rect + section.borders
|
|
@@ -70,11 +79,11 @@ class MarkdownPdf:
|
|
|
70
79
|
self.page += 1
|
|
71
80
|
device = self.writer.begin_page(rect)
|
|
72
81
|
more, _ = story.place(where) # layout into allowed rectangle
|
|
73
|
-
story.element_positions(self.
|
|
82
|
+
story.element_positions(self._recorder, {"toc": section.toc, "pdfile": self})
|
|
74
83
|
story.draw(device)
|
|
75
84
|
self.writer.end_page()
|
|
76
85
|
|
|
77
|
-
def save(self, file_name):
|
|
86
|
+
def save(self, file_name: typing.Union[str, pathlib.Path]) -> None:
|
|
78
87
|
"""Save pdf to file."""
|
|
79
88
|
self.writer.close()
|
|
80
89
|
doc = fitz.open("pdf", self.out_file)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: markdown_pdf
|
|
3
|
-
Version: 1.3
|
|
3
|
+
Version: 1.3.2
|
|
4
4
|
Summary: Markdown to pdf renderer
|
|
5
5
|
Home-page: https://github.com/vb64/markdown-pdf
|
|
6
6
|
Author: Vitaly Bogomolov
|
|
@@ -18,7 +18,7 @@ Requires-Dist: markdown-it-py==3.0.0
|
|
|
18
18
|
# Module markdown-pdf
|
|
19
19
|
|
|
20
20
|
[](https://github.com/vb64/markdown-pdf/actions?query=workflow%3Apep257)
|
|
21
|
-
[](https://github.com/vb64/markdown-pdf/actions?query=workflow%3Apy3)
|
|
22
22
|
[](https://app.codacy.com/gh/vb64/markdown-pdf/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
|
|
23
23
|
[](https://app.codacy.com/gh/vb64/markdown-pdf/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_coverage)
|
|
24
24
|
[](https://pypistats.org/packages/markdown-pdf)
|
|
@@ -93,7 +93,9 @@ text = """# Section with Table
|
|
|
93
93
|
|ListCell|<ul><li>FirstBullet</li><li>SecondBullet</li></ul>|
|
|
94
94
|
"""
|
|
95
95
|
|
|
96
|
-
|
|
96
|
+
css = "table, th, td {border: 1px solid black;}"
|
|
97
|
+
|
|
98
|
+
pdf.add_section(Section(text), user_css=css)
|
|
97
99
|
```
|
|
98
100
|
|
|
99
101
|
Set the properties of the pdf document.
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|