markdown-pdf 1.10__tar.gz → 1.12__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.10/markdown_pdf.egg-info → markdown_pdf-1.12}/PKG-INFO +72 -6
- {markdown_pdf-1.10 → markdown_pdf-1.12}/README.md +66 -2
- {markdown_pdf-1.10 → markdown_pdf-1.12}/markdown_pdf/__init__.py +25 -2
- markdown_pdf-1.12/markdown_pdf/pligins/__init__.py +62 -0
- markdown_pdf-1.12/markdown_pdf/pligins/helpers.py +9 -0
- markdown_pdf-1.12/markdown_pdf/pligins/mermaid.py +25 -0
- markdown_pdf-1.12/markdown_pdf/pligins/plantuml.py +15 -0
- {markdown_pdf-1.10 → markdown_pdf-1.12/markdown_pdf.egg-info}/PKG-INFO +72 -6
- {markdown_pdf-1.10 → markdown_pdf-1.12}/markdown_pdf.egg-info/SOURCES.txt +5 -1
- {markdown_pdf-1.10 → markdown_pdf-1.12}/markdown_pdf.egg-info/requires.txt +2 -0
- {markdown_pdf-1.10 → markdown_pdf-1.12}/pyproject.toml +17 -5
- {markdown_pdf-1.10 → markdown_pdf-1.12}/LICENSE +0 -0
- {markdown_pdf-1.10 → markdown_pdf-1.12}/MANIFEST.in +0 -0
- {markdown_pdf-1.10 → markdown_pdf-1.12}/markdown_pdf/py.typed +0 -0
- {markdown_pdf-1.10 → markdown_pdf-1.12}/markdown_pdf.egg-info/dependency_links.txt +0 -0
- {markdown_pdf-1.10 → markdown_pdf-1.12}/markdown_pdf.egg-info/top_level.txt +0 -0
- {markdown_pdf-1.10 → markdown_pdf-1.12}/setup.cfg +0 -0
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: markdown_pdf
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.12
|
|
4
4
|
Summary: Markdown to pdf renderer
|
|
5
5
|
Author-email: Vitaly Bogomolov <mail@vitaly-bogomolov.ru>
|
|
6
|
-
License:
|
|
6
|
+
License-Expression: AGPL-3.0-only
|
|
7
7
|
Project-URL: Homepage, https://github.com/vb64/markdown-pdf
|
|
8
8
|
Project-URL: Bug Tracker, https://github.com/vb64/markdown-pdf/issues
|
|
9
9
|
Classifier: Programming Language :: Python :: 3
|
|
10
|
-
Classifier: License :: OSI Approved :: GNU Affero General Public License v3
|
|
11
10
|
Classifier: Operating System :: OS Independent
|
|
12
11
|
Requires-Python: >=3.8
|
|
13
12
|
Description-Content-Type: text/markdown
|
|
@@ -15,6 +14,8 @@ License-File: LICENSE
|
|
|
15
14
|
Requires-Dist: PyMuPDF==1.24.6; python_version < "3.9"
|
|
16
15
|
Requires-Dist: PyMuPDF>=1.25.3; python_version > "3.8"
|
|
17
16
|
Requires-Dist: markdown-it-py==3.0.0; python_version >= "3.8"
|
|
17
|
+
Requires-Dist: plantuml==0.3.0
|
|
18
|
+
Requires-Dist: six==1.17.0
|
|
18
19
|
Provides-Extra: dev
|
|
19
20
|
Requires-Dist: flake8; extra == "dev"
|
|
20
21
|
Requires-Dist: pylint; extra == "dev"
|
|
@@ -22,16 +23,17 @@ Requires-Dist: pydocstyle; extra == "dev"
|
|
|
22
23
|
Requires-Dist: pytest; extra == "dev"
|
|
23
24
|
Requires-Dist: pytest-cov; extra == "dev"
|
|
24
25
|
Requires-Dist: codacy-coverage; extra == "dev"
|
|
26
|
+
Dynamic: license-file
|
|
25
27
|
|
|
26
28
|
# Module markdown-pdf
|
|
27
29
|
|
|
28
30
|
[](https://github.com/vb64/markdown-pdf/actions?query=workflow%3Apep257)
|
|
29
|
-
[](https://github.com/vb64/markdown-pdf/actions?query=workflow%3Apy3)
|
|
30
32
|
[](https://app.codacy.com/gh/vb64/markdown-pdf/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
|
|
31
33
|
[](https://app.codacy.com/gh/vb64/markdown-pdf/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_coverage)
|
|
32
34
|
[](https://pypistats.org/packages/markdown-pdf)
|
|
33
35
|
|
|
34
|
-
The free, open source Python module `markdown-pdf` will create a PDF file from your
|
|
36
|
+
The free, open source Python module `markdown-pdf` will create a PDF file from your `markdown` content.
|
|
35
37
|
|
|
36
38
|
When creating a PDF file you can:
|
|
37
39
|
|
|
@@ -43,6 +45,7 @@ When creating a PDF file you can:
|
|
|
43
45
|
- Use different page sizes within single pdf
|
|
44
46
|
- Create tables in `markdown`
|
|
45
47
|
- Use clickable hyperlinks. Thanks a lot [@thongtmtrust](https://github.com/thongtmtrust) for ideas and collaboration.
|
|
48
|
+
- Render plantuml and mermaid code to pdf images with [plugins](plugins.md).
|
|
46
49
|
|
|
47
50
|
The module utilizes the functions of two great libraries.
|
|
48
51
|
|
|
@@ -170,6 +173,69 @@ The following document properties are available for assignment (dictionary `Mark
|
|
|
170
173
|
- `subject`: ""
|
|
171
174
|
- `keywords`: ""
|
|
172
175
|
|
|
176
|
+
## Plugins
|
|
177
|
+
|
|
178
|
+
The module allows you to process specially marked sections of code using plugins.
|
|
179
|
+
|
|
180
|
+
For example, you convert the following Markdown text to PDF:
|
|
181
|
+
|
|
182
|
+
````markdown
|
|
183
|
+
# Title plantuml
|
|
184
|
+
|
|
185
|
+
Document with plantuml code.
|
|
186
|
+
|
|
187
|
+
```plantuml
|
|
188
|
+
@startuml
|
|
189
|
+
Alice -> Bob: Hello Bob
|
|
190
|
+
Bob --> Alice: Hi!
|
|
191
|
+
@enduml
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
End of document
|
|
195
|
+
````
|
|
196
|
+
|
|
197
|
+
Without using the plugin, you will get the following result in pdf:
|
|
198
|
+
|
|
199
|
+

|
|
200
|
+
|
|
201
|
+
You can use a plugin to render plantuml code into an image.
|
|
202
|
+
|
|
203
|
+
````python
|
|
204
|
+
from markdown_pdf import MarkdownPdf, Section
|
|
205
|
+
from markdown_pdf.pligins import Plugin
|
|
206
|
+
|
|
207
|
+
plantuml_text = """# Title plantuml
|
|
208
|
+
|
|
209
|
+
Document with plantuml code.
|
|
210
|
+
|
|
211
|
+
```plantuml
|
|
212
|
+
@startuml
|
|
213
|
+
Alice -> Bob: Hello Bob
|
|
214
|
+
Bob --> Alice: Hi!
|
|
215
|
+
@enduml
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
End of document
|
|
219
|
+
"""
|
|
220
|
+
|
|
221
|
+
plugins = {
|
|
222
|
+
Plugin.Plantuml: {'url': 'http://www.plantuml.com/plantuml/img/'}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
pdf = MarkdownPdf(plugins=plugins)
|
|
226
|
+
pdf.add_section(Section(plantuml_text))
|
|
227
|
+
pdf.save("plantuml.pdf")
|
|
228
|
+
````
|
|
229
|
+
|
|
230
|
+
In this case, the plugin will send the code marked as `plantuml` to the specified internet server
|
|
231
|
+
and replace the code text with an image generated by the server `www.plantuml.com`.
|
|
232
|
+
|
|
233
|
+
In the created file `plantuml.pdf`, you will see the following result:
|
|
234
|
+
|
|
235
|
+

|
|
236
|
+
|
|
237
|
+
You can find a more detailed description of the plugins [here](plugins.md).
|
|
238
|
+
|
|
173
239
|
## Example
|
|
174
240
|
|
|
175
241
|
As an example, you can download the [pdf file](examples/markdown_pdf.pdf) created from this md file.
|
|
@@ -1,12 +1,12 @@
|
|
|
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)
|
|
8
8
|
|
|
9
|
-
The free, open source Python module `markdown-pdf` will create a PDF file from your
|
|
9
|
+
The free, open source Python module `markdown-pdf` will create a PDF file from your `markdown` content.
|
|
10
10
|
|
|
11
11
|
When creating a PDF file you can:
|
|
12
12
|
|
|
@@ -18,6 +18,7 @@ When creating a PDF file you can:
|
|
|
18
18
|
- Use different page sizes within single pdf
|
|
19
19
|
- Create tables in `markdown`
|
|
20
20
|
- Use clickable hyperlinks. Thanks a lot [@thongtmtrust](https://github.com/thongtmtrust) for ideas and collaboration.
|
|
21
|
+
- Render plantuml and mermaid code to pdf images with [plugins](plugins.md).
|
|
21
22
|
|
|
22
23
|
The module utilizes the functions of two great libraries.
|
|
23
24
|
|
|
@@ -145,6 +146,69 @@ The following document properties are available for assignment (dictionary `Mark
|
|
|
145
146
|
- `subject`: ""
|
|
146
147
|
- `keywords`: ""
|
|
147
148
|
|
|
149
|
+
## Plugins
|
|
150
|
+
|
|
151
|
+
The module allows you to process specially marked sections of code using plugins.
|
|
152
|
+
|
|
153
|
+
For example, you convert the following Markdown text to PDF:
|
|
154
|
+
|
|
155
|
+
````markdown
|
|
156
|
+
# Title plantuml
|
|
157
|
+
|
|
158
|
+
Document with plantuml code.
|
|
159
|
+
|
|
160
|
+
```plantuml
|
|
161
|
+
@startuml
|
|
162
|
+
Alice -> Bob: Hello Bob
|
|
163
|
+
Bob --> Alice: Hi!
|
|
164
|
+
@enduml
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
End of document
|
|
168
|
+
````
|
|
169
|
+
|
|
170
|
+
Without using the plugin, you will get the following result in pdf:
|
|
171
|
+
|
|
172
|
+

|
|
173
|
+
|
|
174
|
+
You can use a plugin to render plantuml code into an image.
|
|
175
|
+
|
|
176
|
+
````python
|
|
177
|
+
from markdown_pdf import MarkdownPdf, Section
|
|
178
|
+
from markdown_pdf.pligins import Plugin
|
|
179
|
+
|
|
180
|
+
plantuml_text = """# Title plantuml
|
|
181
|
+
|
|
182
|
+
Document with plantuml code.
|
|
183
|
+
|
|
184
|
+
```plantuml
|
|
185
|
+
@startuml
|
|
186
|
+
Alice -> Bob: Hello Bob
|
|
187
|
+
Bob --> Alice: Hi!
|
|
188
|
+
@enduml
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
End of document
|
|
192
|
+
"""
|
|
193
|
+
|
|
194
|
+
plugins = {
|
|
195
|
+
Plugin.Plantuml: {'url': 'http://www.plantuml.com/plantuml/img/'}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
pdf = MarkdownPdf(plugins=plugins)
|
|
199
|
+
pdf.add_section(Section(plantuml_text))
|
|
200
|
+
pdf.save("plantuml.pdf")
|
|
201
|
+
````
|
|
202
|
+
|
|
203
|
+
In this case, the plugin will send the code marked as `plantuml` to the specified internet server
|
|
204
|
+
and replace the code text with an image generated by the server `www.plantuml.com`.
|
|
205
|
+
|
|
206
|
+
In the created file `plantuml.pdf`, you will see the following result:
|
|
207
|
+
|
|
208
|
+

|
|
209
|
+
|
|
210
|
+
You can find a more detailed description of the plugins [here](plugins.md).
|
|
211
|
+
|
|
148
212
|
## Example
|
|
149
213
|
|
|
150
214
|
As an example, you can download the [pdf file](examples/markdown_pdf.pdf) created from this md file.
|
|
@@ -8,6 +8,7 @@ from markdown_it import MarkdownIt
|
|
|
8
8
|
from pymupdf import (
|
|
9
9
|
_as_pdf_document, mupdf, JM_embedded_clean, JM_ensure_identity, JM_new_output_fileptr, ASSERT_PDF, Rect,
|
|
10
10
|
)
|
|
11
|
+
from .pligins import PLUGINS, get_plugin_chunks, TempFiles
|
|
11
12
|
|
|
12
13
|
MM_2_PT = 2.835
|
|
13
14
|
|
|
@@ -56,10 +57,18 @@ class MarkdownPdf:
|
|
|
56
57
|
"keywords": None,
|
|
57
58
|
}
|
|
58
59
|
|
|
59
|
-
def __init__(
|
|
60
|
+
def __init__(
|
|
61
|
+
self,
|
|
62
|
+
toc_level: int = 6,
|
|
63
|
+
mode: str = 'commonmark',
|
|
64
|
+
optimize: bool = False,
|
|
65
|
+
plugins: typing.Optional[dict] = None
|
|
66
|
+
):
|
|
60
67
|
"""Create md -> pdf converter with given TOC level and mode of md parsing."""
|
|
61
68
|
self.toc_level = toc_level
|
|
62
69
|
self.toc = []
|
|
70
|
+
self.plugins = plugins or {}
|
|
71
|
+
self.temp_files = TempFiles()
|
|
63
72
|
|
|
64
73
|
# zero, commonmark, js-default, gfm-like
|
|
65
74
|
# https://markdown-it-py.readthedocs.io/en/latest/using.html#quick-start
|
|
@@ -91,10 +100,22 @@ class MarkdownPdf:
|
|
|
91
100
|
elpos.rect[1], # top of written rectangle (use for TOC)
|
|
92
101
|
))
|
|
93
102
|
|
|
103
|
+
def apply_plugins(self, text):
|
|
104
|
+
"""Return modified text according plugins settings."""
|
|
105
|
+
if not self.plugins:
|
|
106
|
+
return text
|
|
107
|
+
|
|
108
|
+
text = '\n'.join(text.splitlines())
|
|
109
|
+
for key, val in self.plugins.items():
|
|
110
|
+
for chunk in get_plugin_chunks(key, text):
|
|
111
|
+
text = text.replace(chunk, PLUGINS[key](val, chunk, self.temp_files))
|
|
112
|
+
|
|
113
|
+
return text
|
|
114
|
+
|
|
94
115
|
def add_section(self, section: Section, user_css: typing.Optional[str] = None) -> str:
|
|
95
116
|
"""Add markdown section to pdf."""
|
|
96
117
|
where = section.rect + section.borders
|
|
97
|
-
html = self.m_d.render(section.text)
|
|
118
|
+
html = self.m_d.render(self.apply_plugins(section.text))
|
|
98
119
|
story = fitz.Story(html=html, archive=section.root, user_css=user_css)
|
|
99
120
|
more = 1
|
|
100
121
|
while more: # loop outputting the story
|
|
@@ -126,6 +147,7 @@ class MarkdownPdf:
|
|
|
126
147
|
else:
|
|
127
148
|
doc.save(file_name)
|
|
128
149
|
doc.close()
|
|
150
|
+
self.temp_files.clean()
|
|
129
151
|
|
|
130
152
|
def save_bytes(self, bytesio: io.BytesIO) -> int:
|
|
131
153
|
"""Save pdf to file-like object and return byte size of the filled object."""
|
|
@@ -161,5 +183,6 @@ class MarkdownPdf:
|
|
|
161
183
|
out = JM_new_output_fileptr(bytesio)
|
|
162
184
|
mupdf.pdf_write_document(pdf, out, opts)
|
|
163
185
|
out.fz_close_output()
|
|
186
|
+
self.temp_files.clean()
|
|
164
187
|
|
|
165
188
|
return bytesio.getbuffer().nbytes
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"""Plugins."""
|
|
2
|
+
import os
|
|
3
|
+
import uuid
|
|
4
|
+
|
|
5
|
+
from .plantuml import handler as plantuml_handler
|
|
6
|
+
from .mermaid import handler as mermaid_handler
|
|
7
|
+
|
|
8
|
+
PLUGINS = {}
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class Plugin:
|
|
12
|
+
"""Available plugins."""
|
|
13
|
+
|
|
14
|
+
Plantuml = "plantuml"
|
|
15
|
+
Mermaid = "mermaid"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class TempFiles:
|
|
19
|
+
"""Temp files for plugins."""
|
|
20
|
+
|
|
21
|
+
def __init__(self):
|
|
22
|
+
"""Init empty list."""
|
|
23
|
+
self.name_list = []
|
|
24
|
+
|
|
25
|
+
def new_name(self, ext=None):
|
|
26
|
+
"""Return file name with given extension."""
|
|
27
|
+
self.name_list.append(str(uuid.uuid4()) + ".{}".format(ext) if ext else '')
|
|
28
|
+
return self.name_list[-1]
|
|
29
|
+
|
|
30
|
+
def clean(self):
|
|
31
|
+
"""Remove temp files."""
|
|
32
|
+
for i in self.name_list:
|
|
33
|
+
if os.path.exists(i):
|
|
34
|
+
os.remove(i)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def register(key, handler):
|
|
38
|
+
"""Register plugin as available."""
|
|
39
|
+
PLUGINS[key] = handler
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def get_plugin_chunks(key, text):
|
|
43
|
+
"""Extract key parts from given text."""
|
|
44
|
+
chunk = []
|
|
45
|
+
chunks = []
|
|
46
|
+
|
|
47
|
+
for line in text.splitlines():
|
|
48
|
+
|
|
49
|
+
if line.startswith("```{}".format(key)):
|
|
50
|
+
chunk = [line]
|
|
51
|
+
elif (line.startswith("```")) and chunk:
|
|
52
|
+
chunk.append(line)
|
|
53
|
+
chunks.append('\n'.join(chunk))
|
|
54
|
+
chunk = []
|
|
55
|
+
elif chunk:
|
|
56
|
+
chunk.append(line)
|
|
57
|
+
|
|
58
|
+
return chunks
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
register(Plugin.Plantuml, plantuml_handler)
|
|
62
|
+
register(Plugin.Mermaid, mermaid_handler)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"""Mermaid plugin."""
|
|
2
|
+
import base64
|
|
3
|
+
import requests
|
|
4
|
+
|
|
5
|
+
from .helpers import get_key
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def handler(params_dict, text, temp_files):
|
|
9
|
+
"""Translate mermaid marked text to png image."""
|
|
10
|
+
url = get_key(params_dict, 'url', 'https://mermaid.ink/img/')
|
|
11
|
+
code = '\n'.join(text.splitlines()[1:-1])
|
|
12
|
+
response = requests.get(
|
|
13
|
+
"{}{}".format(
|
|
14
|
+
url,
|
|
15
|
+
base64.urlsafe_b64encode(code.encode("utf-8")).decode("ascii"),
|
|
16
|
+
),
|
|
17
|
+
params={"format": "png"},
|
|
18
|
+
timeout=5
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
file_name = temp_files.new_name(ext="png")
|
|
22
|
+
with open(file_name, mode='wb') as out:
|
|
23
|
+
out.write(response.content)
|
|
24
|
+
|
|
25
|
+
return "\n\n".format(file_name)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"""Plantunl plugin."""
|
|
2
|
+
from plantuml import PlantUML
|
|
3
|
+
from .helpers import get_key
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def handler(params_dict, text, temp_files):
|
|
7
|
+
"""Translate plantunl marked text to png image."""
|
|
8
|
+
url = get_key(params_dict, 'url', 'http://www.plantuml.com/plantuml/img/')
|
|
9
|
+
image = PlantUML(url=url).processes('\n'.join(text.splitlines()[1:-1]))
|
|
10
|
+
file_name = temp_files.new_name("png")
|
|
11
|
+
|
|
12
|
+
with open(file_name, mode='wb') as out:
|
|
13
|
+
out.write(image)
|
|
14
|
+
|
|
15
|
+
return "\n\n".format(file_name)
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: markdown_pdf
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.12
|
|
4
4
|
Summary: Markdown to pdf renderer
|
|
5
5
|
Author-email: Vitaly Bogomolov <mail@vitaly-bogomolov.ru>
|
|
6
|
-
License:
|
|
6
|
+
License-Expression: AGPL-3.0-only
|
|
7
7
|
Project-URL: Homepage, https://github.com/vb64/markdown-pdf
|
|
8
8
|
Project-URL: Bug Tracker, https://github.com/vb64/markdown-pdf/issues
|
|
9
9
|
Classifier: Programming Language :: Python :: 3
|
|
10
|
-
Classifier: License :: OSI Approved :: GNU Affero General Public License v3
|
|
11
10
|
Classifier: Operating System :: OS Independent
|
|
12
11
|
Requires-Python: >=3.8
|
|
13
12
|
Description-Content-Type: text/markdown
|
|
@@ -15,6 +14,8 @@ License-File: LICENSE
|
|
|
15
14
|
Requires-Dist: PyMuPDF==1.24.6; python_version < "3.9"
|
|
16
15
|
Requires-Dist: PyMuPDF>=1.25.3; python_version > "3.8"
|
|
17
16
|
Requires-Dist: markdown-it-py==3.0.0; python_version >= "3.8"
|
|
17
|
+
Requires-Dist: plantuml==0.3.0
|
|
18
|
+
Requires-Dist: six==1.17.0
|
|
18
19
|
Provides-Extra: dev
|
|
19
20
|
Requires-Dist: flake8; extra == "dev"
|
|
20
21
|
Requires-Dist: pylint; extra == "dev"
|
|
@@ -22,16 +23,17 @@ Requires-Dist: pydocstyle; extra == "dev"
|
|
|
22
23
|
Requires-Dist: pytest; extra == "dev"
|
|
23
24
|
Requires-Dist: pytest-cov; extra == "dev"
|
|
24
25
|
Requires-Dist: codacy-coverage; extra == "dev"
|
|
26
|
+
Dynamic: license-file
|
|
25
27
|
|
|
26
28
|
# Module markdown-pdf
|
|
27
29
|
|
|
28
30
|
[](https://github.com/vb64/markdown-pdf/actions?query=workflow%3Apep257)
|
|
29
|
-
[](https://github.com/vb64/markdown-pdf/actions?query=workflow%3Apy3)
|
|
30
32
|
[](https://app.codacy.com/gh/vb64/markdown-pdf/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
|
|
31
33
|
[](https://app.codacy.com/gh/vb64/markdown-pdf/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_coverage)
|
|
32
34
|
[](https://pypistats.org/packages/markdown-pdf)
|
|
33
35
|
|
|
34
|
-
The free, open source Python module `markdown-pdf` will create a PDF file from your
|
|
36
|
+
The free, open source Python module `markdown-pdf` will create a PDF file from your `markdown` content.
|
|
35
37
|
|
|
36
38
|
When creating a PDF file you can:
|
|
37
39
|
|
|
@@ -43,6 +45,7 @@ When creating a PDF file you can:
|
|
|
43
45
|
- Use different page sizes within single pdf
|
|
44
46
|
- Create tables in `markdown`
|
|
45
47
|
- Use clickable hyperlinks. Thanks a lot [@thongtmtrust](https://github.com/thongtmtrust) for ideas and collaboration.
|
|
48
|
+
- Render plantuml and mermaid code to pdf images with [plugins](plugins.md).
|
|
46
49
|
|
|
47
50
|
The module utilizes the functions of two great libraries.
|
|
48
51
|
|
|
@@ -170,6 +173,69 @@ The following document properties are available for assignment (dictionary `Mark
|
|
|
170
173
|
- `subject`: ""
|
|
171
174
|
- `keywords`: ""
|
|
172
175
|
|
|
176
|
+
## Plugins
|
|
177
|
+
|
|
178
|
+
The module allows you to process specially marked sections of code using plugins.
|
|
179
|
+
|
|
180
|
+
For example, you convert the following Markdown text to PDF:
|
|
181
|
+
|
|
182
|
+
````markdown
|
|
183
|
+
# Title plantuml
|
|
184
|
+
|
|
185
|
+
Document with plantuml code.
|
|
186
|
+
|
|
187
|
+
```plantuml
|
|
188
|
+
@startuml
|
|
189
|
+
Alice -> Bob: Hello Bob
|
|
190
|
+
Bob --> Alice: Hi!
|
|
191
|
+
@enduml
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
End of document
|
|
195
|
+
````
|
|
196
|
+
|
|
197
|
+
Without using the plugin, you will get the following result in pdf:
|
|
198
|
+
|
|
199
|
+

|
|
200
|
+
|
|
201
|
+
You can use a plugin to render plantuml code into an image.
|
|
202
|
+
|
|
203
|
+
````python
|
|
204
|
+
from markdown_pdf import MarkdownPdf, Section
|
|
205
|
+
from markdown_pdf.pligins import Plugin
|
|
206
|
+
|
|
207
|
+
plantuml_text = """# Title plantuml
|
|
208
|
+
|
|
209
|
+
Document with plantuml code.
|
|
210
|
+
|
|
211
|
+
```plantuml
|
|
212
|
+
@startuml
|
|
213
|
+
Alice -> Bob: Hello Bob
|
|
214
|
+
Bob --> Alice: Hi!
|
|
215
|
+
@enduml
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
End of document
|
|
219
|
+
"""
|
|
220
|
+
|
|
221
|
+
plugins = {
|
|
222
|
+
Plugin.Plantuml: {'url': 'http://www.plantuml.com/plantuml/img/'}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
pdf = MarkdownPdf(plugins=plugins)
|
|
226
|
+
pdf.add_section(Section(plantuml_text))
|
|
227
|
+
pdf.save("plantuml.pdf")
|
|
228
|
+
````
|
|
229
|
+
|
|
230
|
+
In this case, the plugin will send the code marked as `plantuml` to the specified internet server
|
|
231
|
+
and replace the code text with an image generated by the server `www.plantuml.com`.
|
|
232
|
+
|
|
233
|
+
In the created file `plantuml.pdf`, you will see the following result:
|
|
234
|
+
|
|
235
|
+

|
|
236
|
+
|
|
237
|
+
You can find a more detailed description of the plugins [here](plugins.md).
|
|
238
|
+
|
|
173
239
|
## Example
|
|
174
240
|
|
|
175
241
|
As an example, you can download the [pdf file](examples/markdown_pdf.pdf) created from this md file.
|
|
@@ -8,4 +8,8 @@ markdown_pdf.egg-info/PKG-INFO
|
|
|
8
8
|
markdown_pdf.egg-info/SOURCES.txt
|
|
9
9
|
markdown_pdf.egg-info/dependency_links.txt
|
|
10
10
|
markdown_pdf.egg-info/requires.txt
|
|
11
|
-
markdown_pdf.egg-info/top_level.txt
|
|
11
|
+
markdown_pdf.egg-info/top_level.txt
|
|
12
|
+
markdown_pdf/pligins/__init__.py
|
|
13
|
+
markdown_pdf/pligins/helpers.py
|
|
14
|
+
markdown_pdf/pligins/mermaid.py
|
|
15
|
+
markdown_pdf/pligins/plantuml.py
|
|
@@ -7,23 +7,24 @@ build-backend = "setuptools.build_meta"
|
|
|
7
7
|
|
|
8
8
|
[project]
|
|
9
9
|
name = "markdown_pdf"
|
|
10
|
-
version = "1.
|
|
10
|
+
version = "1.12"
|
|
11
11
|
description = "Markdown to pdf renderer"
|
|
12
12
|
readme = { file = "README.md", content-type = "text/markdown" }
|
|
13
13
|
requires-python = ">=3.8"
|
|
14
|
-
license =
|
|
14
|
+
license = "AGPL-3.0-only"
|
|
15
15
|
authors = [
|
|
16
16
|
{ name = "Vitaly Bogomolov", email = "mail@vitaly-bogomolov.ru" }
|
|
17
17
|
]
|
|
18
18
|
classifiers = [
|
|
19
19
|
"Programming Language :: Python :: 3",
|
|
20
|
-
"License :: OSI Approved :: GNU Affero General Public License v3",
|
|
21
20
|
"Operating System :: OS Independent"
|
|
22
21
|
]
|
|
23
22
|
dependencies = [
|
|
24
23
|
"PyMuPDF==1.24.6; python_version<'3.9'",
|
|
25
24
|
"PyMuPDF>=1.25.3; python_version>'3.8'",
|
|
26
|
-
"markdown-it-py==3.0.0; python_version>='3.8'"
|
|
25
|
+
"markdown-it-py==3.0.0; python_version>='3.8'",
|
|
26
|
+
"plantuml==0.3.0",
|
|
27
|
+
"six==1.17.0"
|
|
27
28
|
]
|
|
28
29
|
|
|
29
30
|
[project.optional-dependencies]
|
|
@@ -41,7 +42,18 @@ dev = [
|
|
|
41
42
|
"Bug Tracker" = "https://github.com/vb64/markdown-pdf/issues"
|
|
42
43
|
|
|
43
44
|
[tool.setuptools]
|
|
44
|
-
packages = ["markdown_pdf"]
|
|
45
|
+
packages = ["markdown_pdf", "markdown_pdf.pligins"]
|
|
45
46
|
|
|
46
47
|
[tool.setuptools.package-data]
|
|
47
48
|
"markdown_pdf" = ["py.typed"]
|
|
49
|
+
|
|
50
|
+
[tool.pytest.ini_options]
|
|
51
|
+
filterwarnings = [
|
|
52
|
+
# note the use of single quote below to denote "raw" strings in TOML
|
|
53
|
+
'ignore:builtin type swigvarlink has no __module__ attribute:DeprecationWarning',
|
|
54
|
+
'ignore:builtin type SwigPyObject has no __module__ attribute:DeprecationWarning',
|
|
55
|
+
'ignore:builtin type SwigPyPacked has no __module__ attribute:DeprecationWarning',
|
|
56
|
+
]
|
|
57
|
+
markers = [
|
|
58
|
+
'external: marks a test as uses external resources'
|
|
59
|
+
]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|