Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure SVG and HTML elements exist before using them. #441 #442

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,7 @@ function AddError(message,nopush) {
function GetMML(result) {
if (!data.mml && !data.mmlNode) return;
var jax = MathJax.Hub.getAllJax()[0];
if (!jax) return;
if (data.speakText && !jax.root.alttext) {
jax.root.alttext = result.speakText;
var attrNames = jax.root.attrNames;
Expand All @@ -643,10 +644,11 @@ function GetMML(result) {
function GetSpeech(result) {
if (!data.speakText) return;
result.speakText = "Equation";
if (data.format !== "MathML") result.speakText = data.math;
else {
if (data.format !== "MathML") {
result.speakText = data.math;
} else {
var jax = MathJax.Hub.getAllJax()[0];
if (jax.root.alttext) result.speakText = jax.root.alttext;
if (jax && jax.root.alttext) result.speakText = jax.root.alttext;
}
}

Expand All @@ -658,7 +660,7 @@ function GetHTML(result) {
if (!data.html && !data.htmlNode) return;
var jax = MathJax.Hub.getAllJax()[0]; if (!jax) return;
var script = jax.SourceElement(), html = script.previousSibling;

if (!html) return;
// add speech text if there isn't one
if (data.speakText){
var labelTarget = html.querySelector('.mjx-math');
Expand Down Expand Up @@ -695,6 +697,7 @@ function GetSVG(result) {
var jax = MathJax.Hub.getAllJax()[0]; if (!jax) return;
var script = jax.SourceElement(),
svg = script.previousSibling.getElementsByTagName("svg")[0];
if (!svg) return;
svg.setAttribute("xmlns","http://www.w3.org/2000/svg");

//
Expand Down