From f23afa3c5375d2e9e6f176fe082b05513824fd90 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sat, 5 Oct 2019 23:54:26 +0200 Subject: [PATCH] Better management for font styles in http.webpage.simplify --- platypush/plugins/http/webpage/__init__.py | 44 +++++++++++++--------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/platypush/plugins/http/webpage/__init__.py b/platypush/plugins/http/webpage/__init__.py index ddf0f2c11c..82bd1e8f62 100644 --- a/platypush/plugins/http/webpage/__init__.py +++ b/platypush/plugins/http/webpage/__init__.py @@ -77,29 +77,37 @@ class HttpWebpagePlugin(Plugin): 'content': content, } - content = ''' - - - {title} - - - -

{title}

- {content} - - '''.format(title=title, content=content) - outfile = os.path.abspath(os.path.expanduser(outfile)) + content = '''

{title}

{content}
'''.\ + format(title=title, content=content) + + style = ''' + body { + font-size: 22px; + font-family: 'Merriweather', Georgia, 'Times New Roman', Times, serif; + } + ''' if outfile.lower().endswith('.pdf'): import weasyprint - weasyprint.HTML(string=content).write_pdf(outfile) + from weasyprint.fonts import FontConfiguration + + font_config = FontConfiguration() + css = [weasyprint.CSS('https://fonts.googleapis.com/css?family=Merriweather'), + weasyprint.CSS(string=style, font_config=font_config)] + + weasyprint.HTML(string=content).write_pdf(outfile, stylesheets=css) else: + content = ''' + + + {title} + + + {{content}} + + '''.format(title=title, style=style, content=content) + with open(outfile, 'w', encoding='utf-8') as f: f.write(content)