From 3d22d9396614783550f9e2f4af954eb9a080d1f1 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 4 Apr 2016 22:52:41 +0530 Subject: [PATCH] E-book viewer: When displaying an EPUB 3 document that uses epub:switch to provide a fallback for MathML content, prevent both the MathML and fallback from being shown together. PDF Output: When displaying an EPUB 3 document that uses epub:switch to provide a fallback for MathML content, prevent both the MathML and fallback from being rendered together. --- resources/compiled_coffeescript.zip | Bin 105783 -> 106998 bytes src/calibre/ebooks/oeb/display/mathjax.coffee | 24 ++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/resources/compiled_coffeescript.zip b/resources/compiled_coffeescript.zip index cf97c94acf927e137e0ff096e10bc43cc3317b5d..5532c771a9b381b38b8b03e8348f4ba1282d021a 100644 GIT binary patch delta 924 zcmZuvO-vI(7~Ls~P(uR15V10{Me zF(f7?PU1jY4SJJx>#9Yn?w4`r-mVrhkkib^(Cc!LEeGr=B3jiyn=Vk0#v zGp#a$TC()fd{t4Qk0nTf=yQmDZ2#a1J^5LY}z&t3MYP+3nAvxT9 z0>T+lhLfes6?U&v=+zStZXjQ9ovAp246T!_kaIhXeQC|e`*-d2+g&s$Fge~!wj>ik zq%CV9e7KhU8>uEE;d&-#&StgQ$j{3rQj@Krul=Cq&JAE7xBfJeA5ZF6PObVk_q||x zZ2<&yEw4yozLDHqtD=7wKxf5LJ0QvV2Kqe*s%ZZr=+tfW(ZnJcJTx!>IQlXV+UREn zSNJ9X&5r?7^Q8-iD>=6GY=6^n-0wW#wsf-=npy-#T74IE(FX-^oDS!}J^H)=hUlX) zpr_~Z;47Uf0E5-#afL#`(@voqb$idc1ZU7CdEA26>F&lZx7#C%ND@RzqW24+iJA&v KxTwwr=Kcfa&nZX% delta 251 zcmex%m~HzmwhfA__`F=JJ#P2dadYxAFmUp2)?d}hJ^9|&+|5sR`94CEoNhmtF`6lQ z`}DxMjH1&w&Sf-WeyGSexu8>I`hkUv9MhTRF={a>SxncP$LP+~?l`@C9-}u)T@)k3 zbe#o^GU5T=tZWQGzy*Y_m>3u=r!zAAW2&AmxR6m~`sq20eACnBGfn^*Wjg)90-z0c z3mBhImzvASJ-v1zqqA9VVo63;VufB-v67X7l98!_xnZKAWr{_Lv00j#iBVFrSyHN* nv6-2fg^@*yk-4F{k%@(Y$#lp0jN;S3&1dwO&NH9UjIkB~&q_~F diff --git a/src/calibre/ebooks/oeb/display/mathjax.coffee b/src/calibre/ebooks/oeb/display/mathjax.coffee index 6c24a31939..8a635d2f65 100644 --- a/src/calibre/ebooks/oeb/display/mathjax.coffee +++ b/src/calibre/ebooks/oeb/display/mathjax.coffee @@ -74,9 +74,33 @@ class MathJax if script != null or document.getElementsByTagName('math').length > 0 this.math_present = true + this.remove_math_fallbacks() this.load_mathjax(user_config, is_windows) return this.math_present + remove_math_fallbacks: () -> + # localName no longer exists in Chrome >= 46 so you will need to + # investigate a proper solution for this in modern browsers. Probably + # use document.evaluate() and node.tagName? IE does not support + # document.evaluate() but Edge may or may not, you will need to + # experiment + for sw in document.getElementsByTagName("epub:switch") + non_math = [] + found_math = false + c = sw.firstChild + while c + if c.localName == 'epub:case' + if c.getAttribute('required-namespace') == "http://www.w3.org/1998/Math/MathML" + found_math = c + else + non_math.push(c) + else if c.localName == 'epub:default' + non_math.push(c) + c = c.nextSibling + if found_math + for c in non_math + c.style.display = 'none' + after_resize: () -> if not this.math_present or this.hub == null return