MCPcopy Create free account
hub / github.com/TruthHun/BookStack / _getExpansion

Method _getExpansion

static/katex/katex.mjs:14122–14162  ·  view source on GitHub ↗

* Returns the expanded macro as a reversed array of tokens and a macro * argument count. Or returns `null` if no such macro.

(name)

Source from the content-addressed store, hash-verified

14120
14121
14122 _getExpansion(name) {
14123 const definition = this.macros.get(name);
14124
14125 if (definition == null) {
14126 // mainly checking for undefined here
14127 return definition;
14128 }
14129
14130 const expansion = typeof definition === "function" ? definition(this) : definition;
14131
14132 if (typeof expansion === "string") {
14133 let numArgs = 0;
14134
14135 if (expansion.indexOf("#") !== -1) {
14136 const stripped = expansion.replace(/##/g, "");
14137
14138 while (stripped.indexOf("#" + (numArgs + 1)) !== -1) {
14139 ++numArgs;
14140 }
14141 }
14142
14143 const bodyLexer = new Lexer(expansion, this.settings);
14144 const tokens = [];
14145 let tok = bodyLexer.lex();
14146
14147 while (tok.text !== "EOF") {
14148 tokens.push(tok);
14149 tok = bodyLexer.lex();
14150 }
14151
14152 tokens.reverse(); // to fit in with stack using push and pop
14153
14154 const expanded = {
14155 tokens,
14156 numArgs
14157 };
14158 return expanded;
14159 }
14160
14161 return expansion;
14162 }
14163 /**
14164 * Determine whether a command is currently "defined" (has some
14165 * functionality), meaning that it's a macro (in the current group),

Callers 3

expandOnceMethod · 0.95
katex.jsFile · 0.80
katex.min.jsFile · 0.80

Calls 2

lexMethod · 0.95
getMethod · 0.45

Tested by

no test coverage detected