From ecc4f5c21f155d689a75cb3f48b154ba37501583 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Fri, 18 Dec 2020 09:53:28 +0100 Subject: [PATCH 1/1] Fixed MathML in EPUB. --- CHANGELOG.md | 6 ++++++ setup.py | 2 +- src/librarian/epub.py | 2 +- src/librarian/functions.py | 13 +++++++++++-- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 521ef1c..322dba0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/setup.py b/setup.py index 3a50c6c..dda645c 100755 --- 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', diff --git a/src/librarian/epub.py b/src/librarian/epub.py index a8c6680..c286903 100644 --- a/src/librarian/epub.py +++ b/src/librarian/epub.py @@ -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') diff --git a/src/librarian/functions.py b/src/librarian/functions.py index 15e931c..2899808 100644 --- a/src/librarian/functions.py +++ b/src/librarian/functions.py @@ -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) -- 2.20.1