1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
6 * @fileoverview Implentation of ChromeVox's bridge to MathJax.
10 goog.provide('cvox.AbstractMathJax');
12 goog.require('cvox.MathJaxInterface');
16 * Creates a new instance.
18 * @implements {cvox.MathJaxInterface}
20 cvox.AbstractMathJax = function() {
27 cvox.AbstractMathJax.prototype.isMathjaxActive = goog.abstractMethod;
33 cvox.AbstractMathJax.prototype.getAllJax = goog.abstractMethod;
39 cvox.AbstractMathJax.prototype.registerSignal = goog.abstractMethod;
45 cvox.AbstractMathJax.prototype.getTex = goog.abstractMethod;
51 cvox.AbstractMathJax.prototype.getAsciiMath = goog.abstractMethod;
57 cvox.AbstractMathJax.prototype.injectScripts = goog.abstractMethod;
63 cvox.AbstractMathJax.prototype.configMediaWiki = goog.abstractMethod;
67 * Get MathML represententations for all images that have latex alt text.
68 * @param {function(Node, string)} callback A function taking a MathML node and
71 cvox.AbstractMathJax.prototype.getAllTexs = function(callback) {
72 var allTexs = document.
73 querySelectorAll(cvox.DomUtil.altMathQuerySelector('tex'));
74 for (var i = 0, tex; tex = allTexs[i]; i++) {
75 this.getTex(callback, tex);
81 * Get MathML represententations for all images that have asciimath alt text.
82 * @param {function(Node, string)} callback A function taking a MathML node and
85 cvox.AbstractMathJax.prototype.getAllAsciiMaths = function(callback) {
86 var allAsciiMaths = document.
87 querySelectorAll(cvox.DomUtil.altMathQuerySelector('asciimath'));
88 for (var i = 0, tex; tex = allAsciiMaths[i]; i++) {
89 this.getAsciiMath(callback, tex);
95 * Converts a XML markup string to a DOM node and applies a callback function.
96 * The function is generally used in the context of retrieving a MathJax
97 * element's MathML representation and converting it from a string. The callback
98 * is therefore use by MathJax internally in case the requested MathML
99 * representation is not ready yet.
100 * @param {function(Node, string)} callback A function taking a node and an id
102 * @param {string} mml The MathML string.
103 * @param {string} id The Mathjax node id.
105 cvox.AbstractMathJax.prototype.convertMarkupToDom = function(
108 var dp = new DOMParser;
109 var cleanMml = mml.replace(/>\s+</g, '><');
110 callback(dp.parseFromString(cleanMml, 'text/xml').firstChild, id);