X-Git-Url: https://git.mdrn.pl/librarian.git/blobdiff_plain/4e329824f40367945de11d3647396859092f5c2c..1f8cf8e0244045ed2b2a8efcff5d6db967ac2b11:/librarian/html.py
diff --git a/librarian/html.py b/librarian/html.py
index 67f0061..f8e4a83 100644
--- a/librarian/html.py
+++ b/librarian/html.py
@@ -38,14 +38,14 @@ def html_has_content(text):
def transform_abstrakt(abstrakt_element):
style_filename = get_stylesheet('legacy')
style = etree.parse(style_filename)
- xml = etree.tostring(abstrakt_element)
- document = etree.parse(six.BytesIO(xml.replace('abstrakt', 'dlugi_cytat'))) # HACK
+ xml = etree.tostring(abstrakt_element, encoding='unicode')
+ document = etree.parse(six.StringIO(xml.replace('abstrakt', 'dlugi_cytat'))) # HACK
result = document.xslt(style)
- html = re.sub('', '', etree.tostring(result))
+ html = re.sub('', '', etree.tostring(result, encoding='unicode'))
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,
@@ -71,7 +71,10 @@ def transform(wldoc, stylesheet='legacy', options=None, flags=None):
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):
@@ -236,7 +239,7 @@ def add_anchors(root):
if any_ancestor(element, f):
continue
- if element.tag == 'p' and 'verse' in element.get('class', ''):
+ if element.tag == 'div' and 'verse' in element.get('class', ''):
if counter == 1 or counter % 5 == 0:
add_anchor(element, "f%d" % counter, link_text=counter)
counter += 1