-
Notifications
You must be signed in to change notification settings - Fork 3
/
katex.js
59 lines (48 loc) · 1.72 KB
/
katex.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
* This is the main entry point for KaTeX. Here, we expose functions for
* rendering expressions either to DOM nodes or to markup strings.
*
* We also expose the ParseError class to check if errors thrown from KaTeX are
* errors in the expression, or errors in javascript handling.
*/
var ParseError = require("./src/ParseError");
var Settings = require("./src/Settings");
var buildTree = require("./src/buildTree");
var parseTree = require("./src/parseTree");
var utils = require("./src/utils");
/**
* Parse and build an expression, and place that expression in the DOM node
* given.
*/
var render = function(expression, baseNode, options) {
utils.clearNode(baseNode);
var settings = new Settings(options);
var tree = parseTree(expression, settings);
var node = buildTree(tree, expression, settings).toNode();
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.
*/
var renderToString = function(expression, options) {
var settings = new Settings(options);
var tree = parseTree(expression, settings);
return buildTree(tree, expression, settings).toMarkup();
};
module.exports = {
render: render,
renderToString: renderToString,
ParseError: ParseError
};