From: Marcin Koziej Date: Mon, 3 Feb 2014 09:42:11 +0000 (+0100) Subject: for epubs, we zip all resources into OPS, not preserving tree structure — flattening... X-Git-Url: https://git.mdrn.pl/librarian.git/commitdiff_plain/0b542d0cbe6ab3bc6df1d3f29ffecfa15c14df5b?hp=607ea5393e3768f8b842b613b100a2fb62074f31 for epubs, we zip all resources into OPS, not preserving tree structure — flattening of paths is needed --- diff --git a/librarian/epub.py b/librarian/epub.py index 8dc11c7..de136ea 100644 --- a/librarian/epub.py +++ b/librarian/epub.py @@ -330,6 +330,12 @@ def transform_chunk(chunk_xml, chunk_no, annotations, empty=False, _empty_html_s return output_html, toc, chars +def flatten_image_paths(wldoc): + root = wldoc.edoc.getroot() + for node in root.findall(".//ilustr"): + node.attrib['src'] = os.path.basename(node.attrib['src']) + return wldoc + def render_latex(wldoc, prefix="latex"): """ Renders CODE as images and returns @@ -398,6 +404,8 @@ def transform(wldoc, verbose=False, if main_text.tag == RDFNS('RDF'): main_text = None + flatten_image_paths(wldoc) + if main_text is not None: for chunk_xml in chop(main_text): empty = False