From 490263f7cd1190141e4c760c8bfab6e98e485fed Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Wed, 5 Apr 2017 15:27:14 +0100 Subject: [PATCH] Allow scss styles --- .gitignore | 1 + md_pdf/assets/static/style.css | 9 --------- md_pdf/assets/static/style.scss | 10 ++++++++++ md_pdf/build/__init__.py | 2 ++ md_pdf/build/css.py | 17 +++++++++++++++++ setup.py | 1 + 6 files changed, 31 insertions(+), 9 deletions(-) delete mode 100644 md_pdf/assets/static/style.css create mode 100644 md_pdf/assets/static/style.scss create mode 100644 md_pdf/build/css.py diff --git a/.gitignore b/.gitignore index b43b745..0a8eff8 100644 --- a/.gitignore +++ b/.gitignore @@ -89,5 +89,6 @@ ENV/ out/ md_pdf/assets/templates/cover.html +md_pdf/assets/static/style.css md_pdf/assets/csl/ md_pdf/assets/styles-master/ diff --git a/md_pdf/assets/static/style.css b/md_pdf/assets/static/style.css deleted file mode 100644 index 5c81e76..0000000 --- a/md_pdf/assets/static/style.css +++ /dev/null @@ -1,9 +0,0 @@ -body.cover { - margin: 0 auto; - text-align: center; -} - -body.cover h1 { - font-size: 48px; - padding-top: 400px; -} diff --git a/md_pdf/assets/static/style.scss b/md_pdf/assets/static/style.scss new file mode 100644 index 0000000..5025637 --- /dev/null +++ b/md_pdf/assets/static/style.scss @@ -0,0 +1,10 @@ +body.cover { + margin: 0 auto; + text-align: center; + + & h1 { + font-size: 48px; + padding-top: 400px; + + } +} diff --git a/md_pdf/build/__init__.py b/md_pdf/build/__init__.py index 2774aab..ab4ffd6 100644 --- a/md_pdf/build/__init__.py +++ b/md_pdf/build/__init__.py @@ -1,6 +1,7 @@ from md_pdf.build.md import read_files from md_pdf.build.pandoc import build_document, output_html from md_pdf.build.cover import render_cover +from md_pdf.build.css import render_css from md_pdf.build.pdf import export_pdf import os import logging @@ -16,4 +17,5 @@ def build(config): output_html(doc, os.path.abspath(config['output_dir'])) if 'pdf' in config['output_formats']: render_cover(config) + render_css() export_pdf(doc, config) diff --git a/md_pdf/build/css.py b/md_pdf/build/css.py new file mode 100644 index 0000000..0843923 --- /dev/null +++ b/md_pdf/build/css.py @@ -0,0 +1,17 @@ +from scss import Compiler +from md_pdf.consts import STATIC_DIR +from md_pdf.build.pdf import STYLE_FILE +import os + + +STYLE_SRC_FILE = os.path.join(STATIC_DIR, 'style.scss') + + +def render_css(): + compiler = Compiler() + with open(STYLE_SRC_FILE) as f: + style = f.read() + with open(STYLE_FILE, 'w') as f: + data = compiler.compile_string(style) + f.write(data) + return data diff --git a/setup.py b/setup.py index 55b1fee..a357cdc 100644 --- a/setup.py +++ b/setup.py @@ -10,6 +10,7 @@ setup( "pdfkit==0.6.1", "progressbar2==3.16.0", "pypandoc==1.3.3", + "pyscss==1.3.5", "PyYAML==3.12" ], entry_points="""