+ if len(self.header):
+ self.tree.insert(0, self.header)
+
+ if self.with_nota_red and len(self.nota_red):
+ self.tree.append(self.nota_red)
+ if self.with_themes:
+ add_table_of_themes(self.tree)
+ if self.with_toc:
+ add_table_of_contents(self.tree)
+
+ if len(self.footnotes):
+ fnheader = etree.Element("h3")
+ fnheader.text = _("Footnotes")
+ self.footnotes.insert(0, fnheader)
+ self.tree.append(self.footnotes)
+
+ def add_visible_number(self, element):
+ assert '_id' in element.attrib, etree.tostring(element)
+ self.start_element('a', {
+ 'href': f'#{element.attrib["_id"]}',
+ 'class': 'wl-num',
+ })
+ self.push_text(element.attrib['_visible_numbering'])
+ self.end_element()
+
+
+class StandaloneHtmlBuilder(HtmlBuilder):
+ css_url = "https://static.wolnelektury.pl/css/compressed/book_text.css"
+
+ def postprocess(self, document):
+ super(StandaloneHtmlBuilder, self).postprocess(document)
+
+ tree = etree.Element('html')
+ body = etree.SubElement(tree, 'body')
+ body.append(self.tree)
+ self.tree = tree
+
+ head = etree.Element('head')
+ tree.insert(0, head)
+
+ etree.SubElement(head, 'meta', charset='utf-8')
+ etree.SubElement(head, 'title').text = document.meta.title
+
+ etree.SubElement(
+ head,
+ 'meta',
+ name="viewport",
+ content="width=device-width, initial-scale=1, maximum-scale=1"
+ )
+
+ if self.no_externalities:
+ etree.SubElement(
+ head, 'style',
+ ).text = urlopen(self.css_url).read().decode('utf-8')