Skip to content

Commit

Permalink
Merge pull request #381 from mathjax/develop
Browse files Browse the repository at this point in the history
Merge version 2.0.0 into master
  • Loading branch information
dpvc committed Feb 6, 2018
2 parents a30432f + a7c43da commit 89d1e0a
Show file tree
Hide file tree
Showing 18 changed files with 181 additions and 362 deletions.
4 changes: 1 addition & 3 deletions .travis.yml
@@ -1,7 +1,5 @@
language: node_js
node_js:
- '4'
- '5'
- '6'
- '7'
- '8'
Expand All @@ -15,6 +13,6 @@ deploy:
provider: npm
email: manager@mathjax.org
api_key:
secure: aJ/ZDGLods2x/Iss0bNgZ3xNHR7K8kkjEZ9jMAjTNxRlgC1oTbmjnPVVwybznUoIf8e13vpEyLHVNCZFWiE1rHwsguJCa1FoANKjpw51o/B811DZ65Nvj0qFuSi9UrHUwuVcnVCp2Qn2XEschCgT9yVWmiOmstq3557qg2iUJ1o=
secure: MG7sE1EsJd1wvcy1HPqX1YD3kvW0JODhgxN5xquHxitF8ua9Wevn0xwNnYMZdHhaiimaRn63L6wE1Rx6B41Z07uOAIPzcGi9Z6qqqQjrxhGC7WKdLd8gLD7RULhneTZ/ABjPgH2YQ31zcR17QEo34O4HbpKYmcrfSNfHd1IOgvA=
on:
tags: true
108 changes: 87 additions & 21 deletions lib/main.js
Expand Up @@ -30,10 +30,11 @@ var http = require('http');
var fs = require('fs');
var path = require('path');
var url = require('url');
var jsdom = require('jsdom').jsdom;
var jsdom = require('jsdom');
var JSDOM = jsdom.JSDOM;
var isFullwidthCodePoint = require('is-fullwidth-code-point');

require('./patch/jsdom.js').patch(jsdom); // Fix some bugs in jsdom
require('./patch/jsdom.js').patch(JSDOM); // Fix some bugs in jsdom

var displayMessages = false; // don't log Message.Set() calls
var displayErrors = true; // show error messages on the console
Expand Down Expand Up @@ -114,22 +115,22 @@ var CHTMLSTYLES; // filled in when CommonHTML is loaded
// the jax to be loaded completely)
//
function GetWindow() {
document = jsdom('',{userAgent: "Node.js"});
var virtualConsole = new jsdom.VirtualConsole();
virtualConsole.sendTo(console);
window = new JSDOM('',{
virtualConsole: virtualConsole,
userAgent: "Node.js",
runScripts: "dangerously",
resources: "usable"
}).window;
document = window.document;
html = document.firstChild;
window = document.defaultView;
window.console = console;
window.addEventListener("error",function (event) {AddError("Error: "+event.error.stack)});
content = document.body.appendChild(document.createElement("div"));
content.id = "MathJax_Content";
content.innerHTML = '<script type="math/tex">x</script>' +
'<script type="math/asciimath">x</script>' +
'<script type="math/mml"><math><mi>x</mi></math></script>';
//
// Node's url.resolve() has a problem with resolving a file:// URL when
// the base URL is "about:blank", so force it to be something else (HACK)
// since jsdom 3.x sets the base to "about:blank".
//
if (document._URL === "about:blank") document._URL = "file:///blank.html";
}

//
Expand All @@ -140,7 +141,6 @@ function ConfigureMathJax() {
//
// Load all input jax and preprocessors
// Load AMS extensions and the autoload extension for TeX
// Allow $...$ delimiters and don't create previews for any preprocessor,
// Create stand-alone SVG elements with font caches by default
// (users can override that)
//
Expand Down Expand Up @@ -324,6 +324,30 @@ function ConfigureMathJax() {
this.d = this.D = (bbox.height + bbox.y)*scale;
}
});

//
// Don't have mglyph load images
//
MathJax.Hub.Register.StartupHook("SVG mglyph Ready",function () {
var MML = MathJax.ElementJax.mml;
var MGLYPH = MML.mglyph;
var TOSVG = MGLYPH.prototype.toSVG;
MGLYPH.Augment({
toSVG: function (variant,scale) {
var values = this.getValues("src","width","height");
if (values.src !== "" && !MGLYPH.GLYPH[values.src]) {
if (!values.width || !values.height) {
AddError("mglyphs must have explicit width and height in mathjax-node");
}
MGLYPH.GLYPH[values.src] = {
img: {SRC: values.src, width: 0, height: 0},
status: "OK"
};
}
return TOSVG.apply(this,arguments);
}
});
});

});

Expand Down Expand Up @@ -427,7 +451,43 @@ function ConfigureMathJax() {

});

