mathup
Version:
Easy MathML authoring tool with a quick to write syntax
42 lines (36 loc) • 1.24 kB
JavaScript
import transforms from "./transforms/index.js";
/**
* @typedef {import("../parser/index.js").Node} ASTNode
* @typedef {object} TransformerOptions
* @property {"ltr" | "rtl" | null} [dir=null] - The reading direction of the
* output. Default is `null`
* @property {"block" | "inline" | null} [display=null] - Whether the expression
* should be in display mode. Default is `null` Default is `null` Default is
* `null` Default is `null`
* @typedef {object} Tag
* @property {string} tag
* @property {Record<string, string | number | boolean | undefined | null>} [attrs]
* @property {(Tag | null)[]} [childNodes]
* @property {string} [textContent]
*/
/**
* @template {ASTNode} [Node=ASTNode] Default is `ASTNode`
* @typedef {(
* node: Node,
* transform: (node: ASTNode) => Tag | null,
* options: Required<TransformerOptions>,
* ) => Tag | null} TransformFn
*/
/**
* @param {Required<TransformerOptions>} options
* @returns {(node: ASTNode) => Tag | null}
*/
export default function transformer(options) {
return function transform(node) {
const transformNode = transforms.get(node.type);
if (!transformNode) {
return null;
}
return transformNode(node, transform, options);
};
}