+
+ def merge_chunks(self, chunk_dict):
+ unmerged = []
+
+ for key, data in chunk_dict.iteritems():
+ try:
+ xpath = self.path_to_xpath(key)
+ node = self.edoc.xpath(xpath)[0]
+ repl = etree.fromstring(u"<%s>%s</%s>" %(node.tag, data, node.tag) )
+ node.getparent().replace(node, repl);
+ except Exception, e:
+ unmerged.append( repr( (key, xpath, e) ) )
+
+ return unmerged
+
+ def clean_ed_note(self):
+ """ deletes forbidden tags from nota_red """
+
+ for node in self.edoc.xpath('|'.join('//nota_red//%s' % tag for tag in
+ ('pa', 'pe', 'pr', 'pt', 'begin', 'end', 'motyw'))):
+ tail = node.tail
+ node.clear()
+ node.tag = 'span'
+ node.tail = tail
+
+ # Converters
+
+ def as_html(self, *args, **kwargs):
+ from librarian import html
+ return html.transform(self, *args, **kwargs)
+
+ def as_text(self, *args, **kwargs):
+ from librarian import text
+ return text.transform(self, *args, **kwargs)
+
+ def as_epub(self, *args, **kwargs):
+ from librarian import epub
+ return epub.transform(self, *args, **kwargs)
+
+ def as_pdf(self, *args, **kwargs):
+ from librarian import pdf
+ return pdf.transform(self, *args, **kwargs)
+
+ def as_mobi(self, *args, **kwargs):
+ from librarian import mobi
+ return mobi.transform(self, *args, **kwargs)
+
+ def save_output_file(self, output_file, output_path=None,
+ output_dir_path=None, make_author_dir=False, ext=None):
+ if output_dir_path:
+ save_path = output_dir_path
+ if make_author_dir:
+ save_path = os.path.join(save_path,
+ unicode(self.book_info.author).encode('utf-8'))
+ save_path = os.path.join(save_path,
+ self.book_info.uri.filename_stem())
+ if ext:
+ save_path += '.%s' % ext
+ else:
+ save_path = output_path
+
+ output_file.save_as(save_path)