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