Merge branch 'master' into documentation
This commit is contained in:
commit
73eb9df7a8
7 changed files with 35 additions and 10 deletions
|
@ -4,6 +4,9 @@ machine:
|
|||
node:
|
||||
version: 6.10.2
|
||||
|
||||
general:
|
||||
artifacts:
|
||||
- test-files/out/
|
||||
|
||||
dependencies:
|
||||
pre:
|
||||
|
@ -19,4 +22,5 @@ test:
|
|||
- flake8 md_pdf/ --ignore=E128,E501
|
||||
- safety check
|
||||
- bandit -r md_pdf/
|
||||
- mdp --help
|
||||
- mdp --update-csl
|
||||
- cd test-files/ && mdp -vvv
|
||||
|
|
|
@ -6,4 +6,17 @@ body.cover {
|
|||
padding-top: 400px;
|
||||
font-size: 48px;
|
||||
}
|
||||
|
||||
& h3 {
|
||||
font-size: 36px;
|
||||
}
|
||||
|
||||
& h4 {
|
||||
font-size: 18px;
|
||||
}
|
||||
}
|
||||
|
||||
body, html {
|
||||
line-height: 1.5;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
|
|
@ -7,6 +7,9 @@ import logging
|
|||
logger = logging.getLogger(__file__)
|
||||
|
||||
|
||||
DEFAULT_MARGIN_VERTICAL = '1.5cm'
|
||||
DEFAULT_MARGIN_HORIZONTAL = '2.5cm'
|
||||
|
||||
STYLE_FILE = os.path.join(STATIC_DIR, 'style.css')
|
||||
HEADER_FILE = os.path.join(TEMPLATES_DIR, 'header.html')
|
||||
FOOTER_FILE = os.path.join(TEMPLATES_DIR, 'footer.html')
|
||||
|
@ -14,11 +17,6 @@ PDF_OPTIONS = {
|
|||
"quiet": "",
|
||||
"no-pdf-compression": "",
|
||||
|
||||
"margin-top": '0.6in',
|
||||
"margin-bottom": '0.6in',
|
||||
"margin-left": '0.4in',
|
||||
"margin-right": '0.4in',
|
||||
|
||||
"header-html": HEADER_FILE,
|
||||
"footer-html": FOOTER_FILE,
|
||||
"footer-spacing": 5,
|
||||
|
@ -31,6 +29,12 @@ PDF_OPTIONS = {
|
|||
def export_pdf(content, config):
|
||||
PDF_OPTIONS['title'] = config.get('title', 'Output')
|
||||
PDF_OPTIONS['replace'] = [(key, str(value)) for key, value in config['context'].items()]
|
||||
|
||||
PDF_OPTIONS['margin-top'] = config['context'].get('margin_vertical', DEFAULT_MARGIN_VERTICAL)
|
||||
PDF_OPTIONS['margin-bottom'] = config['context'].get('margin_vertical', DEFAULT_MARGIN_VERTICAL)
|
||||
PDF_OPTIONS['margin-left'] = config['context'].get('margin_horizontal', DEFAULT_MARGIN_HORIZONTAL)
|
||||
PDF_OPTIONS['margin-right'] = config['context'].get('margin_horizontal', DEFAULT_MARGIN_HORIZONTAL)
|
||||
|
||||
logger.info("Rendering PDF...")
|
||||
return pdfkit.from_string(
|
||||
content,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import logging
|
||||
from md_pdf.args import parse_args
|
||||
from md_pdf.exceptions import PrematureExit, BaseException
|
||||
from md_pdf.exceptions import BaseException
|
||||
from md_pdf.logging import set_verbosity
|
||||
from md_pdf.build import build
|
||||
from md_pdf.config.read import load_config
|
||||
|
@ -19,8 +19,6 @@ def cli():
|
|||
config = load_config()
|
||||
validate_config(config)
|
||||
build(config)
|
||||
except PrematureExit:
|
||||
return 0
|
||||
except BaseException as e:
|
||||
logging.error(str(e))
|
||||
return 1
|
||||
|
|
|
@ -24,7 +24,8 @@ def check_required_keys(config):
|
|||
def test_output(config):
|
||||
abs_output_dir = os.path.abspath(config['output_dir'])
|
||||
if not os.path.isdir(abs_output_dir):
|
||||
raise ConfigValidationException("Can't find output directory '{}'".format(abs_output_dir))
|
||||
logger.debug("Creating output directory...")
|
||||
os.mkdir(abs_output_dir)
|
||||
invalid_formats = [key for key in config['output_formats'] if key not in ['html', 'pdf']]
|
||||
if invalid_formats:
|
||||
raise ConfigValidationException("Invalid output formats provided: '{}'".format(", ".join(invalid_formats)))
|
||||
|
|
|
@ -26,6 +26,8 @@ def download_csl():
|
|||
remove_dir(CSL_DIR)
|
||||
|
||||
def download_handle(count, block_size, total_size):
|
||||
if total_size < 1: # only update the bar if we have a size
|
||||
return
|
||||
bar.update(int(count * block_size * 100 / total_size))
|
||||
|
||||
_, download_location = tempfile.mkstemp()
|
||||
|
|
3
setup.py
3
setup.py
|
@ -4,6 +4,7 @@ from setuptools import setup, find_packages
|
|||
setup(
|
||||
name="md-pdf",
|
||||
version="1.0",
|
||||
use_scm_version=True,
|
||||
install_requires=[
|
||||
"beautifulsoup4==4.5.3",
|
||||
"jinja2==2.9.5",
|
||||
|
@ -13,8 +14,10 @@ setup(
|
|||
"pyscss==1.3.5",
|
||||
"PyYAML==3.12"
|
||||
],
|
||||
setup_requires=['setuptools_scm'],
|
||||
packages=find_packages(),
|
||||
include_package_data=True,
|
||||
zip_safe=False,
|
||||
entry_points="""
|
||||
[console_scripts]
|
||||
mdp=md_pdf.cli:cli
|
||||
|
|
Reference in a new issue