Rename breakOnUnsupportedCmds to throwOnError.
Also, the MathBb-chrome test changed, to what I believe is the correct result? Not sure why it looked wrong before. Test plan: - `make test` - take screenshots, see nothing changed.
This commit is contained in:
parent
c428abca1e
commit
d6cec8a861
|
@ -44,8 +44,7 @@ Make sure to include the CSS and font files, but there is no need to include the
|
|||
You can provide an object of options as the last argument to `katex.render` and `katex.renderToString`. Available options are:
|
||||
|
||||
- `displayMode`: `boolean`. 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. If `false` the math will be rendered in inline mode. (default: `false`)
|
||||
- `breakOnUnsupportedCmds`: `boolean`. If `true`, KaTeX will generate a `ParseError` when it encounters an unsupported command. If `false`, KaTeX will render the command as text
|
||||
in the color given by `errorColor`. (default: `true`)
|
||||
- `throwOnError`: `boolean`. 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`. (default: `true`)
|
||||
- `errorColor`: `string`. A color string given in the format `"#XXX"` or `"#XXXXXX"`. This option determines the color which unsupported commands are rendered in. (default: `#cc0000`)
|
||||
|
||||
For example:
|
||||
|
|
|
@ -129,7 +129,7 @@ Parser.prototype.parseExpression = function(pos, mode, breakOnInfix, breakOnToke
|
|||
}
|
||||
var atom = this.parseAtom(pos, mode);
|
||||
if (!atom) {
|
||||
if (!this.settings.breakOnUnsupportedCmds && lex.text[0] === "\\") {
|
||||
if (!this.settings.throwOnError && lex.text[0] === "\\") {
|
||||
var errorNode = this.handleUnsupportedCmd(lex.text, mode);
|
||||
body.push(errorNode);
|
||||
|
||||
|
@ -214,7 +214,7 @@ Parser.prototype.handleSupSubscript = function(pos, mode, symbol, name) {
|
|||
if (!group) {
|
||||
var lex = this.lexer.lex(pos, mode);
|
||||
|
||||
if (!this.settings.breakOnUnsupportedCmds && lex.text[0] === "\\") {
|
||||
if (!this.settings.throwOnError && lex.text[0] === "\\") {
|
||||
return new ParseResult(
|
||||
this.handleUnsupportedCmd(lex.text, mode),
|
||||
lex.position);
|
||||
|
@ -548,7 +548,7 @@ Parser.prototype.parseArguments = function(pos, mode, func, funcData, args) {
|
|||
if (!arg) {
|
||||
var lex = this.lexer.lex(newPos, mode);
|
||||
|
||||
if (!this.settings.breakOnUnsupportedCmds && lex.text[0] === "\\") {
|
||||
if (!this.settings.throwOnError && lex.text[0] === "\\") {
|
||||
arg = new ParseFuncOrArgument(
|
||||
new ParseResult(
|
||||
this.handleUnsupportedCmd(lex.text, mode),
|
||||
|
|
|
@ -21,7 +21,7 @@ function Settings(options) {
|
|||
// allow null options
|
||||
options = options || {};
|
||||
this.displayMode = get(options.displayMode, false);
|
||||
this.breakOnUnsupportedCmds = get(options.breakOnUnsupportedCmds, true);
|
||||
this.throwOnError = get(options.throwOnError, true);
|
||||
this.errorColor = get(options.errorColor, "#cc0000");
|
||||
}
|
||||
|
||||
|
|
|
@ -1707,43 +1707,43 @@ describe("A MathML builder", function() {
|
|||
});
|
||||
});
|
||||
|
||||
describe("A parser that does not break on unsupported commands", function() {
|
||||
describe("A parser that does not throw on unsupported commands", function() {
|
||||
// The parser breaks on unsupported commands unless it is explicitly
|
||||
// told not to
|
||||
var errorColor = "#933";
|
||||
var doNotBreakSettings = new Settings({
|
||||
breakOnUnsupportedCmds: false,
|
||||
var noThrowSettings = new Settings({
|
||||
throwOnError: false,
|
||||
errorColor: errorColor
|
||||
});
|
||||
|
||||
it("should still parse on unrecognized control sequences", function() {
|
||||
expect("\\error").toParse(doNotBreakSettings);
|
||||
expect("\\error").toParse(noThrowSettings);
|
||||
});
|
||||
|
||||
describe("should allow unrecognized controls sequences anywhere, including", function() {
|
||||
it("in superscripts and subscripts", function() {
|
||||
expect("2_\\error").toBuild(doNotBreakSettings);
|
||||
expect("3^{\\error}_\\error").toBuild(doNotBreakSettings);
|
||||
expect("\\int\\nolimits^\\error_\\error").toBuild(doNotBreakSettings);
|
||||
expect("2_\\error").toBuild(noThrowSettings);
|
||||
expect("3^{\\error}_\\error").toBuild(noThrowSettings);
|
||||
expect("\\int\\nolimits^\\error_\\error").toBuild(noThrowSettings);
|
||||
});
|
||||
|
||||
it("in fractions", function() {
|
||||
expect("\\frac{345}{\\error}").toBuild(doNotBreakSettings);
|
||||
expect("\\frac\\error{\\error}").toBuild(doNotBreakSettings);
|
||||
expect("\\frac{345}{\\error}").toBuild(noThrowSettings);
|
||||
expect("\\frac\\error{\\error}").toBuild(noThrowSettings);
|
||||
});
|
||||
|
||||
it("in square roots", function() {
|
||||
expect("\\sqrt\\error").toBuild(doNotBreakSettings);
|
||||
expect("\\sqrt{234\\error}").toBuild(doNotBreakSettings);
|
||||
expect("\\sqrt\\error").toBuild(noThrowSettings);
|
||||
expect("\\sqrt{234\\error}").toBuild(noThrowSettings);
|
||||
});
|
||||
|
||||
it("in text boxes", function() {
|
||||
expect("\\text{\\error}").toBuild(doNotBreakSettings);
|
||||
expect("\\text{\\error}").toBuild(noThrowSettings);
|
||||
});
|
||||
});
|
||||
|
||||
it("should produce color nodes with a color value given by errorColor", function() {
|
||||
var parsedInput = getParsed("\\error", doNotBreakSettings);
|
||||
var parsedInput = getParsed("\\error", noThrowSettings);
|
||||
expect(parsedInput[0].type).toBe("color");
|
||||
expect(parsedInput[0].value.color).toBe(errorColor);
|
||||
});
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 9.7 KiB After Width: | Height: | Size: 11 KiB |
|
@ -11,7 +11,7 @@ var fs = require("fs");
|
|||
var jsyaml = require("js-yaml");
|
||||
var querystring = require("querystring");
|
||||
|
||||
var queryKeys = ["tex", "pre", "post", "display", "doNotBreak", "errorColor"];
|
||||
var queryKeys = ["tex", "pre", "post", "display", "noThrow", "errorColor"];
|
||||
var dict = fs.readFileSync(require.resolve("./ss_data.yaml"));
|
||||
dict = jsyaml.safeLoad(dict);
|
||||
for (var key in dict) {
|
||||
|
|
|
@ -106,7 +106,7 @@ SupSubOffsets: \displaystyle \int_{2+3}x f^{2+3}+3\lim_{2+3+4+5}f
|
|||
Text: \frac{a}{b}\text{c~ {ab} \ e}+fg
|
||||
UnsupportedCmds:
|
||||
tex: \err\,\frac\fracerr3\,2^\superr_\suberr\,\sqrt\sqrterr
|
||||
doNotBreak: 1
|
||||
noThrow: 1
|
||||
errorColor: "#dd4c4c"
|
||||
VerticalSpacing:
|
||||
pre: potato<br>blah
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
|
||||
var settings = {
|
||||
displayMode: !!query["display"],
|
||||
breakOnUnsupportedCmds: !query["doNotBreak"]
|
||||
throwOnError: !query["noThrow"]
|
||||
};
|
||||
if (query["errorColor"]) {
|
||||
settings.errorColor = query["errorColor"];
|
||||
|
|
Loading…
Reference in New Issue
Block a user