//
// Don't have mglyph load images
//
MathJax.Hub.Register.StartupHook("CommonHTML mglyph Ready",function () {
var MML = MathJax.ElementJax.mml;
var MGLYPH = MML.mglyph;
var TOCHTML = MGLYPH.prototype.toCommonHTML;
MGLYPH.Augment({
toCommonHTML: function (node,options) {
var values = this.getValues("src","width","height");
if (values.src !== "" && !MGLYPH.GLYPH[values.src]) {
if (!values.width || !values.height) {
AddError("mglyphs must have explicit width and height in mathjax-node");
}
MGLYPH.GLYPH[values.src] = {
img: {SRC: values.src, width: 0, height: 0},
status: "OK"
};
}
return TOCHTML.apply(this,arguments);
}
});
});

});

//
// Set up None output jax (for when only MathML output is needed)
//
MathJax.OutputJax.None = MathJax.OutputJax({
id: "None",
preTranslate: function () {},
Translate: function () {},
postTranslate: function () {}
});
MathJax.OutputJax.None.loadComplete("jax.js");
MathJax.OutputJax.None.Register("jax/mml");

//
// Reset the color extension after `autoload-all`
Expand All @@ -448,14 +508,14 @@ function ConfigureMathJax() {
// (reseting the counters so that the initial math doesn't affect them)
//
MathJax.Hub.Register.StartupHook("End",function () {
MathJax.OutputJax.SVG.resetGlyphs(true);
if (MathJax.OutputJax.SVG.resetGlyphs) MathJax.OutputJax.SVG.resetGlyphs(true);
MathJax.ElementJax.mml.ID = 0;
serverState = STATE.READY;
MathJax.Hub.Queue(StartQueue);
});
}
};

if (extensions) {
//
// Parse added extensions list and add to standard ones
Expand Down Expand Up @@ -511,7 +571,7 @@ function StartMathJax() {
serverState = STATE.STARTED;
var script = document.createElement("script");
script.src = MathJaxPath;
script.onerror = function () {AddError("Can't load MathJax.js from "+MathJaxPath)}
script.onerror = function () {AddError("Can't load MathJax.js from "+MathJaxPath)};
document.head.appendChild(script);
}

Expand Down Expand Up @@ -543,7 +603,7 @@ function AddError(message,nopush) {
function GetMML(result) {
if (!data.mml && !data.mmlNode) return;
var jax = MathJax.Hub.getAllJax()[0];
if (data.speakText && !jax.root.alttext){
if (data.speakText && !jax.root.alttext) {
jax.root.alttext = result.speakText;
var attrNames = jax.root.attrNames;
if (attrNames && attrNames.indexOf("alttext") === -1) {
Expand All @@ -557,7 +617,7 @@ function GetMML(result) {
return MathJax.Callback.After(window.Array(GetMML,result),err.restart);
}
if (data.mml) result.mml = mml;
if (data.mmlNode) result.mmlNode = jsdom(mml).body.firstChild;
if (data.mmlNode) result.mmlNode = JSDOM.fragment(mml).firstChild;
}

//
Expand Down Expand Up @@ -700,7 +760,13 @@ function StartQueue() {
//
GetState(data.state);

var renderer = ( (data.html || data.htmlNode || data.css) ? "CommonHTML" : "SVG");
//
// Get the renderer to use
//
var renderer = (
(data.html || data.htmlNode || data.css) ? "CommonHTML" :
(data.svg || data.svgNode) ? "SVG" : "None"
);

//
// Set up a timeout timer to restart MathJax if it runs too long,
Expand Down Expand Up @@ -731,7 +797,7 @@ function GetState(state) {
MML = MathJax.ElementJax.mml,
AMS = MathJax.Extension["TeX/AMSmath"],
HUB = MathJax.Hub, HTML = MathJax.HTML,
GLYPH = SVG.BBOX.GLYPH;
GLYPH = (SVG.BBOX||{}).GLYPH;

if (state && state.AMS) {
AMS.startNumber = state.AMS.startNumber;
Expand All @@ -744,7 +810,7 @@ function GetState(state) {
ID = state.ID;
} else {
if (state) {state.AMS = {}}
SVG.resetGlyphs(true);
if (SVG.resetGlyphs) SVG.resetGlyphs(true);
if (data.useGlobalCache) {
state.glyphs = {};
state.defs = HTML.Element("defs");
Expand Down Expand Up @@ -777,7 +843,7 @@ function ReturnResult(result) {
var state = data.state;
if (state) {
var AMS = MathJax.Extension["TeX/AMSmath"];
var GLYPH = MathJax.OutputJax.SVG.BBOX.GLYPH;
var GLYPH = (MathJax.OutputJax.SVG||{}).BBOX.GLYPH;
state.AMS.startNumber = AMS.startNumber;
state.AMS.labels = AMS.labels;
state.AMS.IDs = AMS.IDs;
Expand Down

0 comments on commit 89d1e0a

Please sign in to comment.