Add swappable CSS for HTML previews.
authorRadek Czajka <rczajka@rczajka.pl>
Wed, 12 Feb 2020 12:30:24 +0000 (13:30 +0100)
committerRadek Czajka <rczajka@rczajka.pl>
Wed, 12 Feb 2020 12:30:24 +0000 (13:30 +0100)
librarian/html.py
librarian/xslt/book2html.xslt
scripts/book2html

index ed7b4d6..096e399 100644 (file)
@@ -45,7 +45,7 @@ def transform_abstrakt(abstrakt_element):
     return re.sub('</?blockquote[^>]*>', '', html)
 
 
     return re.sub('</?blockquote[^>]*>', '', html)
 
 
-def transform(wldoc, stylesheet='legacy', options=None, flags=None):
+def transform(wldoc, stylesheet='legacy', options=None, flags=None, css=None):
     """Transforms the WL document to XHTML.
 
     If output_filename is None, returns an XML,
     """Transforms the WL document to XHTML.
 
     If output_filename is None, returns an XML,
@@ -71,7 +71,10 @@ def transform(wldoc, stylesheet='legacy', options=None, flags=None):
         if not options:
             options = {}
         options.setdefault('gallery', "''")
         if not options:
             options = {}
         options.setdefault('gallery', "''")
-        result = document.transform(style, **options)
+
+        css = css or 'https://static.wolnelektury.pl/css/compressed/book_text.css'
+        css = "'%s'" % css
+        result = document.transform(style, css=css, **options)
         del document  # no longer needed large object :)
 
         if html_has_content(result):
         del document  # no longer needed large object :)
 
         if html_has_content(result):
index e670fb0..3b094ac 100644 (file)
                 <title>Książka z serwisu WolneLektury.pl</title>
                <meta charset="utf-8" />
                <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
                 <title>Książka z serwisu WolneLektury.pl</title>
                <meta charset="utf-8" />
                <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
-               <link href="https://static.wolnelektury.pl/css/compressed/book_text.css" rel="stylesheet" type="text/css" />
-               <style>
-                 .animacja {cursor: pointer;}
-               </style>
+               <link rel="stylesheet" type="text/css">
+                       <xsl:attribute name="href">
+                               <xsl:value-of select="$css" />
+                       </xsl:attribute>
+               </link>
            </head>
             <body>
               <xsl:call-template name="book-text" />
            </head>
             <body>
               <xsl:call-template name="book-text" />
index f6d459d..02d542c 100755 (executable)
@@ -19,6 +19,9 @@ class Book2Html(Book2Anything):
                 action='store_false', default=True,
                 help='output raw text for use in templates')
     ]
                 action='store_false', default=True,
                 help='output raw text for use in templates')
     ]
+    transform_options = [
+        Option('--css', dest='css')
+    ]
     parser_options = [
         Option('-i', '--ignore-dublin-core', dest='parse_dublincore', 
                 action='store_false', default=True,
     parser_options = [
         Option('-i', '--ignore-dublin-core', dest='parse_dublincore', 
                 action='store_false', default=True,