Move "ordgroup" and "tag" builders into functions/*. (#1339)

* Move "ordgroup" builders to functions/ordgroup.js.
* Move "tag" MathML builder to functions/tag.js.
This commit is contained in:
Ashish Myles
2018-05-22 22:18:39 -04:00
committed by GitHub
parent 485c509879
commit 4c3439192f
7 changed files with 46 additions and 24 deletions

View File

@@ -242,9 +242,6 @@ export const makeNullDelimiter = function(options, classes) {
* Simpler types come at the beginning, while complicated types come afterwards.
*/
export const groupTypes = {
ordgroup: (group, options) => makeSpan(
["mord"], buildExpression(group.value, options, true), options),
supsub(group, options) {
// Superscript and subscripts are handled in the TeXbook on page
// 445-446, rules 18(a-f).

View File

@@ -79,10 +79,6 @@ export const getVariant = function(group, options) {
*/
export const groupTypes = {};
groupTypes.ordgroup = function(group, options) {
return buildExpressionRow(group.value, options);
};
groupTypes.supsub = function(group, options) {
// Is the inner group a relevant horizonal brace?
let isBrace = false;
@@ -140,21 +136,6 @@ groupTypes.supsub = function(group, options) {
return node;
};
groupTypes.tag = function(group, options) {
const table = new mathMLTree.MathNode("mtable", [
new mathMLTree.MathNode("mlabeledtr", [
new mathMLTree.MathNode("mtd", [
buildExpressionRow(group.value.tag, options),
]),
new mathMLTree.MathNode("mtd", [
buildExpressionRow(group.value.body, options),
]),
]),
]);
table.setAttribute("side", "right");
return table;
};
/**
* Takes a list of nodes, builds them, and returns a list of the generated
* MathML nodes. Also combine consecutive <mtext> outputs into a single

View File

@@ -210,7 +210,7 @@ export function defineFunctionBuilders<NODETYPE: NodeType>({
type, htmlBuilder, mathmlBuilder,
}: {|
type: NODETYPE,
htmlBuilder: HtmlBuilder<NODETYPE>,
htmlBuilder?: HtmlBuilder<NODETYPE>,
mathmlBuilder: MathMLBuilder<NODETYPE>,
|}) {
defineFunction({

View File

@@ -27,6 +27,7 @@ import "./functions/mclass";
import "./functions/mod";
import "./functions/op";
import "./functions/operatorname";
import "./functions/ordgroup";
import "./functions/overline";
import "./functions/phantom";
import "./functions/raisebox";
@@ -38,6 +39,7 @@ import "./functions/styling";
import "./functions/symbolsOp";
import "./functions/symbolsOrd";
import "./functions/symbolsSpacing";
import "./functions/tag";
import "./functions/text";
import "./functions/underline";
import "./functions/verb";

18
src/functions/ordgroup.js Normal file
View File

@@ -0,0 +1,18 @@
// @flow
import {defineFunctionBuilders} from "../defineFunction";
import buildCommon from "../buildCommon";
import * as html from "../buildHTML";
import * as mml from "../buildMathML";
defineFunctionBuilders({
type: "ordgroup",
htmlBuilder(group, options) {
return buildCommon.makeSpan(
["mord"], html.buildExpression(group.value, options, true), options);
},
mathmlBuilder(group, options) {
return mml.buildExpressionRow(group.value, options);
},
});

24
src/functions/tag.js Normal file
View File

@@ -0,0 +1,24 @@
// @flow
import {defineFunctionBuilders} from "../defineFunction";
import mathMLTree from "../mathMLTree";
import * as mml from "../buildMathML";
defineFunctionBuilders({
type: "tag",
mathmlBuilder(group, options) {
const table = new mathMLTree.MathNode("mtable", [
new mathMLTree.MathNode("mlabeledtr", [
new mathMLTree.MathNode("mtd", [
mml.buildExpressionRow(group.value.tag, options),
]),
new mathMLTree.MathNode("mtd", [
mml.buildExpressionRow(group.value.body, options),
]),
]),
]);
table.setAttribute("side", "right");
return table;
},
});

View File

@@ -20,7 +20,7 @@ export type MathNodeType =
"mtext" | "mn" | "mo" | "mi" | "mspace" |
"mover" | "munder" | "munderover" | "msup" | "msub" |
"mfrac" | "mroot" | "msqrt" |
"mtable" | "mtr" | "mtd" |
"mtable" | "mtr" | "mtd" | "mlabeledtr" |
"mrow" | "menclose" |
"mstyle" | "mpadded" | "mphantom";