aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorGertjan van den Burg <gertjanvandenburg@gmail.com>2020-12-27 13:47:40 +0000
committerGertjan van den Burg <gertjanvandenburg@gmail.com>2020-12-27 13:47:40 +0000
commit948d314b47be221f7694a793c964d4728212c33c (patch)
tree6135afbcab009f1f6b22b4bcfec293ff07a25827 /tests
parentMerge branch 'savagej-patch-1' (diff)
downloadpaper2remarkable-948d314b47be221f7694a793c964d4728212c33c.tar.gz
paper2remarkable-948d314b47be221f7694a793c964d4728212c33c.zip
Add support for custom styling of HTML output
Diffstat (limited to 'tests')
-rw-r--r--tests/test_html.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/test_html.py b/tests/test_html.py
index d271bb5..7d5c92b 100644
--- a/tests/test_html.py
+++ b/tests/test_html.py
@@ -7,6 +7,9 @@ This file is part of paper2remarkable.
"""
+import os
+import pdfplumber
+import tempfile
import unittest
from paper2remarkable.providers.html import HTML
@@ -24,6 +27,38 @@ class TestHTML(unittest.TestCase):
expected_image = "https://www.seriouseats.com/images/2015/01/20150118-tea-max-falkowitz-3.jpg"
self.assertIn(expected_image, html_article)
+ def test_custom_css(self):
+ test_css = """
+ @page { size: 702px 936px; margin: 1in; }
+ img { display: block; margin: 0 auto; text-align: center; max-width: 70%; max-height: 300px; }
+ h1,h2,h3 { font-family: 'Montserrat'; }
+ p, li { font-size: 12pt; line-height: 2; font-family: 'Montserrat'; text-align: left; }
+ """
+
+ test_font_urls = [
+ "https://fonts.googleapis.com/css2?family=Montserrat&display=swap"
+ ]
+
+ tmpfd, tempfname_css = tempfile.mkstemp(prefix="p2r_", suffix=".css")
+ with os.fdopen(tmpfd, "w") as fp:
+ fp.write(test_css)
+
+ tmpfd, tempfname_urls = tempfile.mkstemp(prefix="p2r_", suffix=".txt")
+ with os.fdopen(tmpfd, "w") as fp:
+ fp.write("\n".join(test_font_urls))
+
+ url = "https://hbr.org/2019/11/getting-your-team-to-do-more-than-meet-deadlines"
+ prov = HTML(
+ upload=False, css_path=tempfname_css, font_urls_path=tempfname_urls
+ )
+ filename = prov.run(url)
+ with pdfplumber.open(filename) as pdf:
+ self.assertEqual(8, len(pdf.pages))
+
+ os.unlink(tempfname_css)
+ os.unlink(tempfname_urls)
+ os.unlink(filename)
+
if __name__ == "__main__":
unittest.main()