@unified-latex/unified-latex-util-arguments
Advanced tools
+72
-14
@@ -0,1 +1,2 @@ | ||
| "use strict"; | ||
| var __defProp = Object.defineProperty; | ||
@@ -25,2 +26,3 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
| getArgsContent: () => getArgsContent, | ||
| getNamedArgsContent: () => getNamedArgsContent, | ||
| gobbleArguments: () => gobbleArguments, | ||
@@ -40,3 +42,7 @@ unifiedLatexAttachMacroArguments: () => unifiedLatexAttachMacroArguments | ||
| if (typeof argSpec === "string" || !argSpec.type) { | ||
| throw new Error(`argSpec must be an already-parsed argument specification, not "${JSON.stringify(argSpec)}"`); | ||
| throw new Error( | ||
| `argSpec must be an already-parsed argument specification, not "${JSON.stringify( | ||
| argSpec | ||
| )}"` | ||
| ); | ||
| } | ||
@@ -56,7 +62,9 @@ let argument = null; | ||
| const closeMark = argSpec.closeBrace || ""; | ||
| const acceptGroup = argSpec.type === "mandatory" && openMark === "{" && closeMark === "}"; | ||
| const acceptGroup = (argSpec.type === "mandatory" || argSpec.type === "optional") && openMark === "{" && closeMark === "}"; | ||
| function findBracePositions() { | ||
| let openMarkPos = null; | ||
| if (openMark) { | ||
| openMarkPos = nodes.findIndex((node, i) => i >= currPos && import_unified_latex_util_match.match.string(node, openMark)); | ||
| openMarkPos = nodes.findIndex( | ||
| (node, i) => i >= currPos && import_unified_latex_util_match.match.string(node, openMark) | ||
| ); | ||
| if (openMarkPos < currPos) { | ||
@@ -68,3 +76,5 @@ openMarkPos = null; | ||
| if (openMarkPos != null) { | ||
| closeMarkPos = nodes.findIndex((node, i) => i >= openMarkPos + 1 && import_unified_latex_util_match.match.string(node, closeMark)); | ||
| closeMarkPos = nodes.findIndex( | ||
| (node, i) => i >= openMarkPos + 1 && import_unified_latex_util_match.match.string(node, closeMark) | ||
| ); | ||
| if (closeMarkPos < openMarkPos + 1) { | ||
@@ -96,2 +106,10 @@ closeMarkPos = null; | ||
| case "optional": | ||
| if (acceptGroup && import_unified_latex_util_match.match.group(currNode)) { | ||
| argument = (0, import_unified_latex_builder.arg)(currNode.content, { | ||
| openMark, | ||
| closeMark | ||
| }); | ||
| currPos++; | ||
| break; | ||
| } | ||
| if (import_unified_latex_util_match.match.string(currNode, openMark)) { | ||
@@ -110,3 +128,7 @@ const [openMarkPos, closeMarkPos] = findBracePositions(); | ||
| case "optionalStar": | ||
| if (import_unified_latex_util_match.match.string(currNode, "*")) { | ||
| case "optionalToken": | ||
| if (import_unified_latex_util_match.match.string( | ||
| currNode, | ||
| argSpec.type === "optionalStar" ? "*" : argSpec.token | ||
| )) { | ||
| argument = (0, import_unified_latex_builder.arg)([currNode], { openMark: "", closeMark: "" }); | ||
@@ -118,3 +140,5 @@ currPos++; | ||
| default: | ||
| console.warn(`Don't know how to find an argument of argspec type "${argSpec.type}"`); | ||
| console.warn( | ||
| `Don't know how to find an argument of argspec type "${argSpec.type}"` | ||
| ); | ||
| } | ||
@@ -134,3 +158,7 @@ const nodesRemoved = argument ? currPos - startPos : 0; | ||
| for (const spec of argSpec) { | ||
| const { argument, nodesRemoved: removed } = gobbleSingleArgument(nodes, spec, startPos); | ||
| const { argument, nodesRemoved: removed } = gobbleSingleArgument( | ||
| nodes, | ||
| spec, | ||
| startPos | ||
| ); | ||
| if (argument) { | ||
@@ -184,5 +212,9 @@ args.push(argument); | ||
| function attachMacroArgs(tree, macros) { | ||
| (0, import_unified_latex_util_visit.visit)(tree, (nodes) => { | ||
| attachMacroArgsInArray(nodes, macros); | ||
| }, { includeArrays: true, test: Array.isArray }); | ||
| (0, import_unified_latex_util_visit.visit)( | ||
| tree, | ||
| (nodes) => { | ||
| attachMacroArgsInArray(nodes, macros); | ||
| }, | ||
| { includeArrays: true, test: Array.isArray } | ||
| ); | ||
| } | ||
@@ -196,7 +228,13 @@ | ||
| if (Object.keys(macros).length === 0) { | ||
| console.warn("Attempting to attach macro arguments but no macros are specified."); | ||
| console.warn( | ||
| "Attempting to attach macro arguments but no macros are specified." | ||
| ); | ||
| } | ||
| (0, import_unified_latex_util_visit2.visit)(tree, (nodes) => { | ||
| attachMacroArgsInArray(nodes, macros); | ||
| }, { includeArrays: true, test: Array.isArray }); | ||
| (0, import_unified_latex_util_visit2.visit)( | ||
| tree, | ||
| (nodes) => { | ||
| attachMacroArgsInArray(nodes, macros); | ||
| }, | ||
| { includeArrays: true, test: Array.isArray } | ||
| ); | ||
| }; | ||
@@ -217,2 +255,22 @@ }; | ||
| } | ||
| function getNamedArgsContent(node, namedArgumentsFallback = []) { | ||
| var _a; | ||
| const names = ((_a = node._renderInfo) == null ? void 0 : _a.namedArguments) || namedArgumentsFallback; | ||
| if (!Array.isArray(node.args) || !Array.isArray(names) || names.length === 0) { | ||
| return {}; | ||
| } | ||
| const ret = {}; | ||
| node.args.forEach((arg3, i) => { | ||
| const name = names[i]; | ||
| if (name == null) { | ||
| return; | ||
| } | ||
| let val = arg3.content; | ||
| if (arg3.openMark === "" && arg3.content.length === 0) { | ||
| val = null; | ||
| } | ||
| ret[name] = val; | ||
| }); | ||
| return ret; | ||
| } | ||
| //# sourceMappingURL=index.cjs.map |
+3
-3
| { | ||
| "version": 3, | ||
| "sources": ["../index.ts", "../libs/gobble-arguments.ts", "../libs/gobble-single-argument.ts", "../libs/attach-arguments.ts", "../libs/unified-latex-attach-macro-arguments.ts", "../libs/get-args-content.ts"], | ||
| "sourcesContent": ["export { gobbleArguments } from \"./libs/gobble-arguments\";\nexport { attachMacroArgs, attachMacroArgsInArray } from \"./libs/attach-arguments\";\nexport * from \"./libs/unified-latex-attach-macro-arguments\";\nexport * from \"./libs/get-args-content\";\n\n// NOTE: The docstring comment must be the last item in the index.ts file!\n/**\n * ## What is this?\n *\n * Functions to help modify and attach arguments to macros in a `unified-latex` Abstract Syntax Tree (AST).\n * \n * By default, TeX doesn't actually have a concept of macro \"arguments\". Instead, TeX searches the\n * tokens after a macro and processes them according to the macro's rules. However, LaTeX attempts\n * to make macros look like functions that accept arguments. To attach the \"arguments\" to a macro\n * node, the `unified-latex` AST needs to be reparsed and manipulated.\n *\n * ## When should I use this?\n *\n * If you have custom macros that you want arguments attached to.\n * \n * If you know ahead of time which macros need arguments attached to them, use `unified-latex-util-parse`\n * and pass in the appropriate macro info instead.\n */\n", "import {\n ArgSpecAst as ArgSpec,\n parse as parseArgspec,\n} from \"@unified-latex/unified-latex-util-argspec\";\nimport * as Ast from \"@unified-latex/unified-latex-types\";\nimport { arg } from \"@unified-latex/unified-latex-builder\";\nimport { gobbleSingleArgument } from \"./gobble-single-argument\";\n\n/**\n * Gobbles an argument of whose type is specified\n * by `argSpec` starting at the position `startPos`. If an argument couldn't be found,\n * `argument` will be `null`.\n */\nexport function gobbleArguments(\n nodes: Ast.Node[],\n argSpec: string | ArgSpec.Node[],\n startPos = 0\n): {\n args: Ast.Argument[];\n nodesRemoved: number;\n} {\n if (typeof argSpec === \"string\") {\n argSpec = parseArgspec(argSpec);\n }\n\n const args: Ast.Argument[] = [];\n let nodesRemoved = 0;\n for (const spec of argSpec) {\n const { argument, nodesRemoved: removed } = gobbleSingleArgument(\n nodes,\n spec,\n startPos\n );\n if (argument) {\n args.push(argument);\n nodesRemoved += removed;\n } else {\n args.push(arg([], { openMark: \"\", closeMark: \"\" }));\n }\n }\n\n return { args, nodesRemoved };\n}\n", "import { ArgSpecAst as ArgSpec } from \"@unified-latex/unified-latex-util-argspec\";\nimport * as Ast from \"@unified-latex/unified-latex-types\";\nimport { match } from \"@unified-latex/unified-latex-util-match\";\nimport { arg } from \"@unified-latex/unified-latex-builder\";\n\n/**\n * Gobbles an argument of whose type is specified\n * by `argSpec` starting at the position `startPos`. If an argument couldn't be found,\n * `argument` will be `null`.\n */\nexport function gobbleSingleArgument(\n nodes: Ast.Node[],\n argSpec: ArgSpec.Node,\n startPos = 0\n): {\n argument: Ast.Argument | null;\n nodesRemoved: number;\n} {\n if (typeof argSpec === \"string\" || !argSpec.type) {\n throw new Error(\n `argSpec must be an already-parsed argument specification, not \"${JSON.stringify(\n argSpec\n )}\"`\n );\n }\n\n let argument: Ast.Argument | null = null;\n\n let currPos = startPos;\n\n // Gobble whitespace from `currPos` onward, updating `currPos`.\n // If `argSpec` specifies leading whitespace is not allowed,\n // this function does nothing.\n const gobbleWhitespace = (argSpec as ArgSpec.LeadingWhitespace)\n .noLeadingWhitespace\n ? () => {}\n : () => {\n while (currPos < nodes.length) {\n if (!match.whitespace(nodes[currPos])) {\n break;\n }\n currPos++;\n }\n };\n\n const openMark: string = (argSpec as any).openBrace || \"\";\n const closeMark: string = (argSpec as any).closeBrace || \"\";\n\n // Only mandatory arguments can be wrapped in {...}.\n // Since we already parse such things as groups, we need to\n // check the open and closing symbols to see if we allow for\n // groups to be accepted as arguments\n const acceptGroup =\n argSpec.type === \"mandatory\" && openMark === \"{\" && closeMark === \"}\";\n\n // Find the position of the open brace and the closing brace.\n // The position(s) are null if the brace isn't found.\n function findBracePositions(): [number | null, number | null] {\n let openMarkPos: number | null = null;\n if (openMark) {\n openMarkPos = nodes.findIndex(\n (node, i) => i >= currPos && match.string(node, openMark)\n );\n if (openMarkPos < currPos) {\n openMarkPos = null;\n }\n }\n let closeMarkPos: number | null = null;\n if (openMarkPos != null) {\n closeMarkPos = nodes.findIndex(\n (node, i) =>\n i >= (openMarkPos as number) + 1 &&\n match.string(node, closeMark)\n );\n if (closeMarkPos < openMarkPos + 1) {\n closeMarkPos = null;\n }\n }\n return [openMarkPos, closeMarkPos];\n }\n\n // Do the actual matching\n gobbleWhitespace();\n const currNode = nodes[currPos];\n if (\n currNode == null ||\n match.comment(currNode) ||\n match.parbreak(currNode)\n ) {\n return { argument, nodesRemoved: 0 };\n }\n\n switch (argSpec.type) {\n case \"mandatory\":\n if (acceptGroup) {\n let content: Ast.Node[] = [currNode];\n if (match.group(currNode)) {\n // Unwrap a group if there is one.\n content = currNode.content;\n }\n argument = arg(content, {\n openMark,\n closeMark,\n });\n currPos++;\n break;\n }\n // The fallthrough here is on purpose! Matching a mandatory\n // argument and an optional argument is the same for our purposes.\n // We're not going to fail to parse because of a missing argument.\n case \"optional\":\n // We have already gobbled whitespace, so at this point, `currNode`\n // is either an openMark or we don't have an optional argument.\n if (match.string(currNode, openMark)) {\n // If we're here, we have custom braces to match\n const [openMarkPos, closeMarkPos] = findBracePositions();\n if (openMarkPos != null && closeMarkPos != null) {\n argument = arg(nodes.slice(openMarkPos + 1, closeMarkPos), {\n openMark,\n closeMark,\n });\n currPos = closeMarkPos + 1;\n break;\n }\n }\n break;\n case \"optionalStar\":\n if (match.string(currNode, \"*\")) {\n argument = arg([currNode], { openMark: \"\", closeMark: \"\" });\n currPos++;\n break;\n }\n break;\n default:\n console.warn(\n `Don't know how to find an argument of argspec type \"${argSpec.type}\"`\n );\n }\n\n // `currPos` is has already stepped past any whitespace. However,\n // if we did not consume an argument, we don't want to consume the whitespace.\n const nodesRemoved = argument ? currPos - startPos : 0;\n nodes.splice(startPos, nodesRemoved);\n return { argument, nodesRemoved };\n}\n", "import * as Ast from \"@unified-latex/unified-latex-types\";\nimport { match } from \"@unified-latex/unified-latex-util-match\";\nimport { MacroInfoRecord } from \"@unified-latex/unified-latex-types\";\nimport { updateRenderInfo } from \"@unified-latex/unified-latex-util-render-info\";\nimport { gobbleArguments } from \"./gobble-arguments\";\nimport { visit } from \"@unified-latex/unified-latex-util-visit\";\n\n/**\n * Search (in a right-associative way) through the array for instances of\n * `macros` and attach arguments to the macro. Argument signatures are\n * specified by `macros[].signature`.\n *\n * Info stored in `macros[].renderInfo` will be attached to the node\n * with attribute `_renderInfo`.\n */\nexport function attachMacroArgsInArray(\n nodes: Ast.Node[],\n macros: MacroInfoRecord\n): void {\n // Some preliminaries that are only used if `ast` is an array.\n let currIndex: number;\n\n /**\n * Determine whether `node` matches one of the macros in `macros`.\n * Care is taken when matching because not all macros have\n * `\\` as their escape token.\n */\n const isRelevantMacro = match.createMacroMatcher(macros);\n\n function gobbleUntilMacro() {\n // Step backwards until we find the required macro\n while (currIndex >= 0 && !isRelevantMacro(nodes[currIndex])) {\n currIndex--;\n }\n }\n\n // Search for an occurrence of any of the macros `macroName` and its arguments.\n // Some macros are right-associative, so we should start searching from\n // the right\n currIndex = nodes.length - 1;\n while (currIndex >= 0) {\n gobbleUntilMacro();\n if (currIndex < 0) {\n // We didn't find an occurrence of the macro\n return;\n }\n\n // Store the currIndex, which is where the macro is. Start searching\n // for its arguments at the next index.\n const macroIndex = currIndex;\n const macro = nodes[macroIndex] as Ast.Macro;\n const macroName = macro.content;\n const macroInfo = macros[macroName];\n\n // Add `._renderInfo` if we have any\n updateRenderInfo(macro, macroInfo.renderInfo);\n\n // If the macro has no signature, it shouldn't consume any arguments. Just move along.\n // Node: It is important that this happens *after* `updateRenderInfo` is called, since\n // we still want to update the render info even if there are no args.\n if (macroInfo.signature == null) {\n currIndex--;\n continue;\n }\n\n // We don't want to search for macro arguments if we already\n // found them. If the macro has arguments, we assume that\n // they've already been attached\n if (macro.args != null) {\n currIndex = macroIndex - 1;\n continue;\n }\n\n // `currIndex` is the position of the macro. We want to start\n // looking for the arguments right after the macro\n currIndex++;\n const { args } = gobbleArguments(nodes, macroInfo.signature, currIndex);\n macro.args = args;\n // After we've gobbled the arguments, set\n // ourselves one space before the macro so we can continue.\n currIndex = macroIndex - 1;\n }\n}\n\n/**\n * Recursively search for and attach the arguments for a\n * particular macro to its AST node. `macros` should\n * contain a `signature` property which specifies the arguments\n * signature in xparse syntax.\n */\nexport function attachMacroArgs(tree: Ast.Ast, macros: MacroInfoRecord) {\n visit(\n tree,\n (nodes) => {\n attachMacroArgsInArray(nodes, macros);\n },\n { includeArrays: true, test: Array.isArray }\n );\n}\n", "import { Plugin } from \"unified\";\nimport * as Ast from \"@unified-latex/unified-latex-types\";\nimport { MacroInfoRecord } from \"@unified-latex/unified-latex-types\";\nimport { visit } from \"@unified-latex/unified-latex-util-visit\";\nimport { attachMacroArgsInArray } from \"./attach-arguments\";\n\ntype PluginOptions = { macros: MacroInfoRecord } | undefined;\n\n/**\n * Unified plugin to attach macro arguments to the macros specified via the `macros`\n * option.\n *\n * @param macros An object whose keys are macro names and values contains information about the macro and its argument signature.\n */\nexport const unifiedLatexAttachMacroArguments: Plugin<\n PluginOptions[],\n Ast.Root,\n Ast.Root\n> = function unifiedLatexAttachMacroArguments(options) {\n return (tree) => {\n const { macros = {} } = options || {};\n if (Object.keys(macros).length === 0) {\n console.warn(\n \"Attempting to attach macro arguments but no macros are specified.\"\n );\n }\n visit(\n tree,\n (nodes) => {\n attachMacroArgsInArray(nodes, macros);\n },\n { includeArrays: true, test: Array.isArray }\n );\n };\n};\n", "import * as Ast from \"@unified-latex/unified-latex-types\";\n\n/**\n * Returns the content of `args` for a macro or environment as an array. If an argument\n * was omitted (e.g., because it was an optional arg that wasn't included), then `null` is returned.\n */\nexport function getArgsContent(\n node: Ast.Macro | Ast.Environment\n): (Ast.Node[] | null)[] {\n if (!Array.isArray(node.args)) {\n return [];\n }\n\n return node.args.map((arg) => {\n if (arg.openMark === \"\" && arg.content.length === 0) {\n return null;\n }\n return arg.content;\n });\n}\n"], | ||
| "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,wCAGO;AAEP,oCAAoB;;;ACHpB,sCAAsB;AACtB,mCAAoB;AAOb,8BACH,OACA,SACA,WAAW,GAIb;AACE,MAAI,OAAO,YAAY,YAAY,CAAC,QAAQ,MAAM;AAC9C,UAAM,IAAI,MACN,kEAAkE,KAAK,UACnE,OACJ,IACJ;AAAA,EACJ;AAEA,MAAI,WAAgC;AAEpC,MAAI,UAAU;AAKd,QAAM,mBAAoB,QACrB,sBACC,MAAM;AAAA,EAAC,IACP,MAAM;AACF,WAAO,UAAU,MAAM,QAAQ;AAC3B,UAAI,CAAC,sCAAM,WAAW,MAAM,QAAQ,GAAG;AACnC;AAAA,MACJ;AACA;AAAA,IACJ;AAAA,EACJ;AAEN,QAAM,WAAoB,QAAgB,aAAa;AACvD,QAAM,YAAqB,QAAgB,cAAc;AAMzD,QAAM,cACF,QAA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Q,MAAM;AACpB,kBAAY,aAAa;AACzB;AAAA,IACJ;AAIA;AACA,UAAM,EAAE,SAAS,gBAAgB,OAAO,UAAU,WAAW,SAAS;AACtE,UAAM,OAAO;AAGb,gBAAY,aAAa;AAAA,EAC7B;AACJ;AAQO,yBAAyB,MAAe,QAAyB;AACpE,6CACI,MACA,CAAC,UAAU;AACP,2BAAuB,OAAO,MAAM;AAAA,EACxC,GACA,EAAE,eAAe,MAAM,MAAM,MAAM,QAAQ,CAC/C;AACJ;;;AC/FA,uCAAsB;AAWf,IAAM,mCAIT,2CAA0C,SAAS;AACnD,SAAO,CAAC,SAAS;AACb,UAAM,EAAE,SAAS,CAAC,MAAM,WAAW,CAAC;AACpC,QAAI,OAAO,KAAK,MAAM,EAAE,WAAW,GAAG;AAClC,cAAQ,KACJ,mEACJ;AAAA,IACJ;AACA,gDACI,MACA,CAAC,UAAU;AACP,6BAAuB,OAAO,MAAM;AAAA,IACxC,GACA,EAAE,eAAe,MAAM,MAAM,MAAM,QAAQ,CAC/C;AAAA,EACJ;AACJ;;;AC5BO,wBACH,MACqB;AACrB,MAAI,CAAC,MAAM,QAAQ,KAAK,IAAI,GAAG;AAC3B,WAAO,CAAC;AAAA,EACZ;AAEA,SAAO,KAAK,KAAK,IAAI,CAAC,SAAQ;AAC1B,QAAI,KAAI,aAAa,MAAM,KAAI,QAAQ,WAAW,GAAG;AACjD,aAAO;AAAA,IACX;AACA,WAAO,KAAI;AAAA,EACf,CAAC;AACL;", | ||
| "names": [] | ||
| "sourcesContent": ["export { gobbleArguments } from \"./libs/gobble-arguments\";\nexport { attachMacroArgs, attachMacroArgsInArray } from \"./libs/attach-arguments\";\nexport * from \"./libs/unified-latex-attach-macro-arguments\";\nexport * from \"./libs/get-args-content\";\n\n// NOTE: The docstring comment must be the last item in the index.ts file!\n/**\n * ## What is this?\n *\n * Functions to help modify and attach arguments to macros in a `unified-latex` Abstract Syntax Tree (AST).\n * \n * By default, TeX doesn't actually have a concept of macro \"arguments\". Instead, TeX searches the\n * tokens after a macro and processes them according to the macro's rules. However, LaTeX attempts\n * to make macros look like functions that accept arguments. To attach the \"arguments\" to a macro\n * node, the `unified-latex` AST needs to be reparsed and manipulated.\n *\n * ## When should I use this?\n *\n * If you have custom macros that you want arguments attached to.\n * \n * If you know ahead of time which macros need arguments attached to them, use `unified-latex-util-parse`\n * and pass in the appropriate macro info instead.\n */\n", "import {\n ArgSpecAst as ArgSpec,\n parse as parseArgspec,\n} from \"@unified-latex/unified-latex-util-argspec\";\nimport * as Ast from \"@unified-latex/unified-latex-types\";\nimport { arg } from \"@unified-latex/unified-latex-builder\";\nimport { gobbleSingleArgument } from \"./gobble-single-argument\";\n\n/**\n * Gobbles an argument of whose type is specified\n * by `argSpec` starting at the position `startPos`. If an argument couldn't be found,\n * `argument` will be `null`.\n */\nexport function gobbleArguments(\n nodes: Ast.Node[],\n argSpec: string | ArgSpec.Node[],\n startPos = 0\n): {\n args: Ast.Argument[];\n nodesRemoved: number;\n} {\n if (typeof argSpec === \"string\") {\n argSpec = parseArgspec(argSpec);\n }\n\n const args: Ast.Argument[] = [];\n let nodesRemoved = 0;\n for (const spec of argSpec) {\n const { argument, nodesRemoved: removed } = gobbleSingleArgument(\n nodes,\n spec,\n startPos\n );\n if (argument) {\n args.push(argument);\n nodesRemoved += removed;\n } else {\n args.push(arg([], { openMark: \"\", closeMark: \"\" }));\n }\n }\n\n return { args, nodesRemoved };\n}\n", "import { ArgSpecAst as ArgSpec } from \"@unified-latex/unified-latex-util-argspec\";\nimport * as Ast from \"@unified-latex/unified-latex-types\";\nimport { match } from \"@unified-latex/unified-latex-util-match\";\nimport { arg } from \"@unified-latex/unified-latex-builder\";\n\n/**\n * Gobbles an argument of whose type is specified\n * by `argSpec` starting at the position `startPos`. If an argument couldn't be found,\n * `argument` will be `null`.\n */\nexport function gobbleSingleArgument(\n nodes: Ast.Node[],\n argSpec: ArgSpec.Node,\n startPos = 0\n): {\n argument: Ast.Argument | null;\n nodesRemoved: number;\n} {\n if (typeof argSpec === \"string\" || !argSpec.type) {\n throw new Error(\n `argSpec must be an already-parsed argument specification, not \"${JSON.stringify(\n argSpec\n )}\"`\n );\n }\n\n let argument: Ast.Argument | null = null;\n\n let currPos = startPos;\n\n // Gobble whitespace from `currPos` onward, updating `currPos`.\n // If `argSpec` specifies leading whitespace is not allowed,\n // this function does nothing.\n const gobbleWhitespace = (argSpec as ArgSpec.LeadingWhitespace)\n .noLeadingWhitespace\n ? () => {}\n : () => {\n while (currPos < nodes.length) {\n if (!match.whitespace(nodes[currPos])) {\n break;\n }\n currPos++;\n }\n };\n\n const openMark: string = (argSpec as any).openBrace || \"\";\n const closeMark: string = (argSpec as any).closeBrace || \"\";\n\n // Only mandatory arguments can be wrapped in {...}.\n // Since we already parse such things as groups, we need to\n // check the open and closing symbols to see if we allow for\n // groups to be accepted as arguments\n const acceptGroup =\n (argSpec.type === \"mandatory\" || argSpec.type === \"optional\") &&\n openMark === \"{\" &&\n closeMark === \"}\";\n\n // Find the position of the open brace and the closing brace.\n // The position(s) are null if the brace isn't found.\n function findBracePositions(): [number | null, number | null] {\n let openMarkPos: number | null = null;\n if (openMark) {\n openMarkPos = nodes.findIndex(\n (node, i) => i >= currPos && match.string(node, openMark)\n );\n if (openMarkPos < currPos) {\n openMarkPos = null;\n }\n }\n let closeMarkPos: number | null = null;\n if (openMarkPos != null) {\n closeMarkPos = nodes.findIndex(\n (node, i) =>\n i >= (openMarkPos as number) + 1 &&\n match.string(node, closeMark)\n );\n if (closeMarkPos < openMarkPos + 1) {\n closeMarkPos = null;\n }\n }\n return [openMarkPos, closeMarkPos];\n }\n\n // Do the actual matching\n gobbleWhitespace();\n const currNode = nodes[currPos];\n if (\n currNode == null ||\n match.comment(currNode) ||\n match.parbreak(currNode)\n ) {\n return { argument, nodesRemoved: 0 };\n }\n\n switch (argSpec.type) {\n case \"mandatory\":\n if (acceptGroup) {\n // We have already gobbled whitespace, so at this point, `currNode`\n // is either an openMark or we don't have an optional argument.\n let content: Ast.Node[] = [currNode];\n if (match.group(currNode)) {\n // Unwrap a group if there is one.\n content = currNode.content;\n }\n argument = arg(content, {\n openMark,\n closeMark,\n });\n currPos++;\n break;\n }\n // NOTE: Fallthrough is on purpose.\n // Matching a mandatory argument and an optional argument is the same for our purposes\n // because we're not going to fail to parse because of a missing argument.\n case \"optional\":\n // It is possible that an optional argument accepts a group if its open/close braces are `{}`\n if (acceptGroup && match.group(currNode)) {\n argument = arg(currNode.content, {\n openMark,\n closeMark,\n });\n currPos++;\n break;\n }\n if (match.string(currNode, openMark)) {\n // If we're here, we have custom braces to match\n const [openMarkPos, closeMarkPos] = findBracePositions();\n if (openMarkPos != null && closeMarkPos != null) {\n argument = arg(nodes.slice(openMarkPos + 1, closeMarkPos), {\n openMark,\n closeMark,\n });\n currPos = closeMarkPos + 1;\n break;\n }\n }\n break;\n case \"optionalStar\":\n case \"optionalToken\":\n if (\n match.string(\n currNode,\n argSpec.type === \"optionalStar\" ? \"*\" : argSpec.token\n )\n ) {\n argument = arg([currNode], { openMark: \"\", closeMark: \"\" });\n currPos++;\n break;\n }\n break;\n default:\n console.warn(\n `Don't know how to find an argument of argspec type \"${argSpec.type}\"`\n );\n }\n\n // `currPos` is has already stepped past any whitespace. However,\n // if we did not consume an argument, we don't want to consume the whitespace.\n const nodesRemoved = argument ? currPos - startPos : 0;\n nodes.splice(startPos, nodesRemoved);\n return { argument, nodesRemoved };\n}\n", "import * as Ast from \"@unified-latex/unified-latex-types\";\nimport { match } from \"@unified-latex/unified-latex-util-match\";\nimport { MacroInfoRecord } from \"@unified-latex/unified-latex-types\";\nimport { updateRenderInfo } from \"@unified-latex/unified-latex-util-render-info\";\nimport { gobbleArguments } from \"./gobble-arguments\";\nimport { visit } from \"@unified-latex/unified-latex-util-visit\";\n\n/**\n * Search (in a right-associative way) through the array for instances of\n * `macros` and attach arguments to the macro. Argument signatures are\n * specified by `macros[].signature`.\n *\n * Info stored in `macros[].renderInfo` will be attached to the node\n * with attribute `_renderInfo`.\n */\nexport function attachMacroArgsInArray(\n nodes: Ast.Node[],\n macros: MacroInfoRecord\n): void {\n // Some preliminaries that are only used if `ast` is an array.\n let currIndex: number;\n\n /**\n * Determine whether `node` matches one of the macros in `macros`.\n * Care is taken when matching because not all macros have\n * `\\` as their escape token.\n */\n const isRelevantMacro = match.createMacroMatcher(macros);\n\n function gobbleUntilMacro() {\n // Step backwards until we find the required macro\n while (currIndex >= 0 && !isRelevantMacro(nodes[currIndex])) {\n currIndex--;\n }\n }\n\n // Search for an occurrence of any of the macros `macroName` and its arguments.\n // Some macros are right-associative, so we should start searching from\n // the right\n currIndex = nodes.length - 1;\n while (currIndex >= 0) {\n gobbleUntilMacro();\n if (currIndex < 0) {\n // We didn't find an occurrence of the macro\n return;\n }\n\n // Store the currIndex, which is where the macro is. Start searching\n // for its arguments at the next index.\n const macroIndex = currIndex;\n const macro = nodes[macroIndex] as Ast.Macro;\n const macroName = macro.content;\n const macroInfo = macros[macroName];\n\n // Add `._renderInfo` if we have any\n updateRenderInfo(macro, macroInfo.renderInfo);\n\n // If the macro has no signature, it shouldn't consume any arguments. Just move along.\n // Node: It is important that this happens *after* `updateRenderInfo` is called, since\n // we still want to update the render info even if there are no args.\n if (macroInfo.signature == null) {\n currIndex--;\n continue;\n }\n\n // We don't want to search for macro arguments if we already\n // found them. If the macro has arguments, we assume that\n // they've already been attached\n if (macro.args != null) {\n currIndex = macroIndex - 1;\n continue;\n }\n\n // `currIndex` is the position of the macro. We want to start\n // looking for the arguments right after the macro\n currIndex++;\n const { args } = gobbleArguments(nodes, macroInfo.signature, currIndex);\n macro.args = args;\n // After we've gobbled the arguments, set\n // ourselves one space before the macro so we can continue.\n currIndex = macroIndex - 1;\n }\n}\n\n/**\n * Recursively search for and attach the arguments for a\n * particular macro to its AST node. `macros` should\n * contain a `signature` property which specifies the arguments\n * signature in xparse syntax.\n */\nexport function attachMacroArgs(tree: Ast.Ast, macros: MacroInfoRecord) {\n visit(\n tree,\n (nodes) => {\n attachMacroArgsInArray(nodes, macros);\n },\n { includeArrays: true, test: Array.isArray }\n );\n}\n", "import { Plugin } from \"unified\";\nimport * as Ast from \"@unified-latex/unified-latex-types\";\nimport { MacroInfoRecord } from \"@unified-latex/unified-latex-types\";\nimport { visit } from \"@unified-latex/unified-latex-util-visit\";\nimport { attachMacroArgsInArray } from \"./attach-arguments\";\n\ntype PluginOptions = { macros: MacroInfoRecord } | undefined;\n\n/**\n * Unified plugin to attach macro arguments to the macros specified via the `macros`\n * option.\n *\n * @param macros An object whose keys are macro names and values contains information about the macro and its argument signature.\n */\nexport const unifiedLatexAttachMacroArguments: Plugin<\n PluginOptions[],\n Ast.Root,\n Ast.Root\n> = function unifiedLatexAttachMacroArguments(options) {\n return (tree) => {\n const { macros = {} } = options || {};\n if (Object.keys(macros).length === 0) {\n console.warn(\n \"Attempting to attach macro arguments but no macros are specified.\"\n );\n }\n visit(\n tree,\n (nodes) => {\n attachMacroArgsInArray(nodes, macros);\n },\n { includeArrays: true, test: Array.isArray }\n );\n };\n};\n", "import * as Ast from \"@unified-latex/unified-latex-types\";\n\n/**\n * Returns the content of `args` for a macro or environment as an array. If an argument\n * was omitted (e.g., because it was an optional arg that wasn't included), then `null` is returned.\n */\nexport function getArgsContent(\n node: Ast.Macro | Ast.Environment\n): (Ast.Node[] | null)[] {\n if (!Array.isArray(node.args)) {\n return [];\n }\n\n return node.args.map((arg) => {\n if (arg.openMark === \"\" && arg.content.length === 0) {\n return null;\n }\n return arg.content;\n });\n}\n\n/**\n * Returns the content of `args` for a macro or environment as an object whose keys are the \"names\"\n * of each argument. These names of the arguments must be specified in the `_renderInfo` prop. If `_renderInfo`\n * does not contain a `namedArguments` array, then an empty object will be returned.\n *\n * @namedArgumentsFallback - If `_renderInfo.namedArguments` is not provided, `namedArgumentsFallback` is ued.\n */\nexport function getNamedArgsContent(\n node: Ast.Macro | Ast.Environment,\n namedArgumentsFallback: readonly (string | null)[] = []\n): Record<string, Ast.Node[] | null> {\n const names = node._renderInfo?.namedArguments || namedArgumentsFallback;\n\n if (\n !Array.isArray(node.args) ||\n !Array.isArray(names) ||\n names.length === 0\n ) {\n return {};\n }\n const ret: Record<string, Ast.Node[] | null> = {};\n\n node.args.forEach((arg, i) => {\n const name = names[i];\n if (name == null) {\n // If a null name was given, it shouldn't be listed as a named argument.\n return;\n }\n let val: Ast.Node[] | null = arg.content;\n if (arg.openMark === \"\" && arg.content.length === 0) {\n val = null;\n }\n ret[name] = val;\n });\n\n return ret;\n}\n"], | ||
| "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,wCAGO;AAEP,IAAAA,gCAAoB;;;ACHpB,sCAAsB;AACtB,mCAAoB;AAOb,SAAS,qBACZ,OACA,SACA,WAAW,GAIb;AACE,MAAI,OAAO,YAAY,YAAY,CAAC,QAAQ,MAAM;AAC9C,UAAM,IAAI;AAAA,MACN,kEAAkE,KAAK;AAAA,QACnE;AAAA,MACJ;AAAA,IACJ;AAAA,EACJ;AAEA,MAAI,WAAgC;AAEpC,MAAI,UAAU;AAKd,QAAM,mBAAoB,QACrB,sBACC,MAAM;AAAA,EAAC,IACP,MAAM;AACF,WAAO,UAAU,MAAM,QAAQ;AAC3B,UAAI,CAAC,sCAAM,WAAW,MAAM,QAAQ,GAAG;AACnC;AAAA,MACJ;AACA;AAAA,IACJ;AAAA,EACJ;AAEN,QAAM,WAAoB,QAAgB,aAAa;AACvD,QAAM,YAAqB,QAAgB,cAAc;AAMzD,QAAM,eACD,QAAQ,SAAS,eAAe,QAAQ,SAAS,eAClD,aAAa,OACb,cAAc;AAIlB,WAAS,qBAAqD;AAC1D,QAAI,cAA6B;AACjC,QAAI,UAAU;AACV,oBAAc,MAAM;AAAA,QAChB,CAAC,MAAM,MAAM,KAAK,WAAW,sCAAM,OAAO,MAAM,QAAQ;AAAA,MAC5D;AACA,UAAI,cAAc,SAAS;AACvB,sBAAc;AAAA,MAClB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AElD,MACI,CAAC,MAAM,QAAQ,KAAK,IAAI,KACxB,CAAC,MAAM,QAAQ,KAAK,KACpB,MAAM,WAAW,GACnB;AACE,WAAO,CAAC;AAAA,EACZ;AACA,QAAM,MAAyC,CAAC;AAEhD,OAAK,KAAK,QAAQ,CAACA,MAAK,MAAM;AAC1B,UAAM,OAAO,MAAM;AACnB,QAAI,QAAQ,MAAM;AAEd;AAAA,IACJ;AACA,QAAI,MAAyBA,KAAI;AACjC,QAAIA,KAAI,aAAa,MAAMA,KAAI,QAAQ,WAAW,GAAG;AACjD,YAAM;AAAA,IACV;AACA,QAAI,QAAQ;AAAA,EAChB,CAAC;AAED,SAAO;AACX;", | ||
| "names": ["import_unified_latex_builder", "parseArgspec", "import_unified_latex_util_match", "import_unified_latex_util_visit", "unifiedLatexAttachMacroArguments", "arg"] | ||
| } |
+71
-14
@@ -12,3 +12,7 @@ // libs/gobble-arguments.ts | ||
| if (typeof argSpec === "string" || !argSpec.type) { | ||
| throw new Error(`argSpec must be an already-parsed argument specification, not "${JSON.stringify(argSpec)}"`); | ||
| throw new Error( | ||
| `argSpec must be an already-parsed argument specification, not "${JSON.stringify( | ||
| argSpec | ||
| )}"` | ||
| ); | ||
| } | ||
@@ -28,7 +32,9 @@ let argument = null; | ||
| const closeMark = argSpec.closeBrace || ""; | ||
| const acceptGroup = argSpec.type === "mandatory" && openMark === "{" && closeMark === "}"; | ||
| const acceptGroup = (argSpec.type === "mandatory" || argSpec.type === "optional") && openMark === "{" && closeMark === "}"; | ||
| function findBracePositions() { | ||
| let openMarkPos = null; | ||
| if (openMark) { | ||
| openMarkPos = nodes.findIndex((node, i) => i >= currPos && match.string(node, openMark)); | ||
| openMarkPos = nodes.findIndex( | ||
| (node, i) => i >= currPos && match.string(node, openMark) | ||
| ); | ||
| if (openMarkPos < currPos) { | ||
@@ -40,3 +46,5 @@ openMarkPos = null; | ||
| if (openMarkPos != null) { | ||
| closeMarkPos = nodes.findIndex((node, i) => i >= openMarkPos + 1 && match.string(node, closeMark)); | ||
| closeMarkPos = nodes.findIndex( | ||
| (node, i) => i >= openMarkPos + 1 && match.string(node, closeMark) | ||
| ); | ||
| if (closeMarkPos < openMarkPos + 1) { | ||
@@ -68,2 +76,10 @@ closeMarkPos = null; | ||
| case "optional": | ||
| if (acceptGroup && match.group(currNode)) { | ||
| argument = arg(currNode.content, { | ||
| openMark, | ||
| closeMark | ||
| }); | ||
| currPos++; | ||
| break; | ||
| } | ||
| if (match.string(currNode, openMark)) { | ||
@@ -82,3 +98,7 @@ const [openMarkPos, closeMarkPos] = findBracePositions(); | ||
| case "optionalStar": | ||
| if (match.string(currNode, "*")) { | ||
| case "optionalToken": | ||
| if (match.string( | ||
| currNode, | ||
| argSpec.type === "optionalStar" ? "*" : argSpec.token | ||
| )) { | ||
| argument = arg([currNode], { openMark: "", closeMark: "" }); | ||
@@ -90,3 +110,5 @@ currPos++; | ||
| default: | ||
| console.warn(`Don't know how to find an argument of argspec type "${argSpec.type}"`); | ||
| console.warn( | ||
| `Don't know how to find an argument of argspec type "${argSpec.type}"` | ||
| ); | ||
| } | ||
@@ -106,3 +128,7 @@ const nodesRemoved = argument ? currPos - startPos : 0; | ||
| for (const spec of argSpec) { | ||
| const { argument, nodesRemoved: removed } = gobbleSingleArgument(nodes, spec, startPos); | ||
| const { argument, nodesRemoved: removed } = gobbleSingleArgument( | ||
| nodes, | ||
| spec, | ||
| startPos | ||
| ); | ||
| if (argument) { | ||
@@ -156,5 +182,9 @@ args.push(argument); | ||
| function attachMacroArgs(tree, macros) { | ||
| visit(tree, (nodes) => { | ||
| attachMacroArgsInArray(nodes, macros); | ||
| }, { includeArrays: true, test: Array.isArray }); | ||
| visit( | ||
| tree, | ||
| (nodes) => { | ||
| attachMacroArgsInArray(nodes, macros); | ||
| }, | ||
| { includeArrays: true, test: Array.isArray } | ||
| ); | ||
| } | ||
@@ -168,7 +198,13 @@ | ||
| if (Object.keys(macros).length === 0) { | ||
| console.warn("Attempting to attach macro arguments but no macros are specified."); | ||
| console.warn( | ||
| "Attempting to attach macro arguments but no macros are specified." | ||
| ); | ||
| } | ||
| visit2(tree, (nodes) => { | ||
| attachMacroArgsInArray(nodes, macros); | ||
| }, { includeArrays: true, test: Array.isArray }); | ||
| visit2( | ||
| tree, | ||
| (nodes) => { | ||
| attachMacroArgsInArray(nodes, macros); | ||
| }, | ||
| { includeArrays: true, test: Array.isArray } | ||
| ); | ||
| }; | ||
@@ -189,2 +225,22 @@ }; | ||
| } | ||
| function getNamedArgsContent(node, namedArgumentsFallback = []) { | ||
| var _a; | ||
| const names = ((_a = node._renderInfo) == null ? void 0 : _a.namedArguments) || namedArgumentsFallback; | ||
| if (!Array.isArray(node.args) || !Array.isArray(names) || names.length === 0) { | ||
| return {}; | ||
| } | ||
| const ret = {}; | ||
| node.args.forEach((arg3, i) => { | ||
| const name = names[i]; | ||
| if (name == null) { | ||
| return; | ||
| } | ||
| let val = arg3.content; | ||
| if (arg3.openMark === "" && arg3.content.length === 0) { | ||
| val = null; | ||
| } | ||
| ret[name] = val; | ||
| }); | ||
| return ret; | ||
| } | ||
| export { | ||
@@ -194,2 +250,3 @@ attachMacroArgs, | ||
| getArgsContent, | ||
| getNamedArgsContent, | ||
| gobbleArguments, | ||
@@ -196,0 +253,0 @@ unifiedLatexAttachMacroArguments |
+3
-3
| { | ||
| "version": 3, | ||
| "sources": ["../libs/gobble-arguments.ts", "../libs/gobble-single-argument.ts", "../libs/attach-arguments.ts", "../libs/unified-latex-attach-macro-arguments.ts", "../libs/get-args-content.ts"], | ||
| "sourcesContent": ["import {\n ArgSpecAst as ArgSpec,\n parse as parseArgspec,\n} from \"@unified-latex/unified-latex-util-argspec\";\nimport * as Ast from \"@unified-latex/unified-latex-types\";\nimport { arg } from \"@unified-latex/unified-latex-builder\";\nimport { gobbleSingleArgument } from \"./gobble-single-argument\";\n\n/**\n * Gobbles an argument of whose type is specified\n * by `argSpec` starting at the position `startPos`. If an argument couldn't be found,\n * `argument` will be `null`.\n */\nexport function gobbleArguments(\n nodes: Ast.Node[],\n argSpec: string | ArgSpec.Node[],\n startPos = 0\n): {\n args: Ast.Argument[];\n nodesRemoved: number;\n} {\n if (typeof argSpec === \"string\") {\n argSpec = parseArgspec(argSpec);\n }\n\n const args: Ast.Argument[] = [];\n let nodesRemoved = 0;\n for (const spec of argSpec) {\n const { argument, nodesRemoved: removed } = gobbleSingleArgument(\n nodes,\n spec,\n startPos\n );\n if (argument) {\n args.push(argument);\n nodesRemoved += removed;\n } else {\n args.push(arg([], { openMark: \"\", closeMark: \"\" }));\n }\n }\n\n return { args, nodesRemoved };\n}\n", "import { ArgSpecAst as ArgSpec } from \"@unified-latex/unified-latex-util-argspec\";\nimport * as Ast from \"@unified-latex/unified-latex-types\";\nimport { match } from \"@unified-latex/unified-latex-util-match\";\nimport { arg } from \"@unified-latex/unified-latex-builder\";\n\n/**\n * Gobbles an argument of whose type is specified\n * by `argSpec` starting at the position `startPos`. If an argument couldn't be found,\n * `argument` will be `null`.\n */\nexport function gobbleSingleArgument(\n nodes: Ast.Node[],\n argSpec: ArgSpec.Node,\n startPos = 0\n): {\n argument: Ast.Argument | null;\n nodesRemoved: number;\n} {\n if (typeof argSpec === \"string\" || !argSpec.type) {\n throw new Error(\n `argSpec must be an already-parsed argument specification, not \"${JSON.stringify(\n argSpec\n )}\"`\n );\n }\n\n let argument: Ast.Argument | null = null;\n\n let currPos = startPos;\n\n // Gobble whitespace from `currPos` onward, updating `currPos`.\n // If `argSpec` specifies leading whitespace is not allowed,\n // this function does nothing.\n const gobbleWhitespace = (argSpec as ArgSpec.LeadingWhitespace)\n .noLeadingWhitespace\n ? () => {}\n : () => {\n while (currPos < nodes.length) {\n if (!match.whitespace(nodes[currPos])) {\n break;\n }\n currPos++;\n }\n };\n\n const openMark: string = (argSpec as any).openBrace || \"\";\n const closeMark: string = (argSpec as any).closeBrace || \"\";\n\n // Only mandatory arguments can be wrapped in {...}.\n // Since we already parse such things as groups, we need to\n // check the open and closing symbols to see if we allow for\n // groups to be accepted as arguments\n const acceptGroup =\n argSpec.type === \"mandatory\" && openMark === \"{\" && closeMark === \"}\";\n\n // Find the position of the open brace and the closing brace.\n // The position(s) are null if the brace isn't found.\n function findBracePositions(): [number | null, number | null] {\n let openMarkPos: number | null = null;\n if (openMark) {\n openMarkPos = nodes.findIndex(\n (node, i) => i >= currPos && match.string(node, openMark)\n );\n if (openMarkPos < currPos) {\n openMarkPos = null;\n }\n }\n let closeMarkPos: number | null = null;\n if (openMarkPos != null) {\n closeMarkPos = nodes.findIndex(\n (node, i) =>\n i >= (openMarkPos as number) + 1 &&\n match.string(node, closeMark)\n );\n if (closeMarkPos < openMarkPos + 1) {\n closeMarkPos = null;\n }\n }\n return [openMarkPos, closeMarkPos];\n }\n\n // Do the actual matching\n gobbleWhitespace();\n const currNode = nodes[currPos];\n if (\n currNode == null ||\n match.comment(currNode) ||\n match.parbreak(currNode)\n ) {\n return { argument, nodesRemoved: 0 };\n }\n\n switch (argSpec.type) {\n case \"mandatory\":\n if (acceptGroup) {\n let content: Ast.Node[] = [currNode];\n if (match.group(currNode)) {\n // Unwrap a group if there is one.\n content = currNode.content;\n }\n argument = arg(content, {\n openMark,\n closeMark,\n });\n currPos++;\n break;\n }\n // The fallthrough here is on purpose! Matching a mandatory\n // argument and an optional argument is the same for our purposes.\n // We're not going to fail to parse because of a missing argument.\n case \"optional\":\n // We have already gobbled whitespace, so at this point, `currNode`\n // is either an openMark or we don't have an optional argument.\n if (match.string(currNode, openMark)) {\n // If we're here, we have custom braces to match\n const [openMarkPos, closeMarkPos] = findBracePositions();\n if (openMarkPos != null && closeMarkPos != null) {\n argument = arg(nodes.slice(openMarkPos + 1, closeMarkPos), {\n openMark,\n closeMark,\n });\n currPos = closeMarkPos + 1;\n break;\n }\n }\n break;\n case \"optionalStar\":\n if (match.string(currNode, \"*\")) {\n argument = arg([currNode], { openMark: \"\", closeMark: \"\" });\n currPos++;\n break;\n }\n break;\n default:\n console.warn(\n `Don't know how to find an argument of argspec type \"${argSpec.type}\"`\n );\n }\n\n // `currPos` is has already stepped past any whitespace. However,\n // if we did not consume an argument, we don't want to consume the whitespace.\n const nodesRemoved = argument ? currPos - startPos : 0;\n nodes.splice(startPos, nodesRemoved);\n return { argument, nodesRemoved };\n}\n", "import * as Ast from \"@unified-latex/unified-latex-types\";\nimport { match } from \"@unified-latex/unified-latex-util-match\";\nimport { MacroInfoRecord } from \"@unified-latex/unified-latex-types\";\nimport { updateRenderInfo } from \"@unified-latex/unified-latex-util-render-info\";\nimport { gobbleArguments } from \"./gobble-arguments\";\nimport { visit } from \"@unified-latex/unified-latex-util-visit\";\n\n/**\n * Search (in a right-associative way) through the array for instances of\n * `macros` and attach arguments to the macro. Argument signatures are\n * specified by `macros[].signature`.\n *\n * Info stored in `macros[].renderInfo` will be attached to the node\n * with attribute `_renderInfo`.\n */\nexport function attachMacroArgsInArray(\n nodes: Ast.Node[],\n macros: MacroInfoRecord\n): void {\n // Some preliminaries that are only used if `ast` is an array.\n let currIndex: number;\n\n /**\n * Determine whether `node` matches one of the macros in `macros`.\n * Care is taken when matching because not all macros have\n * `\\` as their escape token.\n */\n const isRelevantMacro = match.createMacroMatcher(macros);\n\n function gobbleUntilMacro() {\n // Step backwards until we find the required macro\n while (currIndex >= 0 && !isRelevantMacro(nodes[currIndex])) {\n currIndex--;\n }\n }\n\n // Search for an occurrence of any of the macros `macroName` and its arguments.\n // Some macros are right-associative, so we should start searching from\n // the right\n currIndex = nodes.length - 1;\n while (currIndex >= 0) {\n gobbleUntilMacro();\n if (currIndex < 0) {\n // We didn't find an occurrence of the macro\n return;\n }\n\n // Store the currIndex, which is where the macro is. Start searching\n // for its arguments at the next index.\n const macroIndex = currIndex;\n const macro = nodes[macroIndex] as Ast.Macro;\n const macroName = macro.content;\n const macroInfo = macros[macroName];\n\n // Add `._renderInfo` if we have any\n updateRenderInfo(macro, macroInfo.renderInfo);\n\n // If the macro has no signature, it shouldn't consume any arguments. Just move along.\n // Node: It is important that this happens *after* `updateRenderInfo` is called, since\n // we still want to update the render info even if there are no args.\n if (macroInfo.signature == null) {\n currIndex--;\n continue;\n }\n\n // We don't want to search for macro arguments if we already\n // found them. If the macro has arguments, we assume that\n // they've already been attached\n if (macro.args != null) {\n currIndex = macroIndex - 1;\n continue;\n }\n\n // `currIndex` is the position of the macro. We want to start\n // looking for the arguments right after the macro\n currIndex++;\n const { args } = gobbleArguments(nodes, macroInfo.signature, currIndex);\n macro.args = args;\n // After we've gobbled the arguments, set\n // ourselves one space before the macro so we can continue.\n currIndex = macroIndex - 1;\n }\n}\n\n/**\n * Recursively search for and attach the arguments for a\n * particular macro to its AST node. `macros` should\n * contain a `signature` property which specifies the arguments\n * signature in xparse syntax.\n */\nexport function attachMacroArgs(tree: Ast.Ast, macros: MacroInfoRecord) {\n visit(\n tree,\n (nodes) => {\n attachMacroArgsInArray(nodes, macros);\n },\n { includeArrays: true, test: Array.isArray }\n );\n}\n", "import { Plugin } from \"unified\";\nimport * as Ast from \"@unified-latex/unified-latex-types\";\nimport { MacroInfoRecord } from \"@unified-latex/unified-latex-types\";\nimport { visit } from \"@unified-latex/unified-latex-util-visit\";\nimport { attachMacroArgsInArray } from \"./attach-arguments\";\n\ntype PluginOptions = { macros: MacroInfoRecord } | undefined;\n\n/**\n * Unified plugin to attach macro arguments to the macros specified via the `macros`\n * option.\n *\n * @param macros An object whose keys are macro names and values contains information about the macro and its argument signature.\n */\nexport const unifiedLatexAttachMacroArguments: Plugin<\n PluginOptions[],\n Ast.Root,\n Ast.Root\n> = function unifiedLatexAttachMacroArguments(options) {\n return (tree) => {\n const { macros = {} } = options || {};\n if (Object.keys(macros).length === 0) {\n console.warn(\n \"Attempting to attach macro arguments but no macros are specified.\"\n );\n }\n visit(\n tree,\n (nodes) => {\n attachMacroArgsInArray(nodes, macros);\n },\n { includeArrays: true, test: Array.isArray }\n );\n };\n};\n", "import * as Ast from \"@unified-latex/unified-latex-types\";\n\n/**\n * Returns the content of `args` for a macro or environment as an array. If an argument\n * was omitted (e.g., because it was an optional arg that wasn't included), then `null` is returned.\n */\nexport function getArgsContent(\n node: Ast.Macro | Ast.Environment\n): (Ast.Node[] | null)[] {\n if (!Array.isArray(node.args)) {\n return [];\n }\n\n return node.args.map((arg) => {\n if (arg.openMark === \"\" && arg.content.length === 0) {\n return null;\n }\n return arg.content;\n });\n}\n"], | ||
| "mappings": ";AAAA;AAAA;AAAA;AAKA;;;ACHA;AACA;AAOO,8BACH,OACA,SACA,WAAW,GAIb;AACE,MAAI,OAAO,YAAY,YAAY,CAAC,QAAQ,MAAM;AAC9C,UAAM,IAAI,MACN,kEAAkE,KAAK,UACnE,OACJ,IACJ;AAAA,EACJ;AAEA,MAAI,WAAgC;AAEpC,MAAI,UAAU;AAKd,QAAM,mBAAoB,QACrB,sBACC,MAAM;AAAA,EAAC,IACP,MAAM;AACF,WAAO,UAAU,MAAM,QAAQ;AAC3B,UAAI,CAAC,MAAM,WAAW,MAAM,QAAQ,GAAG;AACnC;AAAA,MACJ;AACA;AAAA,IACJ;AAAA,EACJ;AAEN,QAAM,WAAoB,QAAgB,aAAa;AACvD,QAAM,YAAqB,QAAgB,cAAc;AAMzD,QAAM,cACF,QAAQ,SAAS,eAAe,aAAa,OAAO,cAAc;AAItE,gCAA8D;AAC1D,QAAI,cAA6B;AACjC,QAAI,UAAU;AACV,oBAAc,MAAM,UAChB,CAAC,MAAM,MAAM,KAAK,WAAW,MAAM,OAAO,MAAM,QAAQ,CAC5D;AACA,UAAI,cAAc,SAAS;AACvB,sBAAc;AAAA,MAClB;AAAA,IACJ;AACA,QAAI,eAA8B;AAClC,QAAI,eAAe,MAAM;AACrB,qBAAe,MAAM,UACjB,CAAC,MAAM,MACH,KAAM,cAAyB,KAC/B,MAAM,OAAO,MAAM,SAAS,CACpC;AACA,UAAI,eAAe,cAAc,GAAG;AAChC,uBAAe;AAAA,MACnB;AAAA,IACJ;AACA,WAAO,CAAC,aAAa,YAAY;AAAA,EACrC;AAGA,mBAAiB;AACjB,QAAM,WA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AAuB,OAAO,MAAM;AAAA,IACxC,GACA,EAAE,eAAe,MAAM,MAAM,MAAM,QAAQ,CAC/C;AAAA,EACJ;AACJ;;;AC5BO,wBACH,MACqB;AACrB,MAAI,CAAC,MAAM,QAAQ,KAAK,IAAI,GAAG;AAC3B,WAAO,CAAC;AAAA,EACZ;AAEA,SAAO,KAAK,KAAK,IAAI,CAAC,SAAQ;AAC1B,QAAI,KAAI,aAAa,MAAM,KAAI,QAAQ,WAAW,GAAG;AACjD,aAAO;AAAA,IACX;AACA,WAAO,KAAI;AAAA,EACf,CAAC;AACL;", | ||
| "names": [] | ||
| "sourcesContent": ["import {\n ArgSpecAst as ArgSpec,\n parse as parseArgspec,\n} from \"@unified-latex/unified-latex-util-argspec\";\nimport * as Ast from \"@unified-latex/unified-latex-types\";\nimport { arg } from \"@unified-latex/unified-latex-builder\";\nimport { gobbleSingleArgument } from \"./gobble-single-argument\";\n\n/**\n * Gobbles an argument of whose type is specified\n * by `argSpec` starting at the position `startPos`. If an argument couldn't be found,\n * `argument` will be `null`.\n */\nexport function gobbleArguments(\n nodes: Ast.Node[],\n argSpec: string | ArgSpec.Node[],\n startPos = 0\n): {\n args: Ast.Argument[];\n nodesRemoved: number;\n} {\n if (typeof argSpec === \"string\") {\n argSpec = parseArgspec(argSpec);\n }\n\n const args: Ast.Argument[] = [];\n let nodesRemoved = 0;\n for (const spec of argSpec) {\n const { argument, nodesRemoved: removed } = gobbleSingleArgument(\n nodes,\n spec,\n startPos\n );\n if (argument) {\n args.push(argument);\n nodesRemoved += removed;\n } else {\n args.push(arg([], { openMark: \"\", closeMark: \"\" }));\n }\n }\n\n return { args, nodesRemoved };\n}\n", "import { ArgSpecAst as ArgSpec } from \"@unified-latex/unified-latex-util-argspec\";\nimport * as Ast from \"@unified-latex/unified-latex-types\";\nimport { match } from \"@unified-latex/unified-latex-util-match\";\nimport { arg } from \"@unified-latex/unified-latex-builder\";\n\n/**\n * Gobbles an argument of whose type is specified\n * by `argSpec` starting at the position `startPos`. If an argument couldn't be found,\n * `argument` will be `null`.\n */\nexport function gobbleSingleArgument(\n nodes: Ast.Node[],\n argSpec: ArgSpec.Node,\n startPos = 0\n): {\n argument: Ast.Argument | null;\n nodesRemoved: number;\n} {\n if (typeof argSpec === \"string\" || !argSpec.type) {\n throw new Error(\n `argSpec must be an already-parsed argument specification, not \"${JSON.stringify(\n argSpec\n )}\"`\n );\n }\n\n let argument: Ast.Argument | null = null;\n\n let currPos = startPos;\n\n // Gobble whitespace from `currPos` onward, updating `currPos`.\n // If `argSpec` specifies leading whitespace is not allowed,\n // this function does nothing.\n const gobbleWhitespace = (argSpec as ArgSpec.LeadingWhitespace)\n .noLeadingWhitespace\n ? () => {}\n : () => {\n while (currPos < nodes.length) {\n if (!match.whitespace(nodes[currPos])) {\n break;\n }\n currPos++;\n }\n };\n\n const openMark: string = (argSpec as any).openBrace || \"\";\n const closeMark: string = (argSpec as any).closeBrace || \"\";\n\n // Only mandatory arguments can be wrapped in {...}.\n // Since we already parse such things as groups, we need to\n // check the open and closing symbols to see if we allow for\n // groups to be accepted as arguments\n const acceptGroup =\n (argSpec.type === \"mandatory\" || argSpec.type === \"optional\") &&\n openMark === \"{\" &&\n closeMark === \"}\";\n\n // Find the position of the open brace and the closing brace.\n // The position(s) are null if the brace isn't found.\n function findBracePositions(): [number | null, number | null] {\n let openMarkPos: number | null = null;\n if (openMark) {\n openMarkPos = nodes.findIndex(\n (node, i) => i >= currPos && match.string(node, openMark)\n );\n if (openMarkPos < currPos) {\n openMarkPos = null;\n }\n }\n let closeMarkPos: number | null = null;\n if (openMarkPos != null) {\n closeMarkPos = nodes.findIndex(\n (node, i) =>\n i >= (openMarkPos as number) + 1 &&\n match.string(node, closeMark)\n );\n if (closeMarkPos < openMarkPos + 1) {\n closeMarkPos = null;\n }\n }\n return [openMarkPos, closeMarkPos];\n }\n\n // Do the actual matching\n gobbleWhitespace();\n const currNode = nodes[currPos];\n if (\n currNode == null ||\n match.comment(currNode) ||\n match.parbreak(currNode)\n ) {\n return { argument, nodesRemoved: 0 };\n }\n\n switch (argSpec.type) {\n case \"mandatory\":\n if (acceptGroup) {\n // We have already gobbled whitespace, so at this point, `currNode`\n // is either an openMark or we don't have an optional argument.\n let content: Ast.Node[] = [currNode];\n if (match.group(currNode)) {\n // Unwrap a group if there is one.\n content = currNode.content;\n }\n argument = arg(content, {\n openMark,\n closeMark,\n });\n currPos++;\n break;\n }\n // NOTE: Fallthrough is on purpose.\n // Matching a mandatory argument and an optional argument is the same for our purposes\n // because we're not going to fail to parse because of a missing argument.\n case \"optional\":\n // It is possible that an optional argument accepts a group if its open/close braces are `{}`\n if (acceptGroup && match.group(currNode)) {\n argument = arg(currNode.content, {\n openMark,\n closeMark,\n });\n currPos++;\n break;\n }\n if (match.string(currNode, openMark)) {\n // If we're here, we have custom braces to match\n const [openMarkPos, closeMarkPos] = findBracePositions();\n if (openMarkPos != null && closeMarkPos != null) {\n argument = arg(nodes.slice(openMarkPos + 1, closeMarkPos), {\n openMark,\n closeMark,\n });\n currPos = closeMarkPos + 1;\n break;\n }\n }\n break;\n case \"optionalStar\":\n case \"optionalToken\":\n if (\n match.string(\n currNode,\n argSpec.type === \"optionalStar\" ? \"*\" : argSpec.token\n )\n ) {\n argument = arg([currNode], { openMark: \"\", closeMark: \"\" });\n currPos++;\n break;\n }\n break;\n default:\n console.warn(\n `Don't know how to find an argument of argspec type \"${argSpec.type}\"`\n );\n }\n\n // `currPos` is has already stepped past any whitespace. However,\n // if we did not consume an argument, we don't want to consume the whitespace.\n const nodesRemoved = argument ? currPos - startPos : 0;\n nodes.splice(startPos, nodesRemoved);\n return { argument, nodesRemoved };\n}\n", "import * as Ast from \"@unified-latex/unified-latex-types\";\nimport { match } from \"@unified-latex/unified-latex-util-match\";\nimport { MacroInfoRecord } from \"@unified-latex/unified-latex-types\";\nimport { updateRenderInfo } from \"@unified-latex/unified-latex-util-render-info\";\nimport { gobbleArguments } from \"./gobble-arguments\";\nimport { visit } from \"@unified-latex/unified-latex-util-visit\";\n\n/**\n * Search (in a right-associative way) through the array for instances of\n * `macros` and attach arguments to the macro. Argument signatures are\n * specified by `macros[].signature`.\n *\n * Info stored in `macros[].renderInfo` will be attached to the node\n * with attribute `_renderInfo`.\n */\nexport function attachMacroArgsInArray(\n nodes: Ast.Node[],\n macros: MacroInfoRecord\n): void {\n // Some preliminaries that are only used if `ast` is an array.\n let currIndex: number;\n\n /**\n * Determine whether `node` matches one of the macros in `macros`.\n * Care is taken when matching because not all macros have\n * `\\` as their escape token.\n */\n const isRelevantMacro = match.createMacroMatcher(macros);\n\n function gobbleUntilMacro() {\n // Step backwards until we find the required macro\n while (currIndex >= 0 && !isRelevantMacro(nodes[currIndex])) {\n currIndex--;\n }\n }\n\n // Search for an occurrence of any of the macros `macroName` and its arguments.\n // Some macros are right-associative, so we should start searching from\n // the right\n currIndex = nodes.length - 1;\n while (currIndex >= 0) {\n gobbleUntilMacro();\n if (currIndex < 0) {\n // We didn't find an occurrence of the macro\n return;\n }\n\n // Store the currIndex, which is where the macro is. Start searching\n // for its arguments at the next index.\n const macroIndex = currIndex;\n const macro = nodes[macroIndex] as Ast.Macro;\n const macroName = macro.content;\n const macroInfo = macros[macroName];\n\n // Add `._renderInfo` if we have any\n updateRenderInfo(macro, macroInfo.renderInfo);\n\n // If the macro has no signature, it shouldn't consume any arguments. Just move along.\n // Node: It is important that this happens *after* `updateRenderInfo` is called, since\n // we still want to update the render info even if there are no args.\n if (macroInfo.signature == null) {\n currIndex--;\n continue;\n }\n\n // We don't want to search for macro arguments if we already\n // found them. If the macro has arguments, we assume that\n // they've already been attached\n if (macro.args != null) {\n currIndex = macroIndex - 1;\n continue;\n }\n\n // `currIndex` is the position of the macro. We want to start\n // looking for the arguments right after the macro\n currIndex++;\n const { args } = gobbleArguments(nodes, macroInfo.signature, currIndex);\n macro.args = args;\n // After we've gobbled the arguments, set\n // ourselves one space before the macro so we can continue.\n currIndex = macroIndex - 1;\n }\n}\n\n/**\n * Recursively search for and attach the arguments for a\n * particular macro to its AST node. `macros` should\n * contain a `signature` property which specifies the arguments\n * signature in xparse syntax.\n */\nexport function attachMacroArgs(tree: Ast.Ast, macros: MacroInfoRecord) {\n visit(\n tree,\n (nodes) => {\n attachMacroArgsInArray(nodes, macros);\n },\n { includeArrays: true, test: Array.isArray }\n );\n}\n", "import { Plugin } from \"unified\";\nimport * as Ast from \"@unified-latex/unified-latex-types\";\nimport { MacroInfoRecord } from \"@unified-latex/unified-latex-types\";\nimport { visit } from \"@unified-latex/unified-latex-util-visit\";\nimport { attachMacroArgsInArray } from \"./attach-arguments\";\n\ntype PluginOptions = { macros: MacroInfoRecord } | undefined;\n\n/**\n * Unified plugin to attach macro arguments to the macros specified via the `macros`\n * option.\n *\n * @param macros An object whose keys are macro names and values contains information about the macro and its argument signature.\n */\nexport const unifiedLatexAttachMacroArguments: Plugin<\n PluginOptions[],\n Ast.Root,\n Ast.Root\n> = function unifiedLatexAttachMacroArguments(options) {\n return (tree) => {\n const { macros = {} } = options || {};\n if (Object.keys(macros).length === 0) {\n console.warn(\n \"Attempting to attach macro arguments but no macros are specified.\"\n );\n }\n visit(\n tree,\n (nodes) => {\n attachMacroArgsInArray(nodes, macros);\n },\n { includeArrays: true, test: Array.isArray }\n );\n };\n};\n", "import * as Ast from \"@unified-latex/unified-latex-types\";\n\n/**\n * Returns the content of `args` for a macro or environment as an array. If an argument\n * was omitted (e.g., because it was an optional arg that wasn't included), then `null` is returned.\n */\nexport function getArgsContent(\n node: Ast.Macro | Ast.Environment\n): (Ast.Node[] | null)[] {\n if (!Array.isArray(node.args)) {\n return [];\n }\n\n return node.args.map((arg) => {\n if (arg.openMark === \"\" && arg.content.length === 0) {\n return null;\n }\n return arg.content;\n });\n}\n\n/**\n * Returns the content of `args` for a macro or environment as an object whose keys are the \"names\"\n * of each argument. These names of the arguments must be specified in the `_renderInfo` prop. If `_renderInfo`\n * does not contain a `namedArguments` array, then an empty object will be returned.\n *\n * @namedArgumentsFallback - If `_renderInfo.namedArguments` is not provided, `namedArgumentsFallback` is ued.\n */\nexport function getNamedArgsContent(\n node: Ast.Macro | Ast.Environment,\n namedArgumentsFallback: readonly (string | null)[] = []\n): Record<string, Ast.Node[] | null> {\n const names = node._renderInfo?.namedArguments || namedArgumentsFallback;\n\n if (\n !Array.isArray(node.args) ||\n !Array.isArray(names) ||\n names.length === 0\n ) {\n return {};\n }\n const ret: Record<string, Ast.Node[] | null> = {};\n\n node.args.forEach((arg, i) => {\n const name = names[i];\n if (name == null) {\n // If a null name was given, it shouldn't be listed as a named argument.\n return;\n }\n let val: Ast.Node[] | null = arg.content;\n if (arg.openMark === \"\" && arg.content.length === 0) {\n val = null;\n }\n ret[name] = val;\n });\n\n return ret;\n}\n"], | ||
| "mappings": ";AAAA;AAAA,EAEI,SAAS;AAAA,OACN;AAEP,SAAS,OAAAA,YAAW;;;ACHpB,SAAS,aAAa;AACtB,SAAS,WAAW;AAOb,SAAS,qBACZ,OACA,SACA,WAAW,GAIb;AACE,MAAI,OAAO,YAAY,YAAY,CAAC,QAAQ,MAAM;AAC9C,UAAM,IAAI;AAAA,MACN,kEAAkE,KAAK;AAAA,QACnE;AAAA,MACJ;AAAA,IACJ;AAAA,EACJ;AAEA,MAAI,WAAgC;AAEpC,MAAI,UAAU;AAKd,QAAM,mBAAoB,QACrB,sBACC,MAAM;AAAA,EAAC,IACP,MAAM;AACF,WAAO,UAAU,MAAM,QAAQ;AAC3B,UAAI,CAAC,MAAM,WAAW,MAAM,QAAQ,GAAG;AACnC;AAAA,MACJ;AACA;AAAA,IACJ;AAAA,EACJ;AAEN,QAAM,WAAoB,QAAgB,aAAa;AACvD,QAAM,YAAqB,QAAgB,cAAc;AAMzD,QAAM,eACD,QAAQ,SAAS,eAAe,QAAQ,SAAS,eAClD,aAAa,OACb,cAAc;AAIlB,WAAS,qBAAqD;AAC1D,QAAI,cAA6B;AACjC,QAAI,UAAU;AACV,oBAAc,MAAM;AAAA,QAChB,CAAC,MAAM,MAAM,KAAK,WAA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Z,MACA,yBAAqD,CAAC,GACrB;AA/BrC;AAgCI,QAAM,UAAQ,UAAK,gBAAL,mBAAkB,mBAAkB;AAElD,MACI,CAAC,MAAM,QAAQ,KAAK,IAAI,KACxB,CAAC,MAAM,QAAQ,KAAK,KACpB,MAAM,WAAW,GACnB;AACE,WAAO,CAAC;AAAA,EACZ;AACA,QAAM,MAAyC,CAAC;AAEhD,OAAK,KAAK,QAAQ,CAACA,MAAK,MAAM;AAC1B,UAAM,OAAO,MAAM;AACnB,QAAI,QAAQ,MAAM;AAEd;AAAA,IACJ;AACA,QAAI,MAAyBA,KAAI;AACjC,QAAIA,KAAI,aAAa,MAAMA,KAAI,QAAQ,WAAW,GAAG;AACjD,YAAM;AAAA,IACV;AACA,QAAI,QAAQ;AAAA,EAChB,CAAC;AAED,SAAO;AACX;", | ||
| "names": ["arg", "arg", "match", "match", "visit", "unifiedLatexAttachMacroArguments", "visit", "arg"] | ||
| } |
@@ -7,2 +7,10 @@ import * as Ast from "@unified-latex/unified-latex-types"; | ||
| export declare function getArgsContent(node: Ast.Macro | Ast.Environment): (Ast.Node[] | null)[]; | ||
| /** | ||
| * Returns the content of `args` for a macro or environment as an object whose keys are the "names" | ||
| * of each argument. These names of the arguments must be specified in the `_renderInfo` prop. If `_renderInfo` | ||
| * does not contain a `namedArguments` array, then an empty object will be returned. | ||
| * | ||
| * @namedArgumentsFallback - If `_renderInfo.namedArguments` is not provided, `namedArgumentsFallback` is ued. | ||
| */ | ||
| export declare function getNamedArgsContent(node: Ast.Macro | Ast.Environment, namedArgumentsFallback?: readonly (string | null)[]): Record<string, Ast.Node[] | null>; | ||
| //# sourceMappingURL=get-args-content.d.ts.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"get-args-content.d.ts","sourceRoot":"","sources":["../../libs/get-args-content.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,oCAAoC,CAAC;AAE1D;;;GAGG;AACH,wBAAgB,cAAc,CAC1B,IAAI,EAAE,GAAG,CAAC,KAAK,GAAG,GAAG,CAAC,WAAW,GAClC,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,EAAE,CAWvB"} | ||
| {"version":3,"file":"get-args-content.d.ts","sourceRoot":"","sources":["../../libs/get-args-content.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,oCAAoC,CAAC;AAE1D;;;GAGG;AACH,wBAAgB,cAAc,CAC1B,IAAI,EAAE,GAAG,CAAC,KAAK,GAAG,GAAG,CAAC,WAAW,GAClC,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,EAAE,CAWvB;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAC/B,IAAI,EAAE,GAAG,CAAC,KAAK,GAAG,GAAG,CAAC,WAAW,EACjC,sBAAsB,GAAE,SAAS,CAAC,MAAM,GAAG,IAAI,CAAC,EAAO,GACxD,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CA0BnC"} |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"gobble-single-argument.d.ts","sourceRoot":"","sources":["../../libs/gobble-single-argument.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,IAAI,OAAO,EAAE,MAAM,2CAA2C,CAAC;AAClF,OAAO,KAAK,GAAG,MAAM,oCAAoC,CAAC;AAI1D;;;;GAIG;AACH,wBAAgB,oBAAoB,CAChC,KAAK,EAAE,GAAG,CAAC,IAAI,EAAE,EACjB,OAAO,EAAE,OAAO,CAAC,IAAI,EACrB,QAAQ,SAAI,GACb;IACC,QAAQ,EAAE,GAAG,CAAC,QAAQ,GAAG,IAAI,CAAC;IAC9B,YAAY,EAAE,MAAM,CAAC;CACxB,CA+HA"} | ||
| {"version":3,"file":"gobble-single-argument.d.ts","sourceRoot":"","sources":["../../libs/gobble-single-argument.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,IAAI,OAAO,EAAE,MAAM,2CAA2C,CAAC;AAClF,OAAO,KAAK,GAAG,MAAM,oCAAoC,CAAC;AAI1D;;;;GAIG;AACH,wBAAgB,oBAAoB,CAChC,KAAK,EAAE,GAAG,CAAC,IAAI,EAAE,EACjB,OAAO,EAAE,OAAO,CAAC,IAAI,EACrB,QAAQ,SAAI,GACb;IACC,QAAQ,EAAE,GAAG,CAAC,QAAQ,GAAG,IAAI,CAAC;IAC9B,YAAY,EAAE,MAAM,CAAC;CACxB,CAgJA"} |
+7
-7
| { | ||
| "name": "@unified-latex/unified-latex-util-arguments", | ||
| "version": "1.0.12", | ||
| "version": "1.1.0", | ||
| "description": "Tools for manipulating unified-latex ASTs", | ||
@@ -8,8 +8,8 @@ "main": "index.js", | ||
| "dependencies": { | ||
| "@unified-latex/unified-latex-builder": "^1.0.12", | ||
| "@unified-latex/unified-latex-types": "^1.0.12", | ||
| "@unified-latex/unified-latex-util-argspec": "^1.0.12", | ||
| "@unified-latex/unified-latex-util-match": "^1.0.12", | ||
| "@unified-latex/unified-latex-util-render-info": "^1.0.12", | ||
| "@unified-latex/unified-latex-util-visit": "^1.0.12", | ||
| "@unified-latex/unified-latex-builder": "^1.1.0", | ||
| "@unified-latex/unified-latex-types": "^1.1.0", | ||
| "@unified-latex/unified-latex-util-argspec": "^1.1.0", | ||
| "@unified-latex/unified-latex-util-match": "^1.1.0", | ||
| "@unified-latex/unified-latex-util-render-info": "^1.1.0", | ||
| "@unified-latex/unified-latex-util-visit": "^1.1.0", | ||
| "unified": "^10.1.2" | ||
@@ -16,0 +16,0 @@ }, |
+20
-0
@@ -75,1 +75,21 @@ <!-- DO NOT MODIFY --> | ||
| | node | `Ast.Macro \| Ast.Environment` | | ||
| ## `getNamedArgsContent(node, namedArgumentsFallback)` | ||
| Returns the content of `args` for a macro or environment as an object whose keys are the "names" | ||
| of each argument. These names of the arguments must be specified in the `_renderInfo` prop. If `_renderInfo` | ||
| does not contain a `namedArguments` array, then an empty object will be returned. | ||
| ```typescript | ||
| function getNamedArgsContent( | ||
| node: Ast.Macro | Ast.Environment, | ||
| namedArgumentsFallback: readonly string[] | ||
| ): Record<string, Ast.Node[]>; | ||
| ``` | ||
| **Parameters** | ||
| | Param | Type | | ||
| | :--------------------- | :----------------------------- | | ||
| | node | `Ast.Macro \| Ast.Environment` | | ||
| | namedArgumentsFallback | `readonly string[]` | |
66232
17.27%586
26.57%95
26.67%