markdown-pdf 1.6__tar.gz → 1.8__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.
@@ -0,0 +1,185 @@
1
+ Metadata-Version: 2.1
2
+ Name: markdown_pdf
3
+ Version: 1.8
4
+ Summary: Markdown to pdf renderer
5
+ Author-email: Vitaly Bogomolov <mail@vitaly-bogomolov.ru>
6
+ License: GNU Affero General Public License v3
7
+ Project-URL: Homepage, https://github.com/vb64/markdown-pdf
8
+ Project-URL: Bug Tracker, https://github.com/vb64/markdown-pdf/issues
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: GNU Affero General Public License v3
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.8
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: PyMuPDF==1.24.6; python_version < "3.9"
16
+ Requires-Dist: PyMuPDF==1.25.3; python_version > "3.8"
17
+ Requires-Dist: markdown-it-py==3.0.0; python_version >= "3.8"
18
+ Provides-Extra: dev
19
+ Requires-Dist: flake8; extra == "dev"
20
+ Requires-Dist: pylint; extra == "dev"
21
+ Requires-Dist: pydocstyle; extra == "dev"
22
+ Requires-Dist: pytest; extra == "dev"
23
+ Requires-Dist: pytest-cov; extra == "dev"
24
+ Requires-Dist: codacy-coverage; extra == "dev"
25
+
26
+ # Module markdown-pdf
27
+
28
+ [![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)
30
+ [![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
+ [![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
+ [![PyPI - Downloads](https://img.shields.io/pypi/dm/markdown-pdf?label=pypi%20installs)](https://pypistats.org/packages/markdown-pdf)
33
+
34
+ The free, open source Python module `markdown-pdf` will create a PDF file from your content in `markdown` format.
35
+
36
+ When creating a PDF file you can:
37
+
38
+ - Use `UTF-8` encoded text in `markdown` in any language
39
+ - Embed images used in `markdown`
40
+ - Break text into pages in the desired order
41
+ - Create a TableOfContents (bookmarks) from markdown headings
42
+ - Tune the necessary elements using your CSS code
43
+ - Use different page sizes within single pdf
44
+ - Create tables in `markdown`
45
+ - Use clickable hyperlinks. Thanks a lot [@thongtmtrust](https://github.com/thongtmtrust) for ideas and collaboration.
46
+
47
+ The module utilizes the functions of two great libraries.
48
+
49
+ - [markdown-it-py](https://github.com/executablebooks/markdown-it-py) to convert `markdown` to `html`.
50
+ - [PyMuPDF](https://github.com/pymupdf/PyMuPDF) to convert `html` to `pdf`.
51
+
52
+ ## Installation
53
+
54
+ ```bash
55
+ pip install markdown-pdf
56
+ ```
57
+
58
+ ## Usage
59
+
60
+ Create a compressed pdf with TOC (bookmarks) from headings up to level 2.
61
+
62
+ ```python
63
+ from markdown_pdf import MarkdownPdf
64
+
65
+ pdf = MarkdownPdf(toc_level=2, optimize=True)
66
+ ```
67
+
68
+ Add the first section to the pdf. The title is not included in the table of contents.
69
+
70
+ ```python
71
+ from markdown_pdf import Section
72
+
73
+ pdf.add_section(Section("# Title\n", toc=False))
74
+ ```
75
+
76
+ Add a second section with external and internal hyperlinks.
77
+ In the pdf file it starts on a new page.
78
+
79
+ ```python
80
+ text = """# Section with links
81
+
82
+ - [External link](https://github.com/vb64/markdown-pdf)
83
+ - [Internal link to Head1](#head1)
84
+ - [Internal link to Head3](#head3)
85
+ """
86
+
87
+ pdf.add_section(Section(text))
88
+ ```
89
+
90
+ Add a third section.
91
+ The title is centered using CSS, included in the table of contents of the pdf file, and an image from the file `img/python.png` is embedded on the page.
92
+
93
+ ```python
94
+ pdf.add_section(
95
+ Section("# <a name='head1'></a>Head1\n\n![python](img/python.png)\n\nbody\n"),
96
+ user_css="h1 {text-align:center;}"
97
+ )
98
+ ```
99
+
100
+ Add a next section. Two headings of different levels from this section are included in the TOC of the pdf file.
101
+ The section has landscape orientation of A4 pages.
102
+
103
+ ```python
104
+ pdf.add_section(Section("## Head2\n\n### <a id='head3'></a>Head3\n\n", paper_size="A4-L"))
105
+ ```
106
+
107
+ Add a section with a table.
108
+
109
+ ```python
110
+
111
+ text = """# Section with Table
112
+
113
+ |TableHeader1|TableHeader2|
114
+ |--|--|
115
+ |Text1|Text2|
116
+ |ListCell|<ul><li>FirstBullet</li><li>SecondBullet</li></ul>|
117
+ """
118
+
119
+ css = "table, th, td {border: 1px solid black;}"
120
+
121
+ pdf.add_section(Section(text), user_css=css)
122
+ ```
123
+
124
+ Set the properties of the pdf document.
125
+
126
+ ```python
127
+ pdf.meta["title"] = "User Guide"
128
+ pdf.meta["author"] = "Vitaly Bogomolov"
129
+ ```
130
+
131
+ Save to file.
132
+
133
+ ```python
134
+ pdf.save("guide.pdf")
135
+ ```
136
+
137
+ Or save to file-like object.
138
+
139
+ ```python
140
+ import io
141
+
142
+ out = io.BytesIO()
143
+ pdf.save_bytes(out)
144
+ assert out.getbuffer().nbytes > 0
145
+ ```
146
+
147
+ ![Pdf](img/with_toc.png)
148
+
149
+ ## Settings and options
150
+
151
+ The `Section` class defines a portion of `markdown` data,
152
+ which is processed according to the same rules.
153
+ The next `Section` data starts on a new page.
154
+
155
+ The `Section` class can set the following attributes.
156
+
157
+ - toc: whether to include the headers `<h1>` - `<h6>` of this section in the TOC. Default is True.
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".
160
+ - borders: size of borders. Default (36, 36, -36, -36).
161
+
162
+ The following document properties are available for assignment (dictionary `MarkdownPdf.meta`) with the default values indicated.
163
+
164
+ - `creationDate`: current date
165
+ - `modDate`: current date
166
+ - `creator`: "PyMuPDF library: https://pypi.org/project/PyMuPDF"
167
+ - `producer`: ""
168
+ - `title`: ""
169
+ - `author`: ""
170
+ - `subject`: ""
171
+ - `keywords`: ""
172
+
173
+ ## Example
174
+
175
+ As an example, you can download the [pdf file](examples/markdown_pdf.pdf) created from this md file.
176
+ This [Python script](makepdf.py) was used to create the PDF file.
177
+
178
+ ## Development
179
+
180
+ ```bash
181
+ git clone git@github.com:vb64/markdown-pdf.git
182
+ cd markdown-pdf
183
+ make setup PYTHON_BIN=/path/to/python3
184
+ make tests
185
+ ```
@@ -32,12 +32,12 @@ pip install markdown-pdf
32
32
 
33
33
  ## Usage
34
34
 
35
- Create a pdf with TOC (bookmarks) from headings up to level 2.
35
+ Create a compressed pdf with TOC (bookmarks) from headings up to level 2.
36
36
 
37
37
  ```python
38
38
  from markdown_pdf import MarkdownPdf
39
39
 
40
- pdf = MarkdownPdf(toc_level=2)
40
+ pdf = MarkdownPdf(toc_level=2, optimize=True)
41
41
  ```
42
42
 
43
43
  Add the first section to the pdf. The title is not included in the table of contents.
@@ -109,6 +109,16 @@ Save to file.
109
109
  pdf.save("guide.pdf")
110
110
  ```
111
111
 
112
+ Or save to file-like object.
113
+
114
+ ```python
115
+ import io
116
+
117
+ out = io.BytesIO()
118
+ pdf.save_bytes(out)
119
+ assert out.getbuffer().nbytes > 0
120
+ ```
121
+
112
122
  ![Pdf](img/with_toc.png)
113
123
 
114
124
  ## Settings and options
@@ -145,18 +155,6 @@ This [Python script](makepdf.py) was used to create the PDF file.
145
155
  ```bash
146
156
  git clone git@github.com:vb64/markdown-pdf.git
147
157
  cd markdown-pdf
148
- ```
149
-
150
- With Python > 3.8
151
-
152
- ```bash
153
158
  make setup PYTHON_BIN=/path/to/python3
154
159
  make tests
155
160
  ```
156
-
157
- With Python 3.8
158
-
159
- ```bash
160
- make setup38 PYTHON_BIN=/path/to/python3.8
161
- make tests
162
- ```
@@ -2,8 +2,12 @@
2
2
  import io
3
3
  import typing
4
4
  import pathlib
5
- from markdown_it import MarkdownIt
5
+
6
6
  import fitz
7
+ from markdown_it import MarkdownIt
8
+ from pymupdf import (
9
+ _as_pdf_document, mupdf, JM_embedded_clean, JM_ensure_identity, JM_new_output_fileptr, ASSERT_PDF,
10
+ )
7
11
 
8
12
 
9
13
  class Section:
@@ -15,7 +19,7 @@ class Section:
15
19
  toc: bool = True,
16
20
  root: str = ".",
17
21
  paper_size: str = "A4",
18
- borders: tuple = (36, 36, -36, -36)
22
+ borders: typing.Tuple[int, int, int, int] = (36, 36, -36, -36)
19
23
  ):
20
24
  """Create md section with given properties."""
21
25
  self.text = text
@@ -40,7 +44,7 @@ class MarkdownPdf:
40
44
  "keywords": None,
41
45
  }
42
46
 
43
- def __init__(self, toc_level: int = 6, mode: str = 'commonmark'):
47
+ def __init__(self, toc_level: int = 6, mode: str = 'commonmark', optimize: bool = False):
44
48
  """Create md -> pdf converter with given TOC level and mode of md parsing."""
45
49
  self.toc_level = toc_level
46
50
  self.toc = []
@@ -49,6 +53,8 @@ class MarkdownPdf:
49
53
  # https://markdown-it-py.readthedocs.io/en/latest/using.html#quick-start
50
54
  self.m_d = (MarkdownIt(mode).enable('table')) # Enable support for tables
51
55
 
56
+ self.optimize = optimize
57
+
52
58
  self.out_file = io.BytesIO()
53
59
  self.writer = fitz.DocumentWriter(self.out_file)
54
60
  self.page_num = 0
@@ -90,13 +96,59 @@ class MarkdownPdf:
90
96
 
91
97
  return html
92
98
 
93
- def save(self, file_name: typing.Union[str, pathlib.Path]) -> None:
94
- """Save pdf to file."""
99
+ def _make_doc(self):
100
+ """Return fitz doc object."""
95
101
  self.writer.close()
96
102
  self.out_file.seek(0)
97
103
  doc = fitz.Story.add_pdf_links(self.out_file, self.hrefs)
98
104
  doc.set_metadata(self.meta)
99
105
  if self.toc_level > 0:
100
106
  doc.set_toc(self.toc)
101
- doc.save(file_name)
107
+
108
+ return doc
109
+
110
+ def save(self, file_name: typing.Union[str, pathlib.Path]) -> None:
111
+ """Save pdf to file."""
112
+ doc = self._make_doc()
113
+ if self.optimize:
114
+ doc.ez_save(file_name)
115
+ else:
116
+ doc.save(file_name)
102
117
  doc.close()
118
+
119
+ def save_bytes(self, bytesio: io.BytesIO) -> int:
120
+ """Save pdf to file-like object and return byte size of the filled object."""
121
+ doc = self._make_doc()
122
+
123
+ pdf = _as_pdf_document(doc)
124
+ opts = mupdf.PdfWriteOptions()
125
+
126
+ opts.do_incremental = 0
127
+ opts.do_ascii = 0
128
+ opts.do_compress = 0
129
+ opts.do_compress_images = 0
130
+ opts.do_compress_fonts = 0
131
+ opts.do_decompress = 0
132
+ opts.do_garbage = 0
133
+ opts.do_pretty = 0
134
+ opts.do_linear = 0
135
+ opts.do_clean = 0
136
+ opts.do_sanitize = 0
137
+ opts.dont_regenerate_id = 0
138
+ opts.do_appearance = 0
139
+ opts.do_encrypt = 1
140
+ opts.permissions = 4095
141
+ opts.do_preserve_metadata = 1
142
+ opts.do_use_objstms = 0
143
+ opts.compression_effort = 0
144
+
145
+ ASSERT_PDF(pdf)
146
+ pdf.m_internal.resynth_required = 0
147
+ JM_embedded_clean(pdf)
148
+ JM_ensure_identity(pdf)
149
+
150
+ out = JM_new_output_fileptr(bytesio)
151
+ mupdf.pdf_write_document(pdf, out, opts)
152
+ out.fz_close_output()
153
+
154
+ return bytesio.getbuffer().nbytes
File without changes
@@ -0,0 +1,185 @@
1
+ Metadata-Version: 2.1
2
+ Name: markdown_pdf
3
+ Version: 1.8
4
+ Summary: Markdown to pdf renderer
5
+ Author-email: Vitaly Bogomolov <mail@vitaly-bogomolov.ru>
6
+ License: GNU Affero General Public License v3
7
+ Project-URL: Homepage, https://github.com/vb64/markdown-pdf
8
+ Project-URL: Bug Tracker, https://github.com/vb64/markdown-pdf/issues
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: GNU Affero General Public License v3
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.8
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: PyMuPDF==1.24.6; python_version < "3.9"
16
+ Requires-Dist: PyMuPDF==1.25.3; python_version > "3.8"
17
+ Requires-Dist: markdown-it-py==3.0.0; python_version >= "3.8"
18
+ Provides-Extra: dev
19
+ Requires-Dist: flake8; extra == "dev"
20
+ Requires-Dist: pylint; extra == "dev"
21
+ Requires-Dist: pydocstyle; extra == "dev"
22
+ Requires-Dist: pytest; extra == "dev"
23
+ Requires-Dist: pytest-cov; extra == "dev"
24
+ Requires-Dist: codacy-coverage; extra == "dev"
25
+
26
+ # Module markdown-pdf
27
+
28
+ [![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)
30
+ [![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
+ [![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
+ [![PyPI - Downloads](https://img.shields.io/pypi/dm/markdown-pdf?label=pypi%20installs)](https://pypistats.org/packages/markdown-pdf)
33
+
34
+ The free, open source Python module `markdown-pdf` will create a PDF file from your content in `markdown` format.
35
+
36
+ When creating a PDF file you can:
37
+
38
+ - Use `UTF-8` encoded text in `markdown` in any language
39
+ - Embed images used in `markdown`
40
+ - Break text into pages in the desired order
41
+ - Create a TableOfContents (bookmarks) from markdown headings
42
+ - Tune the necessary elements using your CSS code
43
+ - Use different page sizes within single pdf
44
+ - Create tables in `markdown`
45
+ - Use clickable hyperlinks. Thanks a lot [@thongtmtrust](https://github.com/thongtmtrust) for ideas and collaboration.
46
+
47
+ The module utilizes the functions of two great libraries.
48
+
49
+ - [markdown-it-py](https://github.com/executablebooks/markdown-it-py) to convert `markdown` to `html`.
50
+ - [PyMuPDF](https://github.com/pymupdf/PyMuPDF) to convert `html` to `pdf`.
51
+
52
+ ## Installation
53
+
54
+ ```bash
55
+ pip install markdown-pdf
56
+ ```
57
+
58
+ ## Usage
59
+
60
+ Create a compressed pdf with TOC (bookmarks) from headings up to level 2.
61
+
62
+ ```python
63
+ from markdown_pdf import MarkdownPdf
64
+
65
+ pdf = MarkdownPdf(toc_level=2, optimize=True)
66
+ ```
67
+
68
+ Add the first section to the pdf. The title is not included in the table of contents.
69
+
70
+ ```python
71
+ from markdown_pdf import Section
72
+
73
+ pdf.add_section(Section("# Title\n", toc=False))
74
+ ```
75
+
76
+ Add a second section with external and internal hyperlinks.
77
+ In the pdf file it starts on a new page.
78
+
79
+ ```python
80
+ text = """# Section with links
81
+
82
+ - [External link](https://github.com/vb64/markdown-pdf)
83
+ - [Internal link to Head1](#head1)
84
+ - [Internal link to Head3](#head3)
85
+ """
86
+
87
+ pdf.add_section(Section(text))
88
+ ```
89
+
90
+ Add a third section.
91
+ The title is centered using CSS, included in the table of contents of the pdf file, and an image from the file `img/python.png` is embedded on the page.
92
+
93
+ ```python
94
+ pdf.add_section(
95
+ Section("# <a name='head1'></a>Head1\n\n![python](img/python.png)\n\nbody\n"),
96
+ user_css="h1 {text-align:center;}"
97
+ )
98
+ ```
99
+
100
+ Add a next section. Two headings of different levels from this section are included in the TOC of the pdf file.
101
+ The section has landscape orientation of A4 pages.
102
+
103
+ ```python
104
+ pdf.add_section(Section("## Head2\n\n### <a id='head3'></a>Head3\n\n", paper_size="A4-L"))
105
+ ```
106
+
107
+ Add a section with a table.
108
+
109
+ ```python
110
+
111
+ text = """# Section with Table
112
+
113
+ |TableHeader1|TableHeader2|
114
+ |--|--|
115
+ |Text1|Text2|
116
+ |ListCell|<ul><li>FirstBullet</li><li>SecondBullet</li></ul>|
117
+ """
118
+
119
+ css = "table, th, td {border: 1px solid black;}"
120
+
121
+ pdf.add_section(Section(text), user_css=css)
122
+ ```
123
+
124
+ Set the properties of the pdf document.
125
+
126
+ ```python
127
+ pdf.meta["title"] = "User Guide"
128
+ pdf.meta["author"] = "Vitaly Bogomolov"
129
+ ```
130
+
131
+ Save to file.
132
+
133
+ ```python
134
+ pdf.save("guide.pdf")
135
+ ```
136
+
137
+ Or save to file-like object.
138
+
139
+ ```python
140
+ import io
141
+
142
+ out = io.BytesIO()
143
+ pdf.save_bytes(out)
144
+ assert out.getbuffer().nbytes > 0
145
+ ```
146
+
147
+ ![Pdf](img/with_toc.png)
148
+
149
+ ## Settings and options
150
+
151
+ The `Section` class defines a portion of `markdown` data,
152
+ which is processed according to the same rules.
153
+ The next `Section` data starts on a new page.
154
+
155
+ The `Section` class can set the following attributes.
156
+
157
+ - toc: whether to include the headers `<h1>` - `<h6>` of this section in the TOC. Default is True.
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".
160
+ - borders: size of borders. Default (36, 36, -36, -36).
161
+
162
+ The following document properties are available for assignment (dictionary `MarkdownPdf.meta`) with the default values indicated.
163
+
164
+ - `creationDate`: current date
165
+ - `modDate`: current date
166
+ - `creator`: "PyMuPDF library: https://pypi.org/project/PyMuPDF"
167
+ - `producer`: ""
168
+ - `title`: ""
169
+ - `author`: ""
170
+ - `subject`: ""
171
+ - `keywords`: ""
172
+
173
+ ## Example
174
+
175
+ As an example, you can download the [pdf file](examples/markdown_pdf.pdf) created from this md file.
176
+ This [Python script](makepdf.py) was used to create the PDF file.
177
+
178
+ ## Development
179
+
180
+ ```bash
181
+ git clone git@github.com:vb64/markdown-pdf.git
182
+ cd markdown-pdf
183
+ make setup PYTHON_BIN=/path/to/python3
184
+ make tests
185
+ ```
@@ -2,8 +2,8 @@ LICENSE
2
2
  MANIFEST.in
3
3
  README.md
4
4
  pyproject.toml
5
- setup.cfg
6
5
  markdown_pdf/__init__.py
6
+ markdown_pdf/py.typed
7
7
  markdown_pdf.egg-info/PKG-INFO
8
8
  markdown_pdf.egg-info/SOURCES.txt
9
9
  markdown_pdf.egg-info/dependency_links.txt
@@ -7,3 +7,11 @@ PyMuPDF==1.25.3
7
7
 
8
8
  [:python_version >= "3.8"]
9
9
  markdown-it-py==3.0.0
10
+
11
+ [dev]
12
+ flake8
13
+ pylint
14
+ pydocstyle
15
+ pytest
16
+ pytest-cov
17
+ codacy-coverage
@@ -0,0 +1,47 @@
1
+ [build-system]
2
+ requires = [
3
+ "setuptools>=42",
4
+ "wheel"
5
+ ]
6
+ build-backend = "setuptools.build_meta"
7
+
8
+ [project]
9
+ name = "markdown_pdf"
10
+ version = "1.8"
11
+ description = "Markdown to pdf renderer"
12
+ readme = { file = "README.md", content-type = "text/markdown" }
13
+ requires-python = ">=3.8"
14
+ license = { text = "GNU Affero General Public License v3" }
15
+ authors = [
16
+ { name = "Vitaly Bogomolov", email = "mail@vitaly-bogomolov.ru" }
17
+ ]
18
+ classifiers = [
19
+ "Programming Language :: Python :: 3",
20
+ "License :: OSI Approved :: GNU Affero General Public License v3",
21
+ "Operating System :: OS Independent"
22
+ ]
23
+ dependencies = [
24
+ "PyMuPDF==1.24.6; python_version<'3.9'",
25
+ "PyMuPDF==1.25.3; python_version>'3.8'",
26
+ "markdown-it-py==3.0.0; python_version>='3.8'"
27
+ ]
28
+
29
+ [project.optional-dependencies]
30
+ dev = [
31
+ "flake8",
32
+ "pylint",
33
+ "pydocstyle",
34
+ "pytest",
35
+ "pytest-cov",
36
+ "codacy-coverage",
37
+ ]
38
+
39
+ [project.urls]
40
+ "Homepage" = "https://github.com/vb64/markdown-pdf"
41
+ "Bug Tracker" = "https://github.com/vb64/markdown-pdf/issues"
42
+
43
+ [tool.setuptools]
44
+ packages = ["markdown_pdf"]
45
+
46
+ [tool.setuptools.package-data]
47
+ "markdown_pdf" = ["py.typed"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
markdown_pdf-1.6/PKG-INFO DELETED
@@ -1,178 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: markdown_pdf
3
- Version: 1.6
4
- Summary: Markdown to pdf renderer
5
- Home-page: https://github.com/vb64/markdown-pdf
6
- Author: Vitaly Bogomolov
7
- Author-email: mail@vitaly-bogomolov.ru
8
- License: UNKNOWN
9
- Project-URL: Bug Tracker, https://github.com/vb64/markdown-pdf/issues
10
- Description: # Module markdown-pdf
11
-
12
- [![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)
13
- [![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)
14
- [![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)
15
- [![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)
16
- [![PyPI - Downloads](https://img.shields.io/pypi/dm/markdown-pdf?label=pypi%20installs)](https://pypistats.org/packages/markdown-pdf)
17
-
18
- The free, open source Python module `markdown-pdf` will create a PDF file from your content in `markdown` format.
19
-
20
- When creating a PDF file you can:
21
-
22
- - Use `UTF-8` encoded text in `markdown` in any language
23
- - Embed images used in `markdown`
24
- - Break text into pages in the desired order
25
- - Create a TableOfContents (bookmarks) from markdown headings
26
- - Tune the necessary elements using your CSS code
27
- - Use different page sizes within single pdf
28
- - Create tables in `markdown`
29
- - Use clickable hyperlinks. Thanks a lot [@thongtmtrust](https://github.com/thongtmtrust) for ideas and collaboration.
30
-
31
- The module utilizes the functions of two great libraries.
32
-
33
- - [markdown-it-py](https://github.com/executablebooks/markdown-it-py) to convert `markdown` to `html`.
34
- - [PyMuPDF](https://github.com/pymupdf/PyMuPDF) to convert `html` to `pdf`.
35
-
36
- ## Installation
37
-
38
- ```bash
39
- pip install markdown-pdf
40
- ```
41
-
42
- ## Usage
43
-
44
- Create a pdf with TOC (bookmarks) from headings up to level 2.
45
-
46
- ```python
47
- from markdown_pdf import MarkdownPdf
48
-
49
- pdf = MarkdownPdf(toc_level=2)
50
- ```
51
-
52
- Add the first section to the pdf. The title is not included in the table of contents.
53
-
54
- ```python
55
- from markdown_pdf import Section
56
-
57
- pdf.add_section(Section("# Title\n", toc=False))
58
- ```
59
-
60
- Add a second section with external and internal hyperlinks.
61
- In the pdf file it starts on a new page.
62
-
63
- ```python
64
- text = """# Section with links
65
-
66
- - [External link](https://github.com/vb64/markdown-pdf)
67
- - [Internal link to Head1](#head1)
68
- - [Internal link to Head3](#head3)
69
- """
70
-
71
- pdf.add_section(Section(text))
72
- ```
73
-
74
- Add a third section.
75
- The title is centered using CSS, included in the table of contents of the pdf file, and an image from the file `img/python.png` is embedded on the page.
76
-
77
- ```python
78
- pdf.add_section(
79
- Section("# <a name='head1'></a>Head1\n\n![python](img/python.png)\n\nbody\n"),
80
- user_css="h1 {text-align:center;}"
81
- )
82
- ```
83
-
84
- Add a next section. Two headings of different levels from this section are included in the TOC of the pdf file.
85
- The section has landscape orientation of A4 pages.
86
-
87
- ```python
88
- pdf.add_section(Section("## Head2\n\n### <a id='head3'></a>Head3\n\n", paper_size="A4-L"))
89
- ```
90
-
91
- Add a section with a table.
92
-
93
- ```python
94
-
95
- text = """# Section with Table
96
-
97
- |TableHeader1|TableHeader2|
98
- |--|--|
99
- |Text1|Text2|
100
- |ListCell|<ul><li>FirstBullet</li><li>SecondBullet</li></ul>|
101
- """
102
-
103
- css = "table, th, td {border: 1px solid black;}"
104
-
105
- pdf.add_section(Section(text), user_css=css)
106
- ```
107
-
108
- Set the properties of the pdf document.
109
-
110
- ```python
111
- pdf.meta["title"] = "User Guide"
112
- pdf.meta["author"] = "Vitaly Bogomolov"
113
- ```
114
-
115
- Save to file.
116
-
117
- ```python
118
- pdf.save("guide.pdf")
119
- ```
120
-
121
- ![Pdf](img/with_toc.png)
122
-
123
- ## Settings and options
124
-
125
- The `Section` class defines a portion of `markdown` data,
126
- which is processed according to the same rules.
127
- The next `Section` data starts on a new page.
128
-
129
- The `Section` class can set the following attributes.
130
-
131
- - toc: whether to include the headers `<h1>` - `<h6>` of this section in the TOC. Default is True.
132
- - root: the name of the root directory from which the image file paths starts in markdown. Default ".".
133
- - paper_size: name of paper size, [as described here](https://pymupdf.readthedocs.io/en/latest/functions.html#paper_size). Default "A4".
134
- - borders: size of borders. Default (36, 36, -36, -36).
135
-
136
- The following document properties are available for assignment (dictionary `MarkdownPdf.meta`) with the default values indicated.
137
-
138
- - `creationDate`: current date
139
- - `modDate`: current date
140
- - `creator`: "PyMuPDF library: https://pypi.org/project/PyMuPDF"
141
- - `producer`: ""
142
- - `title`: ""
143
- - `author`: ""
144
- - `subject`: ""
145
- - `keywords`: ""
146
-
147
- ## Example
148
-
149
- As an example, you can download the [pdf file](examples/markdown_pdf.pdf) created from this md file.
150
- This [Python script](makepdf.py) was used to create the PDF file.
151
-
152
- ## Development
153
-
154
- ```bash
155
- git clone git@github.com:vb64/markdown-pdf.git
156
- cd markdown-pdf
157
- ```
158
-
159
- With Python > 3.8
160
-
161
- ```bash
162
- make setup PYTHON_BIN=/path/to/python3
163
- make tests
164
- ```
165
-
166
- With Python 3.8
167
-
168
- ```bash
169
- make setup38 PYTHON_BIN=/path/to/python3.8
170
- make tests
171
- ```
172
-
173
- Platform: UNKNOWN
174
- Classifier: Programming Language :: Python :: 3
175
- Classifier: License :: OSI Approved :: GNU Affero General Public License v3
176
- Classifier: Operating System :: OS Independent
177
- Requires-Python: >=3.8
178
- Description-Content-Type: text/markdown
@@ -1,178 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: markdown-pdf
3
- Version: 1.6
4
- Summary: Markdown to pdf renderer
5
- Home-page: https://github.com/vb64/markdown-pdf
6
- Author: Vitaly Bogomolov
7
- Author-email: mail@vitaly-bogomolov.ru
8
- License: UNKNOWN
9
- Project-URL: Bug Tracker, https://github.com/vb64/markdown-pdf/issues
10
- Description: # Module markdown-pdf
11
-
12
- [![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)
13
- [![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)
14
- [![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)
15
- [![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)
16
- [![PyPI - Downloads](https://img.shields.io/pypi/dm/markdown-pdf?label=pypi%20installs)](https://pypistats.org/packages/markdown-pdf)
17
-
18
- The free, open source Python module `markdown-pdf` will create a PDF file from your content in `markdown` format.
19
-
20
- When creating a PDF file you can:
21
-
22
- - Use `UTF-8` encoded text in `markdown` in any language
23
- - Embed images used in `markdown`
24
- - Break text into pages in the desired order
25
- - Create a TableOfContents (bookmarks) from markdown headings
26
- - Tune the necessary elements using your CSS code
27
- - Use different page sizes within single pdf
28
- - Create tables in `markdown`
29
- - Use clickable hyperlinks. Thanks a lot [@thongtmtrust](https://github.com/thongtmtrust) for ideas and collaboration.
30
-
31
- The module utilizes the functions of two great libraries.
32
-
33
- - [markdown-it-py](https://github.com/executablebooks/markdown-it-py) to convert `markdown` to `html`.
34
- - [PyMuPDF](https://github.com/pymupdf/PyMuPDF) to convert `html` to `pdf`.
35
-
36
- ## Installation
37
-
38
- ```bash
39
- pip install markdown-pdf
40
- ```
41
-
42
- ## Usage
43
-
44
- Create a pdf with TOC (bookmarks) from headings up to level 2.
45
-
46
- ```python
47
- from markdown_pdf import MarkdownPdf
48
-
49
- pdf = MarkdownPdf(toc_level=2)
50
- ```
51
-
52
- Add the first section to the pdf. The title is not included in the table of contents.
53
-
54
- ```python
55
- from markdown_pdf import Section
56
-
57
- pdf.add_section(Section("# Title\n", toc=False))
58
- ```
59
-
60
- Add a second section with external and internal hyperlinks.
61
- In the pdf file it starts on a new page.
62
-
63
- ```python
64
- text = """# Section with links
65
-
66
- - [External link](https://github.com/vb64/markdown-pdf)
67
- - [Internal link to Head1](#head1)
68
- - [Internal link to Head3](#head3)
69
- """
70
-
71
- pdf.add_section(Section(text))
72
- ```
73
-
74
- Add a third section.
75
- The title is centered using CSS, included in the table of contents of the pdf file, and an image from the file `img/python.png` is embedded on the page.
76
-
77
- ```python
78
- pdf.add_section(
79
- Section("# <a name='head1'></a>Head1\n\n![python](img/python.png)\n\nbody\n"),
80
- user_css="h1 {text-align:center;}"
81
- )
82
- ```
83
-
84
- Add a next section. Two headings of different levels from this section are included in the TOC of the pdf file.
85
- The section has landscape orientation of A4 pages.
86
-
87
- ```python
88
- pdf.add_section(Section("## Head2\n\n### <a id='head3'></a>Head3\n\n", paper_size="A4-L"))
89
- ```
90
-
91
- Add a section with a table.
92
-
93
- ```python
94
-
95
- text = """# Section with Table
96
-
97
- |TableHeader1|TableHeader2|
98
- |--|--|
99
- |Text1|Text2|
100
- |ListCell|<ul><li>FirstBullet</li><li>SecondBullet</li></ul>|
101
- """
102
-
103
- css = "table, th, td {border: 1px solid black;}"
104
-
105
- pdf.add_section(Section(text), user_css=css)
106
- ```
107
-
108
- Set the properties of the pdf document.
109
-
110
- ```python
111
- pdf.meta["title"] = "User Guide"
112
- pdf.meta["author"] = "Vitaly Bogomolov"
113
- ```
114
-
115
- Save to file.
116
-
117
- ```python
118
- pdf.save("guide.pdf")
119
- ```
120
-
121
- ![Pdf](img/with_toc.png)
122
-
123
- ## Settings and options
124
-
125
- The `Section` class defines a portion of `markdown` data,
126
- which is processed according to the same rules.
127
- The next `Section` data starts on a new page.
128
-
129
- The `Section` class can set the following attributes.
130
-
131
- - toc: whether to include the headers `<h1>` - `<h6>` of this section in the TOC. Default is True.
132
- - root: the name of the root directory from which the image file paths starts in markdown. Default ".".
133
- - paper_size: name of paper size, [as described here](https://pymupdf.readthedocs.io/en/latest/functions.html#paper_size). Default "A4".
134
- - borders: size of borders. Default (36, 36, -36, -36).
135
-
136
- The following document properties are available for assignment (dictionary `MarkdownPdf.meta`) with the default values indicated.
137
-
138
- - `creationDate`: current date
139
- - `modDate`: current date
140
- - `creator`: "PyMuPDF library: https://pypi.org/project/PyMuPDF"
141
- - `producer`: ""
142
- - `title`: ""
143
- - `author`: ""
144
- - `subject`: ""
145
- - `keywords`: ""
146
-
147
- ## Example
148
-
149
- As an example, you can download the [pdf file](examples/markdown_pdf.pdf) created from this md file.
150
- This [Python script](makepdf.py) was used to create the PDF file.
151
-
152
- ## Development
153
-
154
- ```bash
155
- git clone git@github.com:vb64/markdown-pdf.git
156
- cd markdown-pdf
157
- ```
158
-
159
- With Python > 3.8
160
-
161
- ```bash
162
- make setup PYTHON_BIN=/path/to/python3
163
- make tests
164
- ```
165
-
166
- With Python 3.8
167
-
168
- ```bash
169
- make setup38 PYTHON_BIN=/path/to/python3.8
170
- make tests
171
- ```
172
-
173
- Platform: UNKNOWN
174
- Classifier: Programming Language :: Python :: 3
175
- Classifier: License :: OSI Approved :: GNU Affero General Public License v3
176
- Classifier: Operating System :: OS Independent
177
- Requires-Python: >=3.8
178
- Description-Content-Type: text/markdown
@@ -1,6 +0,0 @@
1
- [build-system]
2
- requires = [
3
- "setuptools>=42",
4
- "wheel"
5
- ]
6
- build-backend = "setuptools.build_meta"
@@ -1,29 +0,0 @@
1
- [metadata]
2
- name = markdown_pdf
3
- version = 1.6
4
- author = Vitaly Bogomolov
5
- author_email = mail@vitaly-bogomolov.ru
6
- description = Markdown to pdf renderer
7
- long_description = file: README.md
8
- long_description_content_type = text/markdown
9
- url = https://github.com/vb64/markdown-pdf
10
- project_urls =
11
- Bug Tracker = https://github.com/vb64/markdown-pdf/issues
12
- classifiers =
13
- Programming Language :: Python :: 3
14
- License :: OSI Approved :: GNU Affero General Public License v3
15
- Operating System :: OS Independent
16
-
17
- [options]
18
- package_dir =
19
- packages = markdown_pdf
20
- python_requires = >=3.8
21
- install_requires =
22
- PyMuPDF==1.24.6; python_version<"3.9"
23
- PyMuPDF==1.25.3; python_version>"3.8"
24
- markdown-it-py==3.0.0; python_version>="3.8"
25
-
26
- [egg_info]
27
- tag_build =
28
- tag_date = 0
29
-
File without changes
File without changes