From a072017525be0a0685b210edc2326a2d71906a1d Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Wed, 10 May 2017 20:52:00 +0100 Subject: [PATCH 01/10] Add page breaks when needed --- md_pdf/assets/static/style.scss | 9 +++++++++ md_pdf/build/template.py | 1 + 2 files changed, 10 insertions(+) diff --git a/md_pdf/assets/static/style.scss b/md_pdf/assets/static/style.scss index 2295a1b..904d81f 100644 --- a/md_pdf/assets/static/style.scss +++ b/md_pdf/assets/static/style.scss @@ -27,12 +27,21 @@ body.content { img { margin-top: $image-spacing; width: 100%; + page-break-after: avoid; } p.caption { margin: 1px 5px $image-spacing; padding: 0; font-style: italic; + page-break-before: avoid; } + .references-title { + page-break-after: avoid; + } + + h1, h2, h3, h4, h5, h6 { + page-break-after: avoid; + } } diff --git a/md_pdf/build/template.py b/md_pdf/build/template.py index b74a1d3..1802e41 100644 --- a/md_pdf/build/template.py +++ b/md_pdf/build/template.py @@ -12,6 +12,7 @@ def fix_references_title(content, config): reference_element = soup.find('div', class_='references') if reference_element is not None: title = soup.new_tag('h1') + title['class'] = 'references-title' title.string = "References" reference_element.insert_before(title) return soup.prettify() From bc95f592ab3055e4c7cca615e44578e64366af46 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Wed, 10 May 2017 20:56:57 +0100 Subject: [PATCH 02/10] Set footer font size --- md_pdf/assets/static/style.scss | 7 ++++++- md_pdf/assets/templates/footer.html | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/md_pdf/assets/static/style.scss b/md_pdf/assets/static/style.scss index 904d81f..3ef6a56 100644 --- a/md_pdf/assets/static/style.scss +++ b/md_pdf/assets/static/style.scss @@ -1,4 +1,5 @@ $image-spacing: 30px; +$font-size-base: 12px; body.cover { @@ -22,7 +23,7 @@ body.cover { body.content { line-height: 1.5; - font-size: 12px; + font-size: $font-size-base; img { margin-top: $image-spacing; @@ -45,3 +46,7 @@ body.content { page-break-after: avoid; } } + +body.footer { + font-size: $font-size-base; +} diff --git a/md_pdf/assets/templates/footer.html b/md_pdf/assets/templates/footer.html index 9b988e4..dc4ecf2 100644 --- a/md_pdf/assets/templates/footer.html +++ b/md_pdf/assets/templates/footer.html @@ -6,7 +6,7 @@ - From f745ee5f0b624ffe8bba7ca9115f1f34f7093557 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Wed, 10 May 2017 21:42:03 +0100 Subject: [PATCH 03/10] Enable internal links --- md_pdf/build/pdf.py | 1 + md_pdf/build/template.py | 4 ++-- test-files/1intro.md | 2 ++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/md_pdf/build/pdf.py b/md_pdf/build/pdf.py index 60c6b4b..cc6dbbb 100644 --- a/md_pdf/build/pdf.py +++ b/md_pdf/build/pdf.py @@ -16,6 +16,7 @@ FOOTER_FILE = os.path.join(TEMPLATES_DIR, 'footer.html') PDF_OPTIONS = { "quiet": "", "no-pdf-compression": "", + "enable-internal-links": "", "header-html": HEADER_FILE, "footer-html": FOOTER_FILE, diff --git a/md_pdf/build/template.py b/md_pdf/build/template.py index 1802e41..15803b2 100644 --- a/md_pdf/build/template.py +++ b/md_pdf/build/template.py @@ -21,8 +21,8 @@ def fix_references_title(content, config): def add_base_tag(doc, config): logger.debug("Adding Base Tag...") soup = BeautifulSoup(doc, 'html.parser') - base_tag = soup.new_tag('base', href=os.path.abspath(config['output_dir'])) - soup.head.insert(0, base_tag) + for img in soup.findAll('img'): + img['src'] = os.path.abspath(img['src']) return soup.prettify() diff --git a/test-files/1intro.md b/test-files/1intro.md index d26cb43..f9d0d18 100644 --- a/test-files/1intro.md +++ b/test-files/1intro.md @@ -3,3 +3,5 @@ _Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam ante purus, scelerisque sed pulvinar eget, suscipit feugiat augue. Cras quis quam ac dui aliquam rhoncus eu id diam. Cras dapibus vel nunc in finibus. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Nulla a lacinia nibh. Aenean finibus mauris et est euismod aliquam. Curabitur dictum nulla quis turpis fringilla vestibulum at eget ligula. Donec et ultricies massa, ut volutpat neque. Praesent elementum ultrices urna at finibus. Nunc risus mi, porta sed eros sit amet, sagittis sollicitudin velit. Nulla a felis in tellus gravida pretium sit amet eget libero. Donec aliquet ac est semper molestie._ __Curabitur arcu velit, faucibus sed condimentum vitae, consectetur a lectus. Fusce a cursus magna. Nam vel posuere erat, in congue purus. Aliquam aliquet eu leo vel cursus. Vestibulum mattis est ac diam finibus, in aliquet erat iaculis. Phasellus est quam, rutrum a tempus non, vehicula vitae tellus. Nam nec leo consectetur, aliquam lorem eget, dignissim arcu. Phasellus vitae convallis urna, ac aliquet purus. Vivamus nisl mauris, volutpat quis pretium non, fringilla non dui. Pellentesque velit justo, pretium a porta nec, varius ac lacus.__ + +[reference](#test-image) From 5e76fab44bca89c745f689048a5a04d71c7213ab Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Wed, 10 May 2017 21:48:22 +0100 Subject: [PATCH 04/10] Add docs for inner linking --- docs/markdown.md | 11 +++++++++++ test-files/2-pandoc.md | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/docs/markdown.md b/docs/markdown.md index 46d456d..c5a14aa 100644 --- a/docs/markdown.md +++ b/docs/markdown.md @@ -12,3 +12,14 @@ Images take the same syntax as with standard markdown: Referencing files inside your project directory can be done with a path relative to the project directory. You can use images direct from online, however you'll need to be connected to the internet when generating. The title for the image is also used as the caption, and is displayed directly under the images. + + +### Linking +You can link to other parts of your document by their titles, in the same way linking to ids works on the web. + + +For example, if you had a title _Some Title_, then you can link to it like: + + [Click Here!](#some-title) + +__Note__: The header size doesnt matter. You link to an h4 tag the same as linking to an h1. diff --git a/test-files/2-pandoc.md b/test-files/2-pandoc.md index 08d5e36..e248668 100644 --- a/test-files/2-pandoc.md +++ b/test-files/2-pandoc.md @@ -1,4 +1,4 @@ - +### Referencing test - [@nonexistent] From 56ed7df6c09fa5ae7613dd572157f06eb31abb70 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Thu, 11 May 2017 08:46:38 +0100 Subject: [PATCH 05/10] Remove inline styles on footer --- md_pdf/assets/static/style.scss | 10 +++++++++- md_pdf/assets/templates/footer.html | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/md_pdf/assets/static/style.scss b/md_pdf/assets/static/style.scss index 3ef6a56..80e8e88 100644 --- a/md_pdf/assets/static/style.scss +++ b/md_pdf/assets/static/style.scss @@ -47,6 +47,14 @@ body.content { } } -body.footer { +body.footer, body.header { font-size: $font-size-base; + + table { + width: 100%; + + td { + text-align: center; + } + } } diff --git a/md_pdf/assets/templates/footer.html b/md_pdf/assets/templates/footer.html index dc4ecf2..fdf7715 100644 --- a/md_pdf/assets/templates/footer.html +++ b/md_pdf/assets/templates/footer.html @@ -4,9 +4,9 @@ -
+ Page of
+
- From b01532e7d31e2d1ecb51ee42854b4220c82b04d2 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Thu, 11 May 2017 08:52:02 +0100 Subject: [PATCH 06/10] Force references to new page --- md_pdf/assets/static/style.scss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/md_pdf/assets/static/style.scss b/md_pdf/assets/static/style.scss index 80e8e88..5d1cfc1 100644 --- a/md_pdf/assets/static/style.scss +++ b/md_pdf/assets/static/style.scss @@ -39,7 +39,7 @@ body.content { } .references-title { - page-break-after: avoid; + page-break-before: always; } h1, h2, h3, h4, h5, h6 { From 851a2157622a43a9ae838ccde1396351fe46cd7a Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Thu, 11 May 2017 09:00:40 +0100 Subject: [PATCH 07/10] show wkhtmltopdf output when logging verbose --- md_pdf/build/pdf.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/md_pdf/build/pdf.py b/md_pdf/build/pdf.py index cc6dbbb..12d7352 100644 --- a/md_pdf/build/pdf.py +++ b/md_pdf/build/pdf.py @@ -4,6 +4,7 @@ from md_pdf.build.cover import OUTPUT_COVER_FILE import os import logging + logger = logging.getLogger(__file__) @@ -14,7 +15,6 @@ 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') PDF_OPTIONS = { - "quiet": "", "no-pdf-compression": "", "enable-internal-links": "", @@ -28,6 +28,8 @@ PDF_OPTIONS = { def export_pdf(content, config): + if logger.getEffectiveLevel() > logging.DEBUG: + PDF_OPTIONS['quiet'] = "" PDF_OPTIONS['title'] = config.get('title', 'Output') PDF_OPTIONS['replace'] = [(key, str(value)) for key, value in config['context'].items()] From 6a4815ba774910253a75cc1ba555ab6f42c20978 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Thu, 11 May 2017 09:02:01 +0100 Subject: [PATCH 08/10] Move cover title up --- md_pdf/assets/static/style.scss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/md_pdf/assets/static/style.scss b/md_pdf/assets/static/style.scss index 5d1cfc1..bf57eaa 100644 --- a/md_pdf/assets/static/style.scss +++ b/md_pdf/assets/static/style.scss @@ -7,7 +7,7 @@ body.cover { text-align: center; & h1 { - padding-top: 400px; + padding-top: 300px; font-size: 48px; } From af8464e344c9d0337a2189a56abd71eb3688da34 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Thu, 11 May 2017 09:20:35 +0100 Subject: [PATCH 09/10] Add timer --- md_pdf/build/__init__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/md_pdf/build/__init__.py b/md_pdf/build/__init__.py index 3a34605..5b9f885 100644 --- a/md_pdf/build/__init__.py +++ b/md_pdf/build/__init__.py @@ -6,12 +6,14 @@ from md_pdf.build.pdf import export_pdf from md_pdf.build.template import parse_template import os import logging +import time logger = logging.getLogger(__file__) def build(config): logger.debug("Starting Build...") + start_time = time.time() data = read_files(os.path.abspath(config['input'])) doc = build_document(data, config.get('bibliography'), config.get('context')) parsed_template = parse_template(doc, config) @@ -21,3 +23,4 @@ def build(config): render_cover(config) render_css() export_pdf(parsed_template, config) + logger.info('Output completed in {:.2f} seconds.'.format(time.time() - start_time)) From 847b783ea3ece7378ea99573377f5f7052f14140 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Thu, 11 May 2017 13:19:14 +0100 Subject: [PATCH 10/10] Check / fix support for remote images --- md_pdf/build/template.py | 4 +++- test-files/3-image.md | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/md_pdf/build/template.py b/md_pdf/build/template.py index 15803b2..2d89308 100644 --- a/md_pdf/build/template.py +++ b/md_pdf/build/template.py @@ -22,7 +22,9 @@ def add_base_tag(doc, config): logger.debug("Adding Base Tag...") soup = BeautifulSoup(doc, 'html.parser') for img in soup.findAll('img'): - img['src'] = os.path.abspath(img['src']) + abs_path = os.path.abspath(img['src']) + if os.path.isfile(abs_path): + img['src'] = abs_path return soup.prettify() diff --git a/test-files/3-image.md b/test-files/3-image.md index 0716ec0..88c3a36 100644 --- a/test-files/3-image.md +++ b/test-files/3-image.md @@ -2,3 +2,6 @@ ![title](./test-image.png) + + +![Example remote image](http://image.spreadshirtmedia.com/image-server/v1/designs/11735885,width=178,height=178/TV-Test-Screen.png)
+ Page of