
Summary: Add comments everywhere! Also fix some small bugs like using Style.id instead of Style.size, and rename some variables to be more descriptive. Fixes #22 Test Plan: - Make sure the huxley screenshots didn't change - Make sure the tests still pass Reviewers: alpert Reviewed By: alpert Differential Revision: http://phabricator.khanacademy.org/D13158
86 lines
2.4 KiB
JavaScript
86 lines
2.4 KiB
JavaScript
/**
|
|
* This file contains information about the options that the Parser carries
|
|
* around with it while parsing. Data is held in an `Options` object, and when
|
|
* recursing, a new `Options` object can be created with the `.with*` and
|
|
* `.reset` functions.
|
|
*/
|
|
|
|
/**
|
|
* This is the main options class. It contains the style, size, and color of the
|
|
* current parse level. It also contains the style and size of the parent parse
|
|
* level, so size changes can be handled efficiently.
|
|
*
|
|
* Each of the `.with*` and `.reset` functions passes its current style and size
|
|
* as the parentStyle and parentSize of the new options class, so parent
|
|
* handling is taken care of automatically.
|
|
*/
|
|
function Options(style, size, color, parentStyle, parentSize) {
|
|
this.style = style;
|
|
this.color = color;
|
|
this.size = size;
|
|
|
|
if (parentStyle === undefined) {
|
|
parentStyle = style;
|
|
}
|
|
this.parentStyle = parentStyle;
|
|
|
|
if (parentSize === undefined) {
|
|
parentSize = size;
|
|
}
|
|
this.parentSize = parentSize;
|
|
}
|
|
|
|
/**
|
|
* Create a new options object with the given style.
|
|
*/
|
|
Options.prototype.withStyle = function(style) {
|
|
return new Options(style, this.size, this.color, this.style, this.size);
|
|
};
|
|
|
|
/**
|
|
* Create a new options object with the given size.
|
|
*/
|
|
Options.prototype.withSize = function(size) {
|
|
return new Options(this.style, size, this.color, this.style, this.size);
|
|
};
|
|
|
|
/**
|
|
* Create a new options object with the given color.
|
|
*/
|
|
Options.prototype.withColor = function(color) {
|
|
return new Options(this.style, this.size, color, this.style, this.size);
|
|
};
|
|
|
|
/**
|
|
* Create a new options object with the same style, size, and color. This is
|
|
* used so that parent style and size changes are handled correctly.
|
|
*/
|
|
Options.prototype.reset = function() {
|
|
return new Options(
|
|
this.style, this.size, this.color, this.style, this.size);
|
|
};
|
|
|
|
/**
|
|
* A map of color names to CSS colors.
|
|
* TODO(emily): Remove this when we have real macros
|
|
*/
|
|
var colorMap = {
|
|
"katex-blue": "#6495ed",
|
|
"katex-orange": "#ffa500",
|
|
"katex-pink": "#ff00af",
|
|
"katex-red": "#df0030",
|
|
"katex-green": "#28ae7b",
|
|
"katex-gray": "gray",
|
|
"katex-purple": "#9d38bd"
|
|
};
|
|
|
|
/**
|
|
* Gets the CSS color of the current options object, accounting for the
|
|
* `colorMap`.
|
|
*/
|
|
Options.prototype.getColor = function() {
|
|
return colorMap[this.color] || this.color;
|
|
};
|
|
|
|
module.exports = Options;
|