Fixed MathML in EPUB. 1.11.1
authorRadek Czajka <rczajka@rczajka.pl>
Fri, 18 Dec 2020 08:53:28 +0000 (09:53 +0100)
committerRadek Czajka <rczajka@rczajka.pl>
Fri, 18 Dec 2020 08:53:28 +0000 (09:53 +0100)
CHANGELOG.md
setup.py
src/librarian/epub.py
src/librarian/functions.py

index 521ef1c..322dba0 100644 (file)
@@ -3,6 +3,12 @@
 This document records all notable changes to Librarian.
 
 
+## 1.11.1 (2020-12-18)
+
+### Fixed
+- MathML in EPUBs.
+
+
 ## 1.11 (2020-12-09)
 
 ### Added
index 3a50c6c..dda645c 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -22,7 +22,7 @@ def whole_tree(prefix, path):
 
 setup(
     name='librarian',
-    version='1.11',
+    version='1.11.1',
     description='Converter from WolneLektury.pl XML-based language to XHTML, TXT and other formats',
     author="Marek StÄ™pniowski",
     author_email='marek@stepniowski.com',
index a8c6680..c286903 100644 (file)
@@ -553,7 +553,7 @@ def transform(wldoc, verbose=False, style=None,
 
     spine = output.spine
 
-    functions.reg_mathml_epub(zip)
+    functions.reg_mathml_epub(output)
 
     if os.path.isdir(ilustr_path):
         ilustr_elements = set(ilustr.get('src')
index 15e931c..2899808 100644 (file)
@@ -7,6 +7,7 @@ from __future__ import unicode_literals
 
 from lxml import etree
 import re
+from ebooklib import epub
 
 from librarian.dcparser import Person
 from librarian import get_resource
@@ -138,14 +139,22 @@ def reg_mathml_latex():
     _register_function(mathml_latex)
 
 
-def reg_mathml_epub(zipf):
+def reg_mathml_epub(output):
     from librarian.embeds.mathml import MathML
 
     def mathml(context, trees):
         data = MathML(trees[0]).to_latex().to_png().data
         name = "math%d.png" % mathml.count
         mathml.count += 1
-        zipf.writestr('OPS/' + name, data)
+        output.add_item(
+            epub.EpubItem(
+                uid='math%d' % mathml.count,
+                file_name=name,
+                media_type='image/png',
+                content=data
+            )
+        )
+
         return name
     mathml.count = 0
     _register_function(mathml)