markdown-pdf 1.9__tar.gz → 1.11__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.
@@ -1,13 +1,12 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: markdown_pdf
3
- Version: 1.9
3
+ Version: 1.11
4
4
  Summary: Markdown to pdf renderer
5
5
  Author-email: Vitaly Bogomolov <mail@vitaly-bogomolov.ru>
6
- License: GNU Affero General Public License v3
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,11 +23,12 @@ 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
  [![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/vb64/markdown-pdf/pep257.yml?label=Pep257&style=plastic&branch=main)](https://github.com/vb64/markdown-pdf/actions?query=workflow%3Apep257)
29
- [![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/vb64/markdown-pdf/py3.yml?label=Python%203.8-3.13&style=plastic&branch=main)](https://github.com/vb64/markdown-pdf/actions?query=workflow%3Apy3)
31
+ [![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/vb64/markdown-pdf/py3.yml?label=Python%203.8-3.14&style=plastic&branch=main)](https://github.com/vb64/markdown-pdf/actions?query=workflow%3Apy3)
30
32
  [![Codacy Badge](https://app.codacy.com/project/badge/Grade/27b53043bff34f07bfb79ee1672b7ba0)](https://app.codacy.com/gh/vb64/markdown-pdf/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
31
33
  [![Codacy Badge](https://app.codacy.com/project/badge/Coverage/27b53043bff34f07bfb79ee1672b7ba0)](https://app.codacy.com/gh/vb64/markdown-pdf/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_coverage)
32
34
  [![PyPI - Downloads](https://img.shields.io/pypi/dm/markdown-pdf?label=pypi%20installs)](https://pypistats.org/packages/markdown-pdf)
@@ -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
+ - Use the plantuml content plugin
46
49
 
47
50
  The module utilizes the functions of two great libraries.
48
51
 
@@ -156,7 +159,7 @@ The `Section` class can set the following attributes.
156
159
 
157
160
  - toc: whether to include the headers `<h1>` - `<h6>` of this section in the TOC. Default is True.
158
161
  - 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".
162
+ - 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
163
  - borders: size of borders. Default (36, 36, -36, -36).
161
164
 
162
165
  The following document properties are available for assignment (dictionary `MarkdownPdf.meta`) with the default values indicated.
@@ -170,6 +173,67 @@ 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
+ ![Without plantuml.jpg](img/without_plantuml.jpg)
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
+ ![With plantuml.jpg](img/with_plantuml.jpg)
236
+
173
237
  ## Example
174
238
 
175
239
  As an example, you can download the [pdf file](examples/markdown_pdf.pdf) created from this md file.
@@ -1,7 +1,7 @@
1
1
  # Module markdown-pdf
2
2
 
3
3
  [![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/vb64/markdown-pdf/pep257.yml?label=Pep257&style=plastic&branch=main)](https://github.com/vb64/markdown-pdf/actions?query=workflow%3Apep257)
4
- [![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/vb64/markdown-pdf/py3.yml?label=Python%203.8-3.13&style=plastic&branch=main)](https://github.com/vb64/markdown-pdf/actions?query=workflow%3Apy3)
4
+ [![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/vb64/markdown-pdf/py3.yml?label=Python%203.8-3.14&style=plastic&branch=main)](https://github.com/vb64/markdown-pdf/actions?query=workflow%3Apy3)
5
5
  [![Codacy Badge](https://app.codacy.com/project/badge/Grade/27b53043bff34f07bfb79ee1672b7ba0)](https://app.codacy.com/gh/vb64/markdown-pdf/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
6
6
  [![Codacy Badge](https://app.codacy.com/project/badge/Coverage/27b53043bff34f07bfb79ee1672b7ba0)](https://app.codacy.com/gh/vb64/markdown-pdf/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_coverage)
7
7
  [![PyPI - Downloads](https://img.shields.io/pypi/dm/markdown-pdf?label=pypi%20installs)](https://pypistats.org/packages/markdown-pdf)
@@ -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
+ - Use the plantuml content plugin
21
22
 
22
23
  The module utilizes the functions of two great libraries.
23
24
 
@@ -131,7 +132,7 @@ The `Section` class can set the following attributes.
131
132
 
132
133
  - toc: whether to include the headers `<h1>` - `<h6>` of this section in the TOC. Default is True.
133
134
  - 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".
135
+ - 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
136
  - borders: size of borders. Default (36, 36, -36, -36).
136
137
 
137
138
  The following document properties are available for assignment (dictionary `MarkdownPdf.meta`) with the default values indicated.
@@ -145,6 +146,67 @@ 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
+ ![Without plantuml.jpg](img/without_plantuml.jpg)
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
+ ![With plantuml.jpg](img/with_plantuml.jpg)
209
+
148
210
  ## Example
149
211
 
150
212
  As an example, you can download the [pdf file](examples/markdown_pdf.pdf) created from this md file.
@@ -1,4 +1,5 @@
1
1
  """Markdown to pdf converter based on markdown_it and fitz."""
2
+ import os
2
3
  import io
3
4
  import typing
4
5
  import pathlib
@@ -6,8 +7,18 @@ import pathlib
6
7
  import fitz
7
8
  from markdown_it import MarkdownIt
8
9
  from pymupdf import (
9
- _as_pdf_document, mupdf, JM_embedded_clean, JM_ensure_identity, JM_new_output_fileptr, ASSERT_PDF,
10
+ _as_pdf_document, mupdf, JM_embedded_clean, JM_ensure_identity, JM_new_output_fileptr, ASSERT_PDF, Rect,
10
11
  )
12
+ from .pligins import PLUGINS, get_plugin_chunks
13
+
14
+ MM_2_PT = 2.835
15
+
16
+
17
+ def clear_temp_files(files):
18
+ """Remove temp files from given list."""
19
+ for i in files:
20
+ if os.path.exists(i):
21
+ os.remove(i)
11
22
 
12
23
 
13
24
  class Section:
@@ -18,15 +29,25 @@ class Section:
18
29
  text: str,
19
30
  toc: bool = True,
20
31
  root: str = ".",
21
- paper_size: str = "A4",
32
+ paper_size: str or list or tuple = "A4",
22
33
  borders: typing.Tuple[int, int, int, int] = (36, 36, -36, -36)
23
34
  ):
24
35
  """Create md section with given properties."""
25
36
  self.text = text
26
37
  self.toc = toc
27
38
  self.root = root
28
- # https://pymupdf.readthedocs.io/en/latest/functions.html#paper_size
39
+
29
40
  self.paper_size = paper_size
41
+ if isinstance(paper_size, str):
42
+ # https://pymupdf.readthedocs.io/en/latest/functions.html#paper_size
43
+ self.rect = fitz.paper_rect(paper_size)
44
+ elif isinstance(paper_size, (list, tuple)):
45
+ # Other paper sizes are in pt, so need to times mm by 2.835.
46
+ width, height = paper_size
47
+ self.rect = Rect(0.0, 0.0, (width * MM_2_PT), (height * MM_2_PT))
48
+ else:
49
+ raise TypeError("paper_size must be 'str', 'tuple' or 'list'")
50
+
30
51
  self.borders = borders
31
52
 
32
53
 
@@ -44,10 +65,18 @@ class MarkdownPdf:
44
65
  "keywords": None,
45
66
  }
46
67
 
47
- def __init__(self, toc_level: int = 6, mode: str = 'commonmark', optimize: bool = False):
68
+ def __init__(
69
+ self,
70
+ toc_level: int = 6,
71
+ mode: str = 'commonmark',
72
+ optimize: bool = False,
73
+ plugins: typing.Optional[dict] = None
74
+ ):
48
75
  """Create md -> pdf converter with given TOC level and mode of md parsing."""
49
76
  self.toc_level = toc_level
50
77
  self.toc = []
78
+ self.plugins = plugins or {}
79
+ self.temp_files = []
51
80
 
52
81
  # zero, commonmark, js-default, gfm-like
53
82
  # https://markdown-it-py.readthedocs.io/en/latest/using.html#quick-start
@@ -79,16 +108,27 @@ class MarkdownPdf:
79
108
  elpos.rect[1], # top of written rectangle (use for TOC)
80
109
  ))
81
110
 
111
+ def apply_plugins(self, text):
112
+ """Return modified text according plugins settings."""
113
+ if not self.plugins:
114
+ return text
115
+
116
+ text = '\n'.join(text.splitlines())
117
+ for key, val in self.plugins.items():
118
+ for chunk in get_plugin_chunks(key, text):
119
+ text = text.replace(chunk, PLUGINS[key](val, chunk, self.temp_files))
120
+
121
+ return text
122
+
82
123
  def add_section(self, section: Section, user_css: typing.Optional[str] = None) -> str:
83
124
  """Add markdown section to pdf."""
84
- rect = fitz.paper_rect(section.paper_size)
85
- where = rect + section.borders
86
- html = self.m_d.render(section.text)
125
+ where = section.rect + section.borders
126
+ html = self.m_d.render(self.apply_plugins(section.text))
87
127
  story = fitz.Story(html=html, archive=section.root, user_css=user_css)
88
128
  more = 1
89
129
  while more: # loop outputting the story
90
130
  self.page_num += 1
91
- device = self.writer.begin_page(rect)
131
+ device = self.writer.begin_page(section.rect)
92
132
  more, _ = story.place(where) # layout into allowed rectangle
93
133
  story.element_positions(self._recorder, {"toc": section.toc, "pdfile": self})
94
134
  story.draw(device)
@@ -115,6 +155,7 @@ class MarkdownPdf:
115
155
  else:
116
156
  doc.save(file_name)
117
157
  doc.close()
158
+ clear_temp_files(self.temp_files)
118
159
 
119
160
  def save_bytes(self, bytesio: io.BytesIO) -> int:
120
161
  """Save pdf to file-like object and return byte size of the filled object."""
@@ -150,5 +191,6 @@ class MarkdownPdf:
150
191
  out = JM_new_output_fileptr(bytesio)
151
192
  mupdf.pdf_write_document(pdf, out, opts)
152
193
  out.fz_close_output()
194
+ clear_temp_files(self.temp_files)
153
195
 
154
196
  return bytesio.getbuffer().nbytes
@@ -0,0 +1,32 @@
1
+ """Plugins."""
2
+ from .plantuml import handler as plantuml_handler
3
+
4
+
5
+ class Plugin:
6
+ """Available plugins."""
7
+
8
+ Plantuml = "plantuml"
9
+
10
+
11
+ PLUGINS = {
12
+ Plugin.Plantuml: plantuml_handler,
13
+ }
14
+
15
+
16
+ def get_plugin_chunks(key, text):
17
+ """Extract key parts from given text."""
18
+ chunk = []
19
+ chunks = []
20
+
21
+ for line in text.splitlines():
22
+
23
+ if line.startswith("```{}".format(key)):
24
+ chunk = [line]
25
+ elif (line.startswith("```")) and chunk:
26
+ chunk.append(line)
27
+ chunks.append('\n'.join(chunk))
28
+ chunk = []
29
+ elif chunk:
30
+ chunk.append(line)
31
+
32
+ return chunks
@@ -0,0 +1,26 @@
1
+ """Plantunl plugin."""
2
+ import os
3
+ import tempfile
4
+ from plantuml import PlantUML
5
+
6
+
7
+ def handler(params_dict, text, temp_files):
8
+ """Translate plantunl marked text to png image."""
9
+ url = params_dict.get("url")
10
+ if not url:
11
+ return "No value for 'url' key in plantuml plugin parameters: {}".format(params_dict)
12
+
13
+ text = '\n'.join(text.splitlines()[1:-1])
14
+ server = PlantUML(url=url)
15
+ image = server.processes(text)
16
+ file_name = ''
17
+
18
+ with tempfile.NamedTemporaryFile(mode='wb', delete=False, suffix=".png") as tmp_file:
19
+ file_name = os.path.basename(tmp_file.name)
20
+ temp_files.append(tmp_file.name)
21
+
22
+ with open(file_name, mode='wb') as out:
23
+ temp_files.append(file_name)
24
+ out.write(image)
25
+
26
+ return "\n![PlantUML scheme]({})\n".format(file_name)
@@ -1,13 +1,12 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: markdown_pdf
3
- Version: 1.9
3
+ Version: 1.11
4
4
  Summary: Markdown to pdf renderer
5
5
  Author-email: Vitaly Bogomolov <mail@vitaly-bogomolov.ru>
6
- License: GNU Affero General Public License v3
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,11 +23,12 @@ 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
  [![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/vb64/markdown-pdf/pep257.yml?label=Pep257&style=plastic&branch=main)](https://github.com/vb64/markdown-pdf/actions?query=workflow%3Apep257)
29
- [![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/vb64/markdown-pdf/py3.yml?label=Python%203.8-3.13&style=plastic&branch=main)](https://github.com/vb64/markdown-pdf/actions?query=workflow%3Apy3)
31
+ [![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/vb64/markdown-pdf/py3.yml?label=Python%203.8-3.14&style=plastic&branch=main)](https://github.com/vb64/markdown-pdf/actions?query=workflow%3Apy3)
30
32
  [![Codacy Badge](https://app.codacy.com/project/badge/Grade/27b53043bff34f07bfb79ee1672b7ba0)](https://app.codacy.com/gh/vb64/markdown-pdf/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
31
33
  [![Codacy Badge](https://app.codacy.com/project/badge/Coverage/27b53043bff34f07bfb79ee1672b7ba0)](https://app.codacy.com/gh/vb64/markdown-pdf/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_coverage)
32
34
  [![PyPI - Downloads](https://img.shields.io/pypi/dm/markdown-pdf?label=pypi%20installs)](https://pypistats.org/packages/markdown-pdf)
@@ -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
+ - Use the plantuml content plugin
46
49
 
47
50
  The module utilizes the functions of two great libraries.
48
51
 
@@ -156,7 +159,7 @@ The `Section` class can set the following attributes.
156
159
 
157
160
  - toc: whether to include the headers `<h1>` - `<h6>` of this section in the TOC. Default is True.
158
161
  - 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".
162
+ - 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
163
  - borders: size of borders. Default (36, 36, -36, -36).
161
164
 
162
165
  The following document properties are available for assignment (dictionary `MarkdownPdf.meta`) with the default values indicated.
@@ -170,6 +173,67 @@ 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
+ ![Without plantuml.jpg](img/without_plantuml.jpg)
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
+ ![With plantuml.jpg](img/with_plantuml.jpg)
236
+
173
237
  ## Example
174
238
 
175
239
  As an example, you can download the [pdf file](examples/markdown_pdf.pdf) created from this md file.
@@ -8,4 +8,6 @@ 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/plantuml.py
@@ -1,3 +1,5 @@
1
+ plantuml==0.3.0
2
+ six==1.17.0
1
3
 
2
4
  [:python_version < "3.9"]
3
5
  PyMuPDF==1.24.6
@@ -7,23 +7,24 @@ build-backend = "setuptools.build_meta"
7
7
 
8
8
  [project]
9
9
  name = "markdown_pdf"
10
- version = "1.9"
10
+ version = "1.11"
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 = { text = "GNU Affero General Public License v3" }
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,15 @@ 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
+ ]
File without changes
File without changes
File without changes