Created
April 21, 2018 05:10
-
-
Save czfshine/a1767570c1962ff176b9912f9516af86 to your computer and use it in GitHub Desktop.
Mathjax in Wechat
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var i=0; | |
| var svgs; | |
| function drawCanvas(){ | |
| if(i==0){ | |
| svgs=document.getElementsByClassName("MathJax_SVG"); | |
| }else{ | |
| if(i>=svgs.length){ | |
| return; | |
| } | |
| } | |
| var img = new Image(); | |
| var DOMURL = self.URL || self.webkitURL || self; | |
| var canvas = document.getElementById("canvas"); | |
| var ctx = canvas.getContext("2d"); | |
| canvas.height= svgs[i].getElementsByTagName("svg")[0].clientHeight+200 | |
| canvas.width= svgs[i].getElementsByTagName("svg")[0].clientWidth+200 | |
| svgs[i].style.height=svgs[i].getElementsByTagName("svg")[0].clientHeight*1.25+"px"; | |
| svgs[i].style.width=svgs[i].getElementsByTagName("svg")[0].clientWidth*1.25+10+"px"; | |
| svgs[i].style.overflow="hidden"; | |
| var svgString = new XMLSerializer().serializeToString( svgs[i].getElementsByTagName("svg")[0]); | |
| img.src = 'data:image/svg+xml;base64,' + btoa(unescape(encodeURIComponent(svgString)) ); | |
| img.iddd=i | |
| document.body.appendChild(img); | |
| img.onload = function () { | |
| ctx.drawImage(img, 0, 0); | |
| var im = canvas.toDataURL("image/png"); | |
| var imgg=new Image(); | |
| imgg.style.cssText = 'max-width:none !important;'; | |
| imgg.src=im; | |
| svgs[i].innerHTML="" | |
| svgs[i].appendChild(imgg); | |
| i++; | |
| drawCanvas(); | |
| }; | |
| } | |
| drawCanvas(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment