Skip to content

Commit

Permalink
Merge branch 'master' into website
Browse files Browse the repository at this point in the history
  • Loading branch information
ylemkimon committed Jul 25, 2018
2 parents 5c329cd + e454eb3 commit 29e24c7
Show file tree
Hide file tree
Showing 39 changed files with 2,957 additions and 2,973 deletions.
3 changes: 2 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"presets": [
["es2015", {
"modules": false
"modules": false,
"loose": true
}],
"flow"
],
Expand Down
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ defaults: &defaults

- run:
name: Verify screenshots and generate diffs and new screenshots
command: node dockers/Screenshotter/screenshotter.js --seleniumIP localhost -b $CIRCLE_JOB --verify --diff --new
command: node dockers/Screenshotter/screenshotter.js --selenium-ip localhost -b $CIRCLE_JOB --verify --diff --new

- store_artifacts:
path: test/screenshotter/new
Expand Down
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
**/node_modules/*
build/*
dist/*
7 changes: 7 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@
"valid-jsdoc": 0,
"require-jsdoc": 0
},
"overrides": [{
"files": ["katex.js", "src/**/*.js"],
"excludedFiles": "unicodeMake.js",
"rules": {
"no-restricted-syntax": [2, "ForOfStatement", "ClassDeclaration[superClass]", "ClassExpression[superClass]"]
}
}],
"env": {
"es6": true,
"node": true,
Expand Down
2 changes: 1 addition & 1 deletion .flowconfig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[ignore]
<PROJECT_ROOT>/build
<PROJECT_ROOT>/dist

[include]

Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
build
katex.tar.gz
katex.zip
node_modules
npm-debug.log
debug.log
Expand Down
1 change: 0 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"/*.sh",
"/package.json",
"/Makefile",
"/build",
"/test",
"/src",
"/contrib",
Expand Down
4 changes: 2 additions & 2 deletions check-node-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ v = v.map(function(s){
return parseInt(s);
});
var a = v[0], b = v[1], c = v[2];
if (a < 6 || (a == 6 && b < 5)) {
console.error("Node 6.5 or later required for development. " +
if (a < 6 || (a == 6 && b < 9)) {
console.error("Node 6.9 or later required for development. " +
"Version " + process.version + " found");
process.exit(1);
} else {
Expand Down
160 changes: 62 additions & 98 deletions cli.js
Original file line number Diff line number Diff line change
@@ -1,103 +1,67 @@
#!/usr/bin/env node
// Simple CLI for KaTeX.
// Reads TeX from stdin, outputs HTML to stdout.
// To run this from the repository, you must first build KaTeX by running
// `npm install` and `npm run build`.

/* eslint no-console:0 */

const katex = require("./");
let katex;
try {
katex = require("./");
} catch (e) {
console.error(
"KaTeX could not import, likely because dist/katex.js is missing.");
console.error("Please run 'npm install' and 'npm run build' before running");
console.error("cli.js from the KaTeX repository.");
console.error();
throw e;
}
const {version} = require("./package.json");
const fs = require("fs");

const options = require("nomnom")
.option("displayMode", {
full: "display-mode",
abbr: "d",
flag: true,
default: false,
help: "If true the math will be rendered in display " +
"mode, which will put the math in display style " +
"(so \\int and \\sum are large, for example), and " +
"will center the math on the page on its own line.",
})
.option("throwOnError", {
full: "no-throw-on-error",
abbr: "t",
flag: true,
default: true,
transform: function(t) {
return !t;
},
help: "If true, KaTeX will throw a ParseError when it " +
"encounters an unsupported command. If false, KaTeX " +
"will render the unsupported command as text in the " +
"color given by errorColor.",
})
.option("errorColor", {
full: "error-color",
abbr: "c",
metavar: "color",
default: "#cc0000",
transform: function(color) {
return "#" + color;
},
help: "A color string given in the format 'rgb' or 'rrggbb'. " +
"This option determines the color which unsupported " +
"commands are rendered in.",
})
.option("colorIsTextColor", {
full: "color-is-text-color",
abbr: "b",
flag: true,
default: false,
help: "Makes \\color behave like LaTeX's 2-argument \\textcolor, " +
"instead of LaTeX's one-argument \\color mode change.",
})
.option("unicodeTextInMathMode", {
full: "unicode-text-in-math-mode",
abbr: "u",
flag: true,
default: false,
help: "Add support for unicode text characters in math mode.",
})
.option("maxSize", {
full: "max-size",
abbr: "s",
metavar: "size",
default: 0,
help: "If non-zero, all user-specified sizes, e.g. in " +
"\\rule{500em}{500em}, will be capped to maxSize ems. " +
"Otherwise, elements and spaces can be arbitrarily large",
})
.option("macros", {
full: "macro",
abbr: "m",
metavar: "macro:expansion",
list: true,
default: [],
help: "A custom macro. Each macro is a property with a name " +
"like \\name which maps to a string that " +
"describes the expansion of the macro.",
})
.option("macroFile", {
full: "macro-file",
abbr: "f",
metavar: "path",
default: null,
help: "Read macro definitions from the given file.",
})
.option("inputFile", {
full: "input",
abbr: "i",
metavar: "path",
default: null,
help: "Read LaTeX input from the given file.",
})
.option("outputFile", {
full: "output",
abbr: "o",
metavar: "path",
default: null,
help: "Write html output to the given file.",
})
.parse();
const options = require("commander")
.version(version)
.option("-d, --display-mode",
"Render math in display mode, which puts the math in display style " +
"(so \\int and \\sum are large, for example), and centers the math " +
"on the page on its own line.")
.option("-t, --no-throw-on-error",
"Render errors (in the color given by --error-color) instead of " +
"throwing a ParseError exception when encountering an error.")
.option("-c, --error-color <color>",
"A color string given in the format 'rgb' or 'rrggbb' (no #). " +
"This option determines the color of errors rendered by the -t option.",
"#cc0000",
(color) => "#" + color)
.option("-b, --color-is-text-color",
"Makes \\color behave like LaTeX's 2-argument \\textcolor, " +
"instead of LaTeX's one-argument \\color mode change.")
.option("-S, --strict",
"Turn on strict / LaTeX faithfulness mode, which throws an error " +
"if the input uses features that are not supported by LaTeX")
.option("-s, --max-size <n>",
"If non-zero, all user-specified sizes, e.g. in " +
"\\rule{500em}{500em}, will be capped to maxSize ems. " +
"Otherwise, elements and spaces can be arbitrarily large",
0, parseInt)
.option("-e, --max-expand <n>",
"Limit the number of macro expansions to the specified number, to " +
"prevent e.g. infinite macro loops. If set to Infinity, the macro " +
"expander will try to fully expand as in LaTeX.",
(n) => (n === "Infinity" ? Infinity : parseInt(n)))
.option("-m, --macro <def>",
"Define custom macro of the form '\\foo:expansion' (use multiple -m " +
"arguments for multiple macros).",
(def, defs) => {
defs.push(def);
return defs;
}, [])
.option("-f, --macro-file <path>",
"Read macro definitions, one per line, from the given file.")
.option("-i, --input <path>", "Read LaTeX input from the given file.")
.option("-o, --output <path>", "Write html output to the given file.")
.parse(process.argv);


function readMacros() {
Expand All @@ -114,7 +78,7 @@ function readMacros() {
function splitMacros(macroStrings) {
// Override macros from macro file (if any)
// with macros from command line (if any)
macroStrings = macroStrings.concat(options.macros);
macroStrings = macroStrings.concat(options.macro);

const macros = {};

Expand All @@ -132,8 +96,8 @@ function splitMacros(macroStrings) {
function readInput() {
let input = "";

if (options.inputFile) {
fs.readFile(options.inputFile, "utf-8", function(err, data) {
if (options.input) {
fs.readFile(options.input, "utf-8", function(err, data) {
if (err) {throw err;}
input = data.toString();
writeOutput(input);
Expand All @@ -152,8 +116,8 @@ function readInput() {
function writeOutput(input) {
const output = katex.renderToString(input, options) + "\n";

if (options.outputFile) {
fs.writeFile(options.outputFile, output, function(err) {
if (options.output) {
fs.writeFile(options.output, output, function(err) {
if (err) {
return console.log(err);
}
Expand Down
115 changes: 37 additions & 78 deletions dockers/Screenshotter/screenshotter.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,84 +17,43 @@ const webpackDevServer = require("webpack-dev-server");
const webpackConfig = require("../../webpack.dev");
const data = require("../../test/screenshotter/ss_data");

const dstDir = path.normalize(
path.join(__dirname, "..", "..", "test", "screenshotter", "images"));
const diffDir = path.normalize(
path.join(__dirname, "..", "..", "test", "screenshotter", "diff"));
const newDir = path.normalize(
path.join(__dirname, "..", "..", "test", "screenshotter", "new"));
// Change to KaTeX root directory so that webpack (in particular
// babel-plugin-version-inline) runs correctly.
process.chdir(path.join(__dirname, "..", ".."));
const dstDir = path.normalize(path.join("test", "screenshotter", "images"));
const diffDir = path.normalize(path.join("test", "screenshotter", "diff"));
const newDir = path.normalize(path.join("test", "screenshotter", "new"));

//////////////////////////////////////////////////////////////////////
// Process command line arguments

const opts = require("nomnom")
.option("browser", {
abbr: "b",
"default": "firefox",
help: "Name of the browser to use",
})
.option("container", {
abbr: "c",
type: "string",
help: "Name or ID of a running docker container to contact",
})
.option("seleniumURL", {
full: "selenium-url",
help: "Full URL of the Selenium web driver",
})
.option("seleniumIP", {
full: "selenium-ip",
help: "IP address of the Selenium web driver",
})
.option("seleniumPort", {
full: "selenium-port",
"default": 4444,
help: "Port number of the Selenium web driver",
})
.option("katexURL", {
full: "katex-url",
help: "Full URL of the KaTeX development server",
})
.option("katexIP", {
full: "katex-ip",
help: "Full URL of the KaTeX development server",
})
.option("katexPort", {
full: "katex-port",
help: "Port number of the KaTeX development server",
})
.option("include", {
abbr: "i",
help: "Comma-separated list of test cases to process",
})
.option("exclude", {
abbr: "x",
help: "Comma-separated list of test cases to exclude",
})
.option("reload", {
flag: true,
help: "Reload page for each test",
})
.option("verify", {
flag: true,
help: "Check whether screenshot matches current file content",
})
.option("diff", {
flag: true,
help: "With `--verify`, produce image diffs when match fails",
})
.option("new", {
flag: true,
help: "With `--verify`, generate new screenshots when match fails",
})
.option("attempts", {
help: "Retry this many times before reporting failure",
"default": 5,
})
.option("wait", {
help: "Wait this many seconds between page load and screenshot",
})
.parse();
const opts = require("commander")
.option("-b, --browser <firefox|chrome>",
"Name of the browser to use", "firefox")
.option("-c, --container <id>",
"Name or ID of a running docker container to contact")
.option("--selenium-url <url>", "Full URL of the Selenium web driver")
.option("--selenium-ip <ip>", "IP address of the Selenium web driver")
.option("--selenium-port <n>",
"Port number of the Selenium web driver", 4444, parseInt)
.option("--katex-url <url>", "Full URL of the KaTeX development server")
.option("--katex-ip <ip>", "IP address of the KaTeX development server")
.option("--katex-port <n>",
"Port number of the KaTeX development server", parseInt)
.option("-i, --include <tests>",
"Comma-separated list of test cases to process")
.option("-x, --exclude <tests>",
"Comma-separated list of test cases to exclude")
.option("--reload", "Reload page for each test")
.option("--verify", "Check whether screenshot matches current file content")
.option("--diff", "With `--verify`, produce image diffs when match fails")
.option("--new",
"With `--verify`, generate new screenshots when match fails")
.option("--attempts <n>",
"Retry this many times before reporting failure", 5, parseInt)
.option("--wait <secs>",
"Wait this many seconds between page load and screenshot", parseFloat)
.parse(process.argv);

let listOfCases;
if (opts.include) {
Expand All @@ -109,11 +68,11 @@ if (opts.exclude) {
});
}

let seleniumURL = opts.seleniumURL;
let seleniumIP = opts.seleniumIP;
let seleniumURL = opts.seleniumUrl;
let seleniumIP = opts.seleniumIp;
let seleniumPort = opts.seleniumPort;
let katexURL = opts.katexURL;
let katexIP = opts.katexIP;
let katexURL = opts.katexUrl;
let katexIP = opts.katexIp;
let katexPort = opts.katexPort;

//////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 29e24c7

Please sign in to comment.