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/md_pdf/assets/static/style.scss b/md_pdf/assets/static/style.scss index 2295a1b..bf57eaa 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 { @@ -6,7 +7,7 @@ body.cover { text-align: center; & h1 { - padding-top: 400px; + padding-top: 300px; font-size: 48px; } @@ -22,17 +23,38 @@ body.cover { body.content { line-height: 1.5; - font-size: 12px; + font-size: $font-size-base; 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-before: always; + } + + h1, h2, h3, h4, h5, h6 { + page-break-after: avoid; + } +} + +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 9b988e4..fdf7715 100644 --- a/md_pdf/assets/templates/footer.html +++ b/md_pdf/assets/templates/footer.html @@ -4,9 +4,9 @@ - +
- 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)) diff --git a/md_pdf/build/pdf.py b/md_pdf/build/pdf.py index 60c6b4b..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,8 +15,8 @@ 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": "", "header-html": HEADER_FILE, "footer-html": FOOTER_FILE, @@ -27,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()] diff --git a/md_pdf/build/template.py b/md_pdf/build/template.py index b74a1d3..2d89308 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() @@ -20,8 +21,10 @@ 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'): + 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/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) 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] 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