mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-05 03:08:40 +00:00
This reverts commit d93a958379
.
This commit is contained in:
@@ -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}
|
||||
|
@@ -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": "<!DOCTYPE html>",
|
||||
"limited-quirks": '<!DOCTYPE HTML PUBLIC ' +
|
||||
'"-//W3C//DTD HTML 4.01 Transitional//EN" ' +
|
||||
'"http://www.w3.org/TR/html4/loose.dtd">',
|
||||
"quirks": '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Draft//">',
|
||||
};
|
||||
|
||||
// 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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@@ -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}"
|
||||
|
16
katex.js
16
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.
|
||||
*/
|
||||
|
@@ -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;
|
||||
|
@@ -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");
|
||||
|
||||
|
@@ -1,3 +1,4 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
|
@@ -1,9 +1,9 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<title>Screenshotter test</title>
|
||||
<script src="katex.js" type="text/javascript"></script>
|
||||
<link href="katex.css" rel="stylesheet" type="text/css">
|
||||
<script src="../../katex.js" type="text/javascript"></script>
|
||||
<link href="../../katex.css" rel="stylesheet" type="text/css">
|
||||
<style type="text/css">
|
||||
#math, #pre, #post {
|
||||
font-size: 4em;
|
||||
@@ -13,11 +13,11 @@
|
||||
}
|
||||
@font-face {
|
||||
font-family: "Mincho";
|
||||
src: url("/test/screenshotter/unicode-fonts/mincho/font_1_honokamin.ttf") format("truetype");
|
||||
src: url("unicode-fonts/mincho/font_1_honokamin.ttf") format("truetype");
|
||||
}
|
||||
@font-face {
|
||||
font-family: "Batang";
|
||||
src: url("/test/screenshotter/unicode-fonts/batang/batang.ttf") format("truetype");
|
||||
src: url("unicode-fonts/batang/batang.ttf") format("truetype");
|
||||
}
|
||||
.katex .cjk_fallback {
|
||||
font-family: "Mincho",serif;
|
||||
|
Reference in New Issue
Block a user