From 1e148746f8889fc698dfb155c9283f744712ea70 Mon Sep 17 00:00:00 2001 From: Kevin Barabash Date: Sun, 30 Jul 2017 23:28:58 -0400 Subject: [PATCH] Revert "Make KaTeX work in Quirks mode (#608)" (#777) This reverts commit d93a958379bc9f02ece3469eb4748895f1fcb500. --- dockers/Screenshotter/README.md | 2 +- dockers/Screenshotter/screenshotter.js | 73 ++++---------------------- dockers/Screenshotter/screenshotter.sh | 2 +- katex.js | 16 +++++- src/buildCommon.js | 3 +- src/buildHTML.js | 17 ++---- static/index.html | 1 + test/screenshotter/test.html | 10 ++-- 8 files changed, 40 insertions(+), 84 deletions(-) diff --git a/dockers/Screenshotter/README.md b/dockers/Screenshotter/README.md index 7915a0fd..a4de12b7 100644 --- a/dockers/Screenshotter/README.md +++ b/dockers/Screenshotter/README.md @@ -21,7 +21,7 @@ docker containers with the selenium setups running. Essentially you are encouraged to reproduce the steps from `screenshotter.sh` manually. Example run for Firefox: - container=$(docker run -d -P selenium/standalone-firefox:2.48.2) + container=$(docker run -d -P selenium/standalone-firefox:2.46.0) node dockers/Screenshotter/screenshotter.js -b firefox -c ${container} # possibly repeat the above command as often as you need, then eventually docker stop ${container} diff --git a/dockers/Screenshotter/screenshotter.js b/dockers/Screenshotter/screenshotter.js index 5708bee0..04caed1a 100644 --- a/dockers/Screenshotter/screenshotter.js +++ b/dockers/Screenshotter/screenshotter.js @@ -86,14 +86,6 @@ const opts = require("nomnom") .option("wait", { help: "Wait this many seconds between page load and screenshot", }) - .option("mode", { - choices: ["no-quirks", "limited-quirks", "quirks", "all"], - list: true, - help: "Render mode, determined by doctype, " + - "may be given multiple times, " + - "values [no-quirks|limited-quirks|quirks|all], " + - "defaults to all for --verify or no-quirks otherwise", - }) .parse(); let listOfCases; @@ -109,17 +101,6 @@ if (opts.exclude) { }); } -let modes = opts.mode || []; -if (!modes.length) { - modes = [opts.verify ? "all" : "no-quirks"]; -} -if (modes.indexOf("all") !== -1) { - modes = ["no-quirks", "limited-quirks", "quirks"]; -} -if (modes.length > 1 && !opts.verify) { - modes.length = 1; -} - let seleniumURL = opts.seleniumURL; let seleniumIP = opts.seleniumIP; let seleniumPort = opts.seleniumPort; @@ -377,41 +358,16 @@ function findHostIP() { ////////////////////////////////////////////////////////////////////// // Take the screenshots -let countdown = listOfCases.length * modes.length; +let countdown = listOfCases.length; let exitStatus = 0; const listOfFailed = []; -const doctypes = { - "no-quirks": "", - "limited-quirks": '', - "quirks": '', -}; - -// Use two characters per abbreviation for better alignment of output -const qabbr = { - "no-quirks": "nq", - "limited-quirks": "lq", - "quirks": " q", -}; - function takeScreenshots() { - const html = fs.readFileSync(require.resolve( - "../../test/screenshotter/test.html")); - function handler(req, res, next) { - res.send(doctypes[req.query.mode] + "\n" + html); - } - app.get("/ss-render.html", handler); - modes.forEach(function(mode) { - listOfCases.forEach(function(key) { - takeScreenshot(key, mode); - }); - }); + listOfCases.forEach(takeScreenshot); } -function takeScreenshot(key, mode) { +function takeScreenshot(key) { const itm = data[key]; if (!itm) { console.error("Test case " + key + " not known!"); @@ -423,19 +379,14 @@ function takeScreenshot(key, mode) { return; } - let basename = key + "-" + opts.browser; - if (itm.quirky && itm.quirky.indexOf(mode) !== -1) { - // a test case known to differ depending on mode may make use of this - basename += "-" + qabbr[mode]; - } - let file = path.join(dstDir, basename + ".png"); + let file = path.join(dstDir, key + "-" + opts.browser + ".png"); let retry = 0; let loadExpected = null; if (opts.verify) { loadExpected = promisify(fs.readFile, file); } - const url = katexURL + "ss-render.html?mode=" + mode + "&" + itm.query; + const url = katexURL + "test/screenshotter/test.html?" + itm.query; driver.call(loadMath); function loadMath() { @@ -477,9 +428,8 @@ function takeScreenshot(key, mode) { * the other has something else. By using a different * output file name for one of these cases, we accept both. */ - basename = basename.replace(key, key + "_alt"); key += "_alt"; - file = path.join(dstDir, basename + ".png"); + file = path.join(dstDir, key + "-" + opts.browser + ".png"); if (loadExpected) { loadExpected = promisify(fs.readFile, file); } @@ -488,19 +438,18 @@ function takeScreenshot(key, mode) { pako: pako, }); const buf = opt.bufferSync(img.buf); - const line = qabbr[mode] + " " + key; if (loadExpected) { return loadExpected.then(function(expected) { if (!buf.equals(expected)) { if (++retry >= opts.attempts) { - console.error("FAIL! " + line); - listOfFailed.push(key + "[" + qabbr[mode] + "]"); + console.error("FAIL! " + key); + listOfFailed.push(key); exitStatus = 3; if (opts.diff) { return saveScreenshotDiff(key, buf); } } else { - console.log("error " + line); + console.log("error " + key); browserSideWait(300 * retry); if (retry > 1) { driverReady = false; // reload fully @@ -508,12 +457,12 @@ function takeScreenshot(key, mode) { return driver.call(loadMath); } } else { - console.log("* ok " + line); + console.log("* ok " + key); } }); } else { return promisify(fs.writeFile, file, buf).then(function() { - console.log(line); + console.log(key); }); } } diff --git a/dockers/Screenshotter/screenshotter.sh b/dockers/Screenshotter/screenshotter.sh index d38ca51d..fc0f3f7f 100755 --- a/dockers/Screenshotter/screenshotter.sh +++ b/dockers/Screenshotter/screenshotter.sh @@ -29,7 +29,7 @@ popd || exit 2 container= trap cleanup EXIT status=0 -for browserTag in chrome:2.48.2 firefox:2.48.2; do +for browserTag in firefox:2.48.2 chrome:2.48.2; do browser=${browserTag%:*} image=selenium/standalone-${browserTag} echo "Starting container for ${image}" diff --git a/katex.js b/katex.js index d2824c15..8327592f 100644 --- a/katex.js +++ b/katex.js @@ -18,7 +18,7 @@ import utils from "./src/utils"; * Parse and build an expression, and place that expression in the DOM node * given. */ -const render = function(expression, baseNode, options) { +let render = function(expression, baseNode, options) { utils.clearNode(baseNode); const settings = new Settings(options); @@ -29,6 +29,20 @@ const render = function(expression, baseNode, options) { baseNode.appendChild(node); }; +// KaTeX's styles don't work properly in quirks mode. Print out an error, and +// disable rendering. +if (typeof document !== "undefined") { + if (document.compatMode !== "CSS1Compat") { + typeof console !== "undefined" && console.warn( + "Warning: KaTeX doesn't work in quirks mode. Make sure your " + + "website has a suitable doctype."); + + render = function() { + throw new ParseError("KaTeX doesn't work in quirks mode."); + }; + } +} + /** * Parse and build an expression, and return the markup for that. */ diff --git a/src/buildCommon.js b/src/buildCommon.js index ed3d9a17..93c62742 100644 --- a/src/buildCommon.js +++ b/src/buildCommon.js @@ -347,8 +347,7 @@ const makeVList = function(children, positionType, positionData, options) { } else { const child = children[i].elem; - const childWrap = makeSpan( - [], [pstrut, child, new domTree.symbolNode("\u200b")]); + const childWrap = makeSpan([], [pstrut, child]); childWrap.style.top = (-pstrutSize - currPos - child.depth) + "em"; if (children[i].marginLeft) { childWrap.style.marginLeft = children[i].marginLeft; diff --git a/src/buildHTML.js b/src/buildHTML.js index 07bc6d1b..6a7a8939 100644 --- a/src/buildHTML.js +++ b/src/buildHTML.js @@ -761,20 +761,16 @@ groupTypes.spacing = function(group, options) { groupTypes.llap = function(group, options) { const inner = makeSpan( - ["inner"], [ - buildGroup(group.value.body, options), - new domTree.symbolNode("\u200b")]); - const fix = makeSpan(["fix"], [new domTree.symbolNode("\u200b")]); + ["inner"], [buildGroup(group.value.body, options)]); + const fix = makeSpan(["fix"], []); return makeSpan( ["mord", "llap"], [inner, fix], options); }; groupTypes.rlap = function(group, options) { const inner = makeSpan( - ["inner"], [ - buildGroup(group.value.body, options), - new domTree.symbolNode("\u200b")]); - const fix = makeSpan(["fix"], [new domTree.symbolNode("\u200b")]); + ["inner"], [buildGroup(group.value.body, options)]); + const fix = makeSpan(["fix"], []); return makeSpan( ["mord", "rlap"], [inner, fix], options); }; @@ -1743,10 +1739,7 @@ const buildHTML = function(tree, options) { bottomStrut.style.verticalAlign = -body.depth + "em"; // Wrap the struts and body together - const htmlNode = makeSpan(["katex-html"], [ - topStrut, bottomStrut, body, - // Quirks mode fix - new domTree.symbolNode("\u200b")]); + const htmlNode = makeSpan(["katex-html"], [topStrut, bottomStrut, body]); htmlNode.setAttribute("aria-hidden", "true"); diff --git a/static/index.html b/static/index.html index f2794dc1..11abd4a0 100644 --- a/static/index.html +++ b/static/index.html @@ -1,3 +1,4 @@ + diff --git a/test/screenshotter/test.html b/test/screenshotter/test.html index f242b373..38aa0161 100644 --- a/test/screenshotter/test.html +++ b/test/screenshotter/test.html @@ -1,9 +1,9 @@ + - Screenshotter test - - + +