+ def exit_fragment(self):
+ self.current_cursors.pop()
+
+ def create_fragment(self, name, element):
+ assert name not in self.cursors
+ self.cursors[name] = element
+
+ def forget_fragment(self, name):
+ del self.cursors[name]
+
+ def start_element(self, tag, attrib=None):
+ self.current_cursors.append(etree.SubElement(
+ self.cursor,
+ tag,
+ **(attrib or {})
+ ))
+
+ def end_element(self):
+ self.current_cursors.pop()
+
+ def push_text(self, text):
+ cursor = self.cursor
+ if len(cursor):
+ cursor[-1].tail = (cursor[-1].tail or '') + text
+ else:
+ cursor.text = (cursor.text or '') + text
+
+ def simple_element(self, tag, text='', attrib=None):
+ self.start_element(tag, attrib)
+ self.push_text(text)
+ self.end_element()
+
+
+class HtmlBuilder(TreeBuilder):
+ build_method_fn = 'html_build'
+ file_extension = "html"
+ with_themes = True
+ with_toc = True
+ with_footnotes = True
+ with_nota_red = True
+ with_ids = True
+ with_numbering = True
+ no_externalities = False
+ orphans = True
+
+ root_tag = 'div'
+ root_attrib = {'id': 'book-text'}
+
+ def __init__(self, gallery_path=None, gallery_url=None, base_url=None):
+ self._base_url = base_url
+ self.gallery_path = gallery_path
+ self.gallery_url = gallery_url
+
+ self.tree = text = etree.Element(self.root_tag, **self.root_attrib)
+ self.header = etree.Element('h1')