temml 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE +21 -0
- package/README.md +44 -0
- package/contrib/auto-render/README.md +89 -0
- package/contrib/auto-render/auto-render.js +128 -0
- package/contrib/auto-render/dist/auto-render.js +217 -0
- package/contrib/auto-render/dist/auto-render.min.js +1 -0
- package/contrib/auto-render/splitAtDelimiters.js +84 -0
- package/contrib/auto-render/test/auto-render-spec.js +234 -0
- package/contrib/auto-render/test/auto-render.js +217 -0
- package/contrib/auto-render/test/test_page.html +59 -0
- package/contrib/mhchem/README.md +26 -0
- package/contrib/mhchem/mhchem.js +1705 -0
- package/contrib/mhchem/mhchem.min.js +1 -0
- package/contrib/physics/README.md +20 -0
- package/contrib/physics/physics.js +131 -0
- package/contrib/texvc/README.md +23 -0
- package/contrib/texvc/texvc.js +61 -0
- package/dist/Temml-Asana.css +201 -0
- package/dist/Temml-Latin-Modern.css +216 -0
- package/dist/Temml-Libertinus.css +214 -0
- package/dist/Temml-Local.css +194 -0
- package/dist/Temml-STIX2.css +203 -0
- package/dist/Temml.woff2 +0 -0
- package/dist/temml.cjs +13122 -0
- package/dist/temml.js +11225 -0
- package/dist/temml.min.js +1 -0
- package/dist/temml.mjs +13120 -0
- package/dist/temmlPostProcess.js +70 -0
- package/package.json +34 -0
- package/src/Lexer.js +121 -0
- package/src/MacroExpander.js +437 -0
- package/src/Namespace.js +107 -0
- package/src/ParseError.js +64 -0
- package/src/Parser.js +977 -0
- package/src/Settings.js +49 -0
- package/src/SourceLocation.js +29 -0
- package/src/Style.js +144 -0
- package/src/Token.js +40 -0
- package/src/buildMathML.js +235 -0
- package/src/constants.js +25 -0
- package/src/defineEnvironment.js +25 -0
- package/src/defineFunction.js +69 -0
- package/src/defineMacro.js +11 -0
- package/src/domTree.js +185 -0
- package/src/environments/array.js +791 -0
- package/src/environments/cd.js +252 -0
- package/src/environments.js +8 -0
- package/src/functions/accent.js +127 -0
- package/src/functions/accentunder.js +38 -0
- package/src/functions/arrow.js +204 -0
- package/src/functions/cancelto.js +36 -0
- package/src/functions/char.js +33 -0
- package/src/functions/color.js +253 -0
- package/src/functions/cr.js +46 -0
- package/src/functions/def.js +259 -0
- package/src/functions/delimsizing.js +304 -0
- package/src/functions/enclose.js +193 -0
- package/src/functions/envTag.js +38 -0
- package/src/functions/environment.js +59 -0
- package/src/functions/font.js +123 -0
- package/src/functions/genfrac.js +333 -0
- package/src/functions/hbox.js +29 -0
- package/src/functions/horizBrace.js +32 -0
- package/src/functions/href.js +90 -0
- package/src/functions/html.js +95 -0
- package/src/functions/includegraphics.js +131 -0
- package/src/functions/kern.js +75 -0
- package/src/functions/label.js +29 -0
- package/src/functions/lap.js +75 -0
- package/src/functions/math.js +40 -0
- package/src/functions/mathchoice.js +41 -0
- package/src/functions/mclass.js +201 -0
- package/src/functions/multiscript.js +91 -0
- package/src/functions/not.js +46 -0
- package/src/functions/op.js +338 -0
- package/src/functions/operatorname.js +139 -0
- package/src/functions/ordgroup.js +9 -0
- package/src/functions/phantom.js +73 -0
- package/src/functions/pmb.js +31 -0
- package/src/functions/raise.js +68 -0
- package/src/functions/ref.js +28 -0
- package/src/functions/relax.js +16 -0
- package/src/functions/rule.js +52 -0
- package/src/functions/sizing.js +64 -0
- package/src/functions/smash.js +66 -0
- package/src/functions/sqrt.js +31 -0
- package/src/functions/styling.js +58 -0
- package/src/functions/supsub.js +135 -0
- package/src/functions/symbolsOp.js +53 -0
- package/src/functions/symbolsOrd.js +102 -0
- package/src/functions/symbolsSpacing.js +53 -0
- package/src/functions/tag.js +8 -0
- package/src/functions/text.js +75 -0
- package/src/functions/tip.js +63 -0
- package/src/functions/toggle.js +13 -0
- package/src/functions/verb.js +33 -0
- package/src/functions.js +57 -0
- package/src/linebreaking.js +159 -0
- package/src/macros.js +708 -0
- package/src/mathMLTree.js +175 -0
- package/src/parseNode.js +42 -0
- package/src/parseTree.js +40 -0
- package/src/postProcess.js +57 -0
- package/src/replace.js +225 -0
- package/src/stretchy.js +66 -0
- package/src/svg.js +110 -0
- package/src/symbols.js +972 -0
- package/src/tree.js +50 -0
- package/src/unicodeAccents.js +16 -0
- package/src/unicodeScripts.js +119 -0
- package/src/unicodeSupOrSub.js +108 -0
- package/src/unicodeSymbolBuilder.js +31 -0
- package/src/unicodeSymbols.js +320 -0
- package/src/units.js +109 -0
- package/src/utils.js +109 -0
- package/src/variant.js +103 -0
- package/temml.js +181 -0
package/src/domTree.js
ADDED
@@ -0,0 +1,185 @@
|
|
1
|
+
/**
|
2
|
+
* These objects store the data about the DOM nodes we create, as well as some
|
3
|
+
* extra data. They can then be transformed into real DOM nodes with the
|
4
|
+
* `toNode` function or HTML markup using `toMarkup`. They are useful for both
|
5
|
+
* storing extra properties on the nodes, as well as providing a way to easily
|
6
|
+
* work with the DOM.
|
7
|
+
*
|
8
|
+
* Similar functions for working with MathML nodes exist in mathMLTree.js.
|
9
|
+
*
|
10
|
+
*/
|
11
|
+
import utils from "./utils";
|
12
|
+
|
13
|
+
/**
|
14
|
+
* Create an HTML className based on a list of classes. In addition to joining
|
15
|
+
* with spaces, we also remove empty classes.
|
16
|
+
*/
|
17
|
+
export const createClass = function(classes) {
|
18
|
+
return classes.filter((cls) => cls).join(" ");
|
19
|
+
};
|
20
|
+
|
21
|
+
const initNode = function(classes, style) {
|
22
|
+
this.classes = classes || [];
|
23
|
+
this.attributes = {};
|
24
|
+
this.style = style || {};
|
25
|
+
};
|
26
|
+
|
27
|
+
/**
|
28
|
+
* Convert into an HTML node
|
29
|
+
*/
|
30
|
+
const toNode = function(tagName) {
|
31
|
+
const node = document.createElement(tagName);
|
32
|
+
|
33
|
+
// Apply the class
|
34
|
+
node.className = createClass(this.classes);
|
35
|
+
|
36
|
+
// Apply inline styles
|
37
|
+
for (const style in this.style) {
|
38
|
+
if (Object.prototype.hasOwnProperty.call(this.style, style )) {
|
39
|
+
node.style[style] = this.style[style];
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
// Apply attributes
|
44
|
+
for (const attr in this.attributes) {
|
45
|
+
if (Object.prototype.hasOwnProperty.call(this.attributes, attr )) {
|
46
|
+
node.setAttribute(attr, this.attributes[attr]);
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
// Append the children, also as HTML nodes
|
51
|
+
for (let i = 0; i < this.children.length; i++) {
|
52
|
+
node.appendChild(this.children[i].toNode());
|
53
|
+
}
|
54
|
+
|
55
|
+
return node;
|
56
|
+
};
|
57
|
+
|
58
|
+
/**
|
59
|
+
* Convert into an HTML markup string
|
60
|
+
*/
|
61
|
+
const toMarkup = function(tagName) {
|
62
|
+
let markup = `<${tagName}`;
|
63
|
+
|
64
|
+
// Add the class
|
65
|
+
if (this.classes.length) {
|
66
|
+
markup += ` class="${utils.escape(createClass(this.classes))}"`;
|
67
|
+
}
|
68
|
+
|
69
|
+
let styles = "";
|
70
|
+
|
71
|
+
// Add the styles, after hyphenation
|
72
|
+
for (const style in this.style) {
|
73
|
+
if (Object.prototype.hasOwnProperty.call(this.style, style )) {
|
74
|
+
styles += `${utils.hyphenate(style)}:${this.style[style]};`;
|
75
|
+
}
|
76
|
+
}
|
77
|
+
|
78
|
+
if (styles) {
|
79
|
+
markup += ` style="${styles}"`;
|
80
|
+
}
|
81
|
+
|
82
|
+
// Add the attributes
|
83
|
+
for (const attr in this.attributes) {
|
84
|
+
if (Object.prototype.hasOwnProperty.call(this.attributes, attr )) {
|
85
|
+
markup += ` ${attr}="${utils.escape(this.attributes[attr])}"`;
|
86
|
+
}
|
87
|
+
}
|
88
|
+
|
89
|
+
markup += ">";
|
90
|
+
|
91
|
+
// Add the markup of the children, also as markup
|
92
|
+
for (let i = 0; i < this.children.length; i++) {
|
93
|
+
markup += this.children[i].toMarkup();
|
94
|
+
}
|
95
|
+
|
96
|
+
markup += `</${tagName}>`;
|
97
|
+
|
98
|
+
return markup;
|
99
|
+
};
|
100
|
+
|
101
|
+
/**
|
102
|
+
* This node represents a span node, with a className, a list of children, and
|
103
|
+
* an inline style.
|
104
|
+
*
|
105
|
+
*/
|
106
|
+
export class Span {
|
107
|
+
constructor(classes, children, style) {
|
108
|
+
initNode.call(this, classes, style);
|
109
|
+
this.children = children || [];
|
110
|
+
}
|
111
|
+
|
112
|
+
setAttribute(attribute, value) {
|
113
|
+
this.attributes[attribute] = value;
|
114
|
+
}
|
115
|
+
|
116
|
+
toNode() {
|
117
|
+
return toNode.call(this, "span");
|
118
|
+
}
|
119
|
+
|
120
|
+
toMarkup() {
|
121
|
+
return toMarkup.call(this, "span");
|
122
|
+
}
|
123
|
+
}
|
124
|
+
|
125
|
+
export class TextNode {
|
126
|
+
constructor(text) {
|
127
|
+
this.text = text;
|
128
|
+
}
|
129
|
+
toNode() {
|
130
|
+
return document.createTextNode(this.text);
|
131
|
+
}
|
132
|
+
toMarkup() {
|
133
|
+
return utils.escape(this.text);
|
134
|
+
}
|
135
|
+
}
|
136
|
+
|
137
|
+
/**
|
138
|
+
* This node represents an image embed (<img>) element.
|
139
|
+
*/
|
140
|
+
export class Img {
|
141
|
+
constructor(src, alt, style) {
|
142
|
+
this.alt = alt;
|
143
|
+
this.src = src;
|
144
|
+
this.classes = ["mord"];
|
145
|
+
this.style = style;
|
146
|
+
}
|
147
|
+
|
148
|
+
hasClass(className) {
|
149
|
+
return this.classes.includes(className);
|
150
|
+
}
|
151
|
+
|
152
|
+
toNode() {
|
153
|
+
const node = document.createElement("img");
|
154
|
+
node.src = this.src;
|
155
|
+
node.alt = this.alt;
|
156
|
+
node.className = "mord";
|
157
|
+
|
158
|
+
// Apply inline styles
|
159
|
+
for (const style in this.style) {
|
160
|
+
if (Object.prototype.hasOwnProperty.call(this.style, style )) {
|
161
|
+
node.style[style] = this.style[style];
|
162
|
+
}
|
163
|
+
}
|
164
|
+
|
165
|
+
return node;
|
166
|
+
}
|
167
|
+
|
168
|
+
toMarkup() {
|
169
|
+
let markup = `<img src='${this.src}' alt='${this.alt}'`;
|
170
|
+
|
171
|
+
// Add the styles, after hyphenation
|
172
|
+
let styles = "";
|
173
|
+
for (const style in this.style) {
|
174
|
+
if (Object.prototype.hasOwnProperty.call(this.style, style )) {
|
175
|
+
styles += `${utils.hyphenate(style)}:${this.style[style]};`;
|
176
|
+
}
|
177
|
+
}
|
178
|
+
if (styles) {
|
179
|
+
markup += ` style="${utils.escape(styles)}"`;
|
180
|
+
}
|
181
|
+
|
182
|
+
markup += "/>";
|
183
|
+
return markup;
|
184
|
+
}
|
185
|
+
}
|