md2pdf 0.4__tar.gz → 0.6__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.
- {md2pdf-0.4/md2pdf.egg-info → md2pdf-0.6}/PKG-INFO +7 -4
- md2pdf-0.6/README.md +159 -0
- md2pdf-0.6/md2pdf/__init__.py +8 -0
- md2pdf-0.4/scripts/md2pdf → md2pdf-0.6/md2pdf/__main__.py +2 -1
- {md2pdf-0.4 → md2pdf-0.6}/md2pdf/core.py +4 -9
- {md2pdf-0.4 → md2pdf-0.6}/md2pdf/exceptions.py +2 -1
- {md2pdf-0.4 → md2pdf-0.6/md2pdf.egg-info}/PKG-INFO +7 -4
- {md2pdf-0.4 → md2pdf-0.6}/md2pdf.egg-info/SOURCES.txt +6 -3
- md2pdf-0.6/md2pdf.egg-info/entry_points.txt +3 -0
- {md2pdf-0.4 → md2pdf-0.6}/md2pdf.egg-info/top_level.txt +1 -0
- {md2pdf-0.4 → md2pdf-0.6}/requirements-dev.txt +3 -0
- md2pdf-0.6/setup.cfg +26 -0
- md2pdf-0.6/setup.py +68 -0
- md2pdf-0.6/tests/__init__.py +0 -0
- md2pdf-0.6/tests/defaults.py +6 -0
- md2pdf-0.6/tests/test_cli.py +80 -0
- md2pdf-0.6/tests/test_core.py +31 -0
- md2pdf-0.4/README.md +0 -115
- md2pdf-0.4/md2pdf/__init__.py +0 -5
- md2pdf-0.4/md2pdf/tests.py +0 -16
- md2pdf-0.4/setup.cfg +0 -11
- md2pdf-0.4/setup.py +0 -68
- {md2pdf-0.4 → md2pdf-0.6}/LICENSE +0 -0
- {md2pdf-0.4 → md2pdf-0.6}/MANIFEST.in +0 -0
- {md2pdf-0.4 → md2pdf-0.6}/md2pdf.egg-info/dependency_links.txt +0 -0
- md2pdf-0.4/requirements.txt → md2pdf-0.6/md2pdf.egg-info/requires.txt +0 -0
- md2pdf-0.4/md2pdf.egg-info/requires.txt → md2pdf-0.6/requirements.txt +2 -2
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
Metadata-Version:
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
2
|
Name: md2pdf
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.6
|
|
4
4
|
Summary: md2pdf, a Markdown to PDF conversion tool
|
|
5
5
|
Home-page: UNKNOWN
|
|
6
6
|
Author: Julien Maupetit
|
|
7
7
|
Author-email: julien@maupetit.net
|
|
8
8
|
License: MIT
|
|
9
|
-
Description: UNKNOWN
|
|
10
9
|
Keywords: markdown converter css pdf
|
|
11
10
|
Platform: UNKNOWN
|
|
12
11
|
Classifier: Development Status :: 5 - Production/Stable
|
|
@@ -23,8 +22,12 @@ Classifier: Operating System :: POSIX
|
|
|
23
22
|
Classifier: Programming Language :: Python :: 2
|
|
24
23
|
Classifier: Programming Language :: Python :: 2.7
|
|
25
24
|
Classifier: Programming Language :: Python :: 3
|
|
26
|
-
Classifier: Programming Language :: Python :: 3.3
|
|
27
25
|
Classifier: Programming Language :: Python :: 3.4
|
|
28
26
|
Classifier: Programming Language :: Python :: 3.5
|
|
27
|
+
Classifier: Programming Language :: Python :: 3.6
|
|
29
28
|
Classifier: Topic :: Office/Business
|
|
30
29
|
Classifier: Topic :: Utilities
|
|
30
|
+
License-File: LICENSE
|
|
31
|
+
|
|
32
|
+
UNKNOWN
|
|
33
|
+
|
md2pdf-0.6/README.md
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
Convert Markdown files to PDF with styles.
|
|
4
|
+
|
|
5
|
+
[](https://travis-ci.org/jmaupetit/md2pdf)
|
|
6
|
+
[](https://coveralls.io/github/jmaupetit/md2pdf?branch=master)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
The easiest way to go is to use pip:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
$ pip install md2pdf
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
### As a CLI
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
Usage:
|
|
23
|
+
md2pdf [options] INPUT.MD OUTPUT.PDF
|
|
24
|
+
|
|
25
|
+
Options:
|
|
26
|
+
--css=STYLE.CSS
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
For example, try to generate the project documentation with:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
$ md2pdf README.md README.pdf
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Optionally, you may load an external style (restricted to CSS2):
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
$ md2pdf --css tests/resources/input.css README.md README.pdf
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### As a library
|
|
42
|
+
|
|
43
|
+
You can use `md2pdf` in your python code, like:
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
from md2pdf.core import md2pdf
|
|
47
|
+
|
|
48
|
+
md2pdf(pdf_file_path,
|
|
49
|
+
md_content=None,
|
|
50
|
+
md_file_path=None,
|
|
51
|
+
css_file_path=None,
|
|
52
|
+
base_url=None)
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Function arguments:
|
|
56
|
+
|
|
57
|
+
* `pdf_file_path`: output PDF file path
|
|
58
|
+
* `md_content`: input markdown raw string content
|
|
59
|
+
* `md_file_path`: input markdown file path
|
|
60
|
+
* `css_file_path`: input styles path (CSS)
|
|
61
|
+
* `base_url`: absolute base path for markdown linked content (as images)
|
|
62
|
+
|
|
63
|
+
### With Docker
|
|
64
|
+
|
|
65
|
+
Install [Docker](https://www.docker.com/)
|
|
66
|
+
|
|
67
|
+
Pull the image:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
$ docker pull jmaupetit/md2pdf
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Now run your image:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
$ docker run --rm -v $PWD:/app jmaupetit/md2pdf --css styles.css INPUT.MD OUTPUT.PDF
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Troubleshooting on MacOSX
|
|
80
|
+
|
|
81
|
+
Ensure, Weasyprint is fully functional before using md2pdf. You will find
|
|
82
|
+
installation instructions in the project documentation:
|
|
83
|
+
[https://weasyprint.readthedocs.io/en/latest/install.html](https://weasyprint.readthedocs.io/en/latest/install.html#macos)
|
|
84
|
+
|
|
85
|
+
In a few words, here are the few steps you will need to follow:
|
|
86
|
+
|
|
87
|
+
* Install XQuartz from:
|
|
88
|
+
[https://xquartz.macosforge.org](https://xquartz.macosforge.org)
|
|
89
|
+
* Install all dependencies at once with
|
|
90
|
+
[homebrew](http://mxcl.github.io/homebrew/) and go grab a coffee (this may
|
|
91
|
+
take a while):
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
$ brew install cairo pango gdk-pixbuf libxml2 libxslt libffi
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Misc
|
|
98
|
+
|
|
99
|
+
### Using custom fonts in styles
|
|
100
|
+
|
|
101
|
+
WeasyPrint does not support the `@font-face` property yet (see [project issue
|
|
102
|
+
28](https://github.com/Kozea/WeasyPrint/issues/28)). If you use want to use
|
|
103
|
+
custom fonts, you should use system fonts and define them with the `font-family`
|
|
104
|
+
CSS property, like:
|
|
105
|
+
|
|
106
|
+
```
|
|
107
|
+
font-family: 'Neutraface Condensed';
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Note that you should only define **one single** custom font, not a substitution
|
|
111
|
+
list.
|
|
112
|
+
|
|
113
|
+
## Contributing
|
|
114
|
+
|
|
115
|
+
### Hacking
|
|
116
|
+
|
|
117
|
+
Clone this project first:
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
$ git clone git@github.com:jmaupetit/md2pdf.git
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Install it with its dependencies (ideally in a virtual environment):
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
$ cd md2pdf
|
|
127
|
+
$ python -m venv venv
|
|
128
|
+
$ source venv/bin/activate
|
|
129
|
+
(venv) $ pip install -r requirements-dev.txt
|
|
130
|
+
(venv) $ python setup.py develop
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Running the test suite
|
|
134
|
+
|
|
135
|
+
To run the test suite with your active python version (virtual environment):
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
(venv) $ pytest
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Lint the code via:
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
(venv) $ flake8
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Release a new version
|
|
148
|
+
|
|
149
|
+
Upload a new release to PyPI:
|
|
150
|
+
|
|
151
|
+
```
|
|
152
|
+
$ python setup.py sdist bdist_wheel
|
|
153
|
+
$ twine upload dist/* --username 'johndoe' --password 'secret'
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## License
|
|
157
|
+
|
|
158
|
+
`md2pdf` is released under the MIT License. See the bundled LICENSE file for
|
|
159
|
+
details.
|
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
|
+
from __future__ import unicode_literals
|
|
3
|
+
|
|
2
4
|
from markdown2 import markdown, markdown_path
|
|
3
5
|
from weasyprint import HTML, CSS
|
|
4
6
|
|
|
5
7
|
from .exceptions import ValidationError
|
|
6
8
|
|
|
7
9
|
|
|
8
|
-
__title__ = 'md2pdf'
|
|
9
|
-
__version__ = '0.4'
|
|
10
|
-
__author__ = 'Julien Maupetit'
|
|
11
|
-
__license__ = 'MIT'
|
|
12
|
-
__copyright__ = 'Copyright 2013-2016 Julien Maupetit'
|
|
13
|
-
|
|
14
|
-
|
|
15
10
|
def md2pdf(pdf_file_path, md_content=None, md_file_path=None,
|
|
16
11
|
css_file_path=None, base_url=None):
|
|
17
12
|
"""
|
|
@@ -32,8 +27,8 @@ def md2pdf(pdf_file_path, md_content=None, md_file_path=None,
|
|
|
32
27
|
"""
|
|
33
28
|
|
|
34
29
|
# Convert markdown to html
|
|
35
|
-
raw_html =
|
|
36
|
-
extras = [
|
|
30
|
+
raw_html = ''
|
|
31
|
+
extras = ['cuddled-lists', 'tables', 'footnotes']
|
|
37
32
|
if md_file_path:
|
|
38
33
|
raw_html = markdown_path(md_file_path, extras=extras)
|
|
39
34
|
elif md_content:
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
Metadata-Version:
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
2
|
Name: md2pdf
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.6
|
|
4
4
|
Summary: md2pdf, a Markdown to PDF conversion tool
|
|
5
5
|
Home-page: UNKNOWN
|
|
6
6
|
Author: Julien Maupetit
|
|
7
7
|
Author-email: julien@maupetit.net
|
|
8
8
|
License: MIT
|
|
9
|
-
Description: UNKNOWN
|
|
10
9
|
Keywords: markdown converter css pdf
|
|
11
10
|
Platform: UNKNOWN
|
|
12
11
|
Classifier: Development Status :: 5 - Production/Stable
|
|
@@ -23,8 +22,12 @@ Classifier: Operating System :: POSIX
|
|
|
23
22
|
Classifier: Programming Language :: Python :: 2
|
|
24
23
|
Classifier: Programming Language :: Python :: 2.7
|
|
25
24
|
Classifier: Programming Language :: Python :: 3
|
|
26
|
-
Classifier: Programming Language :: Python :: 3.3
|
|
27
25
|
Classifier: Programming Language :: Python :: 3.4
|
|
28
26
|
Classifier: Programming Language :: Python :: 3.5
|
|
27
|
+
Classifier: Programming Language :: Python :: 3.6
|
|
29
28
|
Classifier: Topic :: Office/Business
|
|
30
29
|
Classifier: Topic :: Utilities
|
|
30
|
+
License-File: LICENSE
|
|
31
|
+
|
|
32
|
+
UNKNOWN
|
|
33
|
+
|
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
LICENSE
|
|
2
2
|
MANIFEST.in
|
|
3
3
|
README.md
|
|
4
|
-
md2pdf
|
|
5
4
|
requirements-dev.txt
|
|
6
5
|
requirements.txt
|
|
7
6
|
setup.cfg
|
|
8
7
|
setup.py
|
|
9
8
|
md2pdf/__init__.py
|
|
9
|
+
md2pdf/__main__.py
|
|
10
10
|
md2pdf/core.py
|
|
11
11
|
md2pdf/exceptions.py
|
|
12
|
-
md2pdf/tests.py
|
|
13
12
|
md2pdf.egg-info/PKG-INFO
|
|
14
13
|
md2pdf.egg-info/SOURCES.txt
|
|
15
14
|
md2pdf.egg-info/dependency_links.txt
|
|
15
|
+
md2pdf.egg-info/entry_points.txt
|
|
16
16
|
md2pdf.egg-info/requires.txt
|
|
17
17
|
md2pdf.egg-info/top_level.txt
|
|
18
|
-
|
|
18
|
+
tests/__init__.py
|
|
19
|
+
tests/defaults.py
|
|
20
|
+
tests/test_cli.py
|
|
21
|
+
tests/test_core.py
|
md2pdf-0.6/setup.cfg
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
[bdist_wheel]
|
|
2
|
+
universal = 1
|
|
3
|
+
|
|
4
|
+
[aliases]
|
|
5
|
+
test = pytest
|
|
6
|
+
|
|
7
|
+
[tool:pytest]
|
|
8
|
+
addopts = -vs --cov=md2pdf --cov-report term-missing tests/
|
|
9
|
+
|
|
10
|
+
[options.entry_points]
|
|
11
|
+
console_scripts = md2pdf = md2pdf.__main__:main
|
|
12
|
+
|
|
13
|
+
[flake8]
|
|
14
|
+
exclude =
|
|
15
|
+
.git,
|
|
16
|
+
.tox,
|
|
17
|
+
__pycache__,
|
|
18
|
+
assets,
|
|
19
|
+
build,
|
|
20
|
+
dist,
|
|
21
|
+
venv,
|
|
22
|
+
|
|
23
|
+
[egg_info]
|
|
24
|
+
tag_build =
|
|
25
|
+
tag_date = 0
|
|
26
|
+
|
md2pdf-0.6/setup.py
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
md2pdf - setup file
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import md2pdf
|
|
8
|
+
|
|
9
|
+
from setuptools import setup, find_packages
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def parse_requirements(requirements, ignore=('setuptools',)):
|
|
13
|
+
"""
|
|
14
|
+
Read dependencies from requirements file (with version numbers if any)
|
|
15
|
+
|
|
16
|
+
Notes:
|
|
17
|
+
- this implementation does not support requirements files with extra
|
|
18
|
+
requirements
|
|
19
|
+
- this implementation has been taken from TailorDev/Watson's setup file
|
|
20
|
+
"""
|
|
21
|
+
with open(requirements) as f:
|
|
22
|
+
packages = set()
|
|
23
|
+
for line in f:
|
|
24
|
+
line = line.strip()
|
|
25
|
+
if line.startswith(('#', '-r', '--')):
|
|
26
|
+
continue
|
|
27
|
+
if '#egg=' in line:
|
|
28
|
+
line = line.split('#egg=')[1]
|
|
29
|
+
pkg = line.strip()
|
|
30
|
+
if pkg not in ignore:
|
|
31
|
+
packages.add(pkg)
|
|
32
|
+
return list(packages)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
setup(
|
|
36
|
+
name='md2pdf',
|
|
37
|
+
version=md2pdf.__version__,
|
|
38
|
+
packages=find_packages(),
|
|
39
|
+
install_requires=parse_requirements('requirements.txt'),
|
|
40
|
+
setup_requires=['pytest-runner', ],
|
|
41
|
+
tests_require=parse_requirements('requirements-dev.txt'),
|
|
42
|
+
author='Julien Maupetit',
|
|
43
|
+
author_email='julien@maupetit.net',
|
|
44
|
+
description='md2pdf, a Markdown to PDF conversion tool',
|
|
45
|
+
license='MIT',
|
|
46
|
+
keywords='markdown converter css pdf',
|
|
47
|
+
classifiers=[
|
|
48
|
+
'Development Status :: 5 - Production/Stable',
|
|
49
|
+
'Intended Audience :: Customer Service',
|
|
50
|
+
'Intended Audience :: End Users/Desktop',
|
|
51
|
+
'Intended Audience :: Information Technology',
|
|
52
|
+
'Intended Audience :: Science/Research',
|
|
53
|
+
'Intended Audience :: Other Audience',
|
|
54
|
+
'License :: OSI Approved :: MIT License',
|
|
55
|
+
'Environment :: Console',
|
|
56
|
+
'Operating System :: MacOS',
|
|
57
|
+
'Operating System :: Microsoft :: Windows',
|
|
58
|
+
'Operating System :: POSIX',
|
|
59
|
+
'Programming Language :: Python :: 2',
|
|
60
|
+
'Programming Language :: Python :: 2.7',
|
|
61
|
+
'Programming Language :: Python :: 3',
|
|
62
|
+
'Programming Language :: Python :: 3.4',
|
|
63
|
+
'Programming Language :: Python :: 3.5',
|
|
64
|
+
'Programming Language :: Python :: 3.6',
|
|
65
|
+
'Topic :: Office/Business',
|
|
66
|
+
'Topic :: Utilities',
|
|
67
|
+
],
|
|
68
|
+
)
|
|
File without changes
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
from __future__ import unicode_literals
|
|
3
|
+
|
|
4
|
+
from os import remove
|
|
5
|
+
from os.path import exists
|
|
6
|
+
from subprocess import PIPE, Popen
|
|
7
|
+
|
|
8
|
+
from .defaults import INPUT_CSS, INPUT_MD, OUTPUT_PDF
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def setup_function(function):
|
|
12
|
+
"""Remove temporary PDF files"""
|
|
13
|
+
|
|
14
|
+
if exists(OUTPUT_PDF):
|
|
15
|
+
remove(OUTPUT_PDF)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _run(cmd):
|
|
19
|
+
"""Run cmd in a shell"""
|
|
20
|
+
|
|
21
|
+
p = Popen(
|
|
22
|
+
cmd,
|
|
23
|
+
shell=True,
|
|
24
|
+
stdin=PIPE,
|
|
25
|
+
stdout=PIPE,
|
|
26
|
+
stderr=PIPE,
|
|
27
|
+
universal_newlines=True,
|
|
28
|
+
close_fds=True
|
|
29
|
+
)
|
|
30
|
+
return p.communicate()
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def test_print_usage_when_no_args():
|
|
34
|
+
|
|
35
|
+
stdout, stderr = _run('md2pdf')
|
|
36
|
+
expected = 'Usage: md2pdf [options] INPUT.MD OUTPUT.PDF'
|
|
37
|
+
assert expected in stderr
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def test_print_usage_when_partial_args():
|
|
41
|
+
|
|
42
|
+
stdout, stderr = _run('md2pdf input.md')
|
|
43
|
+
expected = 'Usage: md2pdf [options] INPUT.MD OUTPUT.PDF'
|
|
44
|
+
assert expected in stderr
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def test_raise_IOError_when_markdown_input_file_does_not_exists():
|
|
48
|
+
|
|
49
|
+
cmd = 'md2pdf input.md output.pdf'
|
|
50
|
+
stdout, stderr = _run(cmd)
|
|
51
|
+
|
|
52
|
+
expected = '[Errno 2] No such file or directory: \'input.md\''
|
|
53
|
+
assert expected in stderr
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def test_raise_IOError_when_stylesheet_does_not_exists():
|
|
57
|
+
|
|
58
|
+
cmd = 'md2pdf --css=styles.css {} {}'.format(INPUT_MD, OUTPUT_PDF)
|
|
59
|
+
stdout, stderr = _run(cmd)
|
|
60
|
+
|
|
61
|
+
expected = '[Errno 2] No such file or directory: \'styles.css\''
|
|
62
|
+
assert expected in stderr
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def test_generate_pdf_from_markdown_source_file():
|
|
66
|
+
|
|
67
|
+
assert not exists(OUTPUT_PDF)
|
|
68
|
+
|
|
69
|
+
cmd = 'md2pdf {} {}'.format(INPUT_MD, OUTPUT_PDF)
|
|
70
|
+
stdout, stderr = _run(cmd)
|
|
71
|
+
assert exists(OUTPUT_PDF)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def test_generate_pdf_from_markdown_source_file_and_stylesheet():
|
|
75
|
+
|
|
76
|
+
assert not exists(OUTPUT_PDF)
|
|
77
|
+
|
|
78
|
+
cmd = 'md2pdf --css {} {} {}'.format(INPUT_CSS, INPUT_MD, OUTPUT_PDF)
|
|
79
|
+
stdout, stderr = _run(cmd)
|
|
80
|
+
assert exists(OUTPUT_PDF)
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
import pytest
|
|
3
|
+
|
|
4
|
+
from os import remove
|
|
5
|
+
from os.path import exists
|
|
6
|
+
|
|
7
|
+
from md2pdf import md2pdf
|
|
8
|
+
from md2pdf.exceptions import ValidationError
|
|
9
|
+
|
|
10
|
+
from .defaults import OUTPUT_PDF
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def setup_function(function):
|
|
14
|
+
"""Remove temporary PDF files"""
|
|
15
|
+
|
|
16
|
+
if exists(OUTPUT_PDF):
|
|
17
|
+
remove(OUTPUT_PDF)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def test_generate_pdf_from_raw_markdown():
|
|
21
|
+
|
|
22
|
+
assert not exists(OUTPUT_PDF)
|
|
23
|
+
|
|
24
|
+
md2pdf(OUTPUT_PDF, md_content='# hi there!')
|
|
25
|
+
assert exists(OUTPUT_PDF)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def test_raises_a_validation_error_when_generated_html_is_empty():
|
|
29
|
+
|
|
30
|
+
with pytest.raises(ValidationError):
|
|
31
|
+
md2pdf(OUTPUT_PDF)
|
md2pdf-0.4/README.md
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-

|
|
2
|
-
|
|
3
|
-
Convert Markdown files to PDF with styles.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
Clone this project first and install it with its dependencies (ideally in a
|
|
8
|
-
virtualenv, see the [virtualenvwrapper project
|
|
9
|
-
documentation](http://virtualenvwrapper.readthedocs.org/en/latest/index.html))
|
|
10
|
-
by typing:
|
|
11
|
-
|
|
12
|
-
```bash
|
|
13
|
-
$ python setup.py install
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
### Troubleshooting on MacOSX
|
|
17
|
-
|
|
18
|
-
Ensure, Weasyprint is fully functionnal before using md2pdf. You will find
|
|
19
|
-
installation instructions in the project documentation:
|
|
20
|
-
[http://weasyprint.org/docs/install/](http://weasyprint.org/docs/install/#mac-os-x)
|
|
21
|
-
|
|
22
|
-
In a few words, here are the few steps you will need to follow:
|
|
23
|
-
|
|
24
|
-
* Install XQuartz from:
|
|
25
|
-
[https://xquartz.macosforge.org](https://xquartz.macosforge.org)
|
|
26
|
-
* Install all dependencies at once with
|
|
27
|
-
[homebrew](http://mxcl.github.io/homebrew/) and go grab a coffee (this may
|
|
28
|
-
take a while):
|
|
29
|
-
|
|
30
|
-
```bash
|
|
31
|
-
$ brew install cairo pango gdk-pixbuf libxml2 libxslt libffi
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
## Usage
|
|
35
|
-
|
|
36
|
-
### As a CLI
|
|
37
|
-
|
|
38
|
-
```
|
|
39
|
-
Usage:
|
|
40
|
-
md2pdf [options] INPUT.MD OUTPUT.PDF
|
|
41
|
-
|
|
42
|
-
Options:
|
|
43
|
-
--css=STYLE.CSS
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
For example, try to generate the project documentation with:
|
|
47
|
-
|
|
48
|
-
```bash
|
|
49
|
-
$ md2pdf README.md README.pdf
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
Optionnaly, you may load an external style (restricted to CSS2):
|
|
53
|
-
|
|
54
|
-
```bash
|
|
55
|
-
$ md2pdf README.md README.pdf --css markdown-css-themes/markdown2.css
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
For testing purpose, I defined
|
|
59
|
-
[markdown-css-themes](https://github.com/jasonm23/markdown-css-themes) as a git
|
|
60
|
-
submodule. If you want to test this css resource, type:
|
|
61
|
-
|
|
62
|
-
```bash
|
|
63
|
-
$ git submodule init
|
|
64
|
-
$ git submodule update
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
### As a library
|
|
68
|
-
|
|
69
|
-
You can use md2pdf in your python code, like:
|
|
70
|
-
|
|
71
|
-
```python
|
|
72
|
-
from md2pdf.core import md2pdf
|
|
73
|
-
|
|
74
|
-
md2pdf(pdf_file_path,
|
|
75
|
-
md_content=None,
|
|
76
|
-
md_file_path=None,
|
|
77
|
-
css_file_path=None,
|
|
78
|
-
base_url=None)
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
See the
|
|
82
|
-
[md2pdf](https://github.com/jmaupetit/md2pdf/blob/master/md2pdf/core.py#L15)
|
|
83
|
-
function's documentation for details.
|
|
84
|
-
|
|
85
|
-
### With Docker
|
|
86
|
-
|
|
87
|
-
Install [Docker](https://www.docker.com/)
|
|
88
|
-
|
|
89
|
-
Pull the image
|
|
90
|
-
|
|
91
|
-
```bash
|
|
92
|
-
$ docker pull jmaupetit/md2pdf
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
Now run your image:
|
|
96
|
-
|
|
97
|
-
```bash
|
|
98
|
-
$ docker run --rm -v $PWD:/srv jmaupetit/md2pdf --css styles.css INPUT.MD OUTPUT.PDF
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
## Misc
|
|
102
|
-
|
|
103
|
-
### Using custom fonts in styles
|
|
104
|
-
|
|
105
|
-
WeasyPrint does not support the `@font-face` property yet (see [project issue
|
|
106
|
-
28](https://github.com/Kozea/WeasyPrint/issues/28)). If you use want to use
|
|
107
|
-
custom fonts, you should use system fonts and define them with the `font-family`
|
|
108
|
-
CSS property, like:
|
|
109
|
-
|
|
110
|
-
```css
|
|
111
|
-
font-family: 'Neutraface Condensed';
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
Note that you should only define **one single** custom font, not a substitution
|
|
115
|
-
list.
|
md2pdf-0.4/md2pdf/__init__.py
DELETED
md2pdf-0.4/md2pdf/tests.py
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
|
|
3
|
-
import unittest
|
|
4
|
-
from md2pdf.core import md2pdf
|
|
5
|
-
from md2pdf.exceptions import ValidationError
|
|
6
|
-
|
|
7
|
-
class TestMarkdownToPDF(unittest.TestCase):
|
|
8
|
-
|
|
9
|
-
def test_md2pdf(self):
|
|
10
|
-
|
|
11
|
-
# no markdown content should raise a ValidationError
|
|
12
|
-
self.assertRaises(ValidationError, md2pdf, 'foo.pdf')
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if __name__ == '__main__':
|
|
16
|
-
unittest.main()
|
md2pdf-0.4/setup.cfg
DELETED
md2pdf-0.4/setup.py
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python
|
|
2
|
-
# -*- coding: utf-8 -*-
|
|
3
|
-
"""
|
|
4
|
-
md2pdf - setup file
|
|
5
|
-
"""
|
|
6
|
-
|
|
7
|
-
import md2pdf
|
|
8
|
-
|
|
9
|
-
from setuptools import setup, find_packages
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
def parse_requirements(requirements, ignore=('setuptools',)):
|
|
13
|
-
"""
|
|
14
|
-
Read dependencies from requirements file (with version numbers if any)
|
|
15
|
-
|
|
16
|
-
Notes:
|
|
17
|
-
- this implementation does not support requirements files with extra
|
|
18
|
-
requirements
|
|
19
|
-
- this implementation has been taken from TailorDev/Watson's setup file
|
|
20
|
-
"""
|
|
21
|
-
with open(requirements) as f:
|
|
22
|
-
packages = set()
|
|
23
|
-
for line in f:
|
|
24
|
-
line = line.strip()
|
|
25
|
-
if line.startswith(('#', '-r', '--')):
|
|
26
|
-
continue
|
|
27
|
-
if '#egg=' in line:
|
|
28
|
-
line = line.split('#egg=')[1]
|
|
29
|
-
pkg = line.strip()
|
|
30
|
-
if pkg not in ignore:
|
|
31
|
-
packages.add(pkg)
|
|
32
|
-
return packages
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
setup(
|
|
36
|
-
name = 'md2pdf',
|
|
37
|
-
version = md2pdf.__version__,
|
|
38
|
-
packages = find_packages(),
|
|
39
|
-
scripts = ['scripts/md2pdf',],
|
|
40
|
-
install_requires=parse_requirements('requirements.txt'),
|
|
41
|
-
tests_require=parse_requirements('requirements-dev.txt'),
|
|
42
|
-
author = 'Julien Maupetit',
|
|
43
|
-
author_email = 'julien@maupetit.net',
|
|
44
|
-
description = "md2pdf, a Markdown to PDF conversion tool",
|
|
45
|
-
license = 'MIT',
|
|
46
|
-
keywords='markdown converter css pdf',
|
|
47
|
-
classifiers=[
|
|
48
|
-
"Development Status :: 5 - Production/Stable",
|
|
49
|
-
"Intended Audience :: Customer Service",
|
|
50
|
-
"Intended Audience :: End Users/Desktop",
|
|
51
|
-
"Intended Audience :: Information Technology",
|
|
52
|
-
"Intended Audience :: Science/Research",
|
|
53
|
-
"Intended Audience :: Other Audience",
|
|
54
|
-
"License :: OSI Approved :: MIT License",
|
|
55
|
-
"Environment :: Console",
|
|
56
|
-
"Operating System :: MacOS",
|
|
57
|
-
"Operating System :: Microsoft :: Windows",
|
|
58
|
-
"Operating System :: POSIX",
|
|
59
|
-
"Programming Language :: Python :: 2",
|
|
60
|
-
"Programming Language :: Python :: 2.7",
|
|
61
|
-
"Programming Language :: Python :: 3",
|
|
62
|
-
"Programming Language :: Python :: 3.3",
|
|
63
|
-
"Programming Language :: Python :: 3.4",
|
|
64
|
-
"Programming Language :: Python :: 3.5",
|
|
65
|
-
"Topic :: Office/Business",
|
|
66
|
-
"Topic :: Utilities",
|
|
67
|
-
],
|
|
68
|
-
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|