@unified-latex/unified-latex-util-environments 1.0.12 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -53,7 +53,7 @@ function unifiedLatexProcessEnvironments(options: {
53
53
  ## `processEnvironment(envNode, envInfo)`
54
54
 
55
55
  Performs any needed processing on the environment (as specified by `envInfo`)
56
- include attaching arguments and possibly manipulating the environment's body.
56
+ including attaching arguments and possibly manipulating the environment's body.
57
57
 
58
58
  ```typescript
59
59
  function processEnvironment(
package/index.cjs CHANGED
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -43,16 +44,22 @@ function processEnvironment(envNode, envInfo) {
43
44
  }
44
45
  function processEnvironments(tree, environments) {
45
46
  const isRelevantEnvironment = import_unified_latex_util_match.match.createEnvironmentMatcher(environments);
46
- (0, import_unified_latex_util_visit.visit)(tree, {
47
- leave: (node) => {
48
- const envName = (0, import_unified_latex_util_print_raw.printRaw)(node.env);
49
- const envInfo = environments[envName];
50
- if (!envInfo) {
51
- throw new Error(`Could not find environment info for environment "${envName}"`);
47
+ (0, import_unified_latex_util_visit.visit)(
48
+ tree,
49
+ {
50
+ leave: (node) => {
51
+ const envName = (0, import_unified_latex_util_print_raw.printRaw)(node.env);
52
+ const envInfo = environments[envName];
53
+ if (!envInfo) {
54
+ throw new Error(
55
+ `Could not find environment info for environment "${envName}"`
56
+ );
57
+ }
58
+ processEnvironment(node, envInfo);
52
59
  }
53
- processEnvironment(node, envInfo);
54
- }
55
- }, { test: isRelevantEnvironment });
60
+ },
61
+ { test: isRelevantEnvironment }
62
+ );
56
63
  }
57
64
 
58
65
  // libs/unified-latex-process-environment.ts
@@ -64,18 +71,26 @@ var unifiedLatexProcessEnvironments = function unifiedLatexAttachMacroArguments(
64
71
  const isRelevantEnvironment = import_unified_latex_util_match2.match.createEnvironmentMatcher(environments);
65
72
  return (tree) => {
66
73
  if (Object.keys(environments).length === 0) {
67
- console.warn("Attempting to attach macro arguments but no macros are specified.");
74
+ console.warn(
75
+ "Attempting to attach macro arguments but no macros are specified."
76
+ );
68
77
  }
69
- (0, import_unified_latex_util_visit2.visit)(tree, {
70
- leave: (node) => {
71
- const envName = (0, import_unified_latex_util_print_raw2.printRaw)(node.env);
72
- const envInfo = environments[envName];
73
- if (!envInfo) {
74
- throw new Error(`Could not find environment info for environment "${envName}"`);
78
+ (0, import_unified_latex_util_visit2.visit)(
79
+ tree,
80
+ {
81
+ leave: (node) => {
82
+ const envName = (0, import_unified_latex_util_print_raw2.printRaw)(node.env);
83
+ const envInfo = environments[envName];
84
+ if (!envInfo) {
85
+ throw new Error(
86
+ `Could not find environment info for environment "${envName}"`
87
+ );
88
+ }
89
+ processEnvironment(node, envInfo);
75
90
  }
76
- processEnvironment(node, envInfo);
77
- }
78
- }, { test: isRelevantEnvironment });
91
+ },
92
+ { test: isRelevantEnvironment }
93
+ );
79
94
  };
80
95
  };
81
96
  //# sourceMappingURL=index.cjs.map
package/index.cjs.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../index.ts", "../libs/process-environment.ts", "../libs/unified-latex-process-environment.ts"],
4
- "sourcesContent": ["export * from \"./libs/process-environment\";\nexport * from \"./libs/unified-latex-process-environment\";\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 report on/manipulate environments in a `unified-latex` Abstract Syntax Tree (AST).\n *\n * ## When should I use this?\n *\n * If you are working on the internals of `unified-latex-util-parse` or need to make a custom parser\n * that treats environments differently.\n */\n", "import * as Ast from \"@unified-latex/unified-latex-types\";\nimport { EnvInfo, EnvInfoRecord } from \"@unified-latex/unified-latex-types\";\nimport { updateRenderInfo } from \"@unified-latex/unified-latex-util-render-info\";\nimport { gobbleArguments } from \"@unified-latex/unified-latex-util-arguments\";\nimport { match } from \"@unified-latex/unified-latex-util-match\";\nimport { visit } from \"@unified-latex/unified-latex-util-visit\";\nimport { printRaw } from \"@unified-latex/unified-latex-util-print-raw\";\n\n/**\n * Performs any needed processing on the environment (as specified by `envInfo`)\n * include attaching arguments and possibly manipulating the environment's body.\n */\nexport function processEnvironment(envNode: Ast.Environment, envInfo: EnvInfo) {\n if (envInfo.signature && envNode.args == null) {\n const { args } = gobbleArguments(envNode.content, envInfo.signature);\n envNode.args = args;\n }\n\n updateRenderInfo(envNode, envInfo.renderInfo);\n if (typeof envInfo.processContent === \"function\") {\n envNode.content = envInfo.processContent(envNode.content);\n }\n}\n\n/**\n * Recursively search for and process the specified environments. Arguments are\n * consumed according to the `signature` specified. The body is processed\n * with the specified `processContent` function (if given). Any specified `renderInfo`\n * is attached to the environment node.\n */\nexport function processEnvironments(\n tree: Ast.Ast,\n environments: EnvInfoRecord\n) {\n const isRelevantEnvironment = match.createEnvironmentMatcher(environments);\n\n visit(\n tree,\n {\n leave: (node) => {\n const envName = printRaw(node.env);\n const envInfo = environments[envName];\n if (!envInfo) {\n throw new Error(\n `Could not find environment info for environment \"${envName}\"`\n );\n }\n processEnvironment(node, envInfo);\n },\n },\n { test: isRelevantEnvironment }\n );\n}\n", "import * as Ast from \"@unified-latex/unified-latex-types\";\nimport { EnvInfoRecord } from \"@unified-latex/unified-latex-types\";\nimport { Plugin } from \"unified\";\nimport { visit } from \"@unified-latex/unified-latex-util-visit\";\nimport { match } from \"@unified-latex/unified-latex-util-match\";\nimport { processEnvironment } from \"./process-environment\";\nimport { printRaw } from \"@unified-latex/unified-latex-util-print-raw\";\n\ntype PluginOptions = { environments: EnvInfoRecord } | undefined;\n\n/**\n * Unified plugin to process environment content and attach arguments.\n *\n * @param environments An object whose keys are environment names and values contains information about the environment and its argument signature.\n */\nexport const unifiedLatexProcessEnvironments: Plugin<\n PluginOptions[],\n Ast.Root,\n Ast.Root\n> = function unifiedLatexAttachMacroArguments(options) {\n const { environments = {} } = options || {};\n const isRelevantEnvironment = match.createEnvironmentMatcher(environments);\n\n return (tree) => {\n if (Object.keys(environments).length === 0) {\n console.warn(\n \"Attempting to attach macro arguments but no macros are specified.\"\n );\n }\n\n visit(\n tree,\n {\n leave: (node) => {\n const envName = printRaw(node.env);\n const envInfo = environments[envName];\n if (!envInfo) {\n throw new Error(\n `Could not find environment info for environment \"${envName}\"`\n );\n }\n processEnvironment(node, envInfo);\n },\n },\n { test: isRelevantEnvironment }\n );\n };\n};\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEA,4CAAiC;AACjC,0CAAgC;AAChC,sCAAsB;AACtB,sCAAsB;AACtB,0CAAyB;AAMlB,4BAA4B,SAA0B,SAAkB;AAC3E,MAAI,QAAQ,aAAa,QAAQ,QAAQ,MAAM;AAC3C,UAAM,EAAE,SAAS,yDAAgB,QAAQ,SAAS,QAAQ,SAAS;AACnE,YAAQ,OAAO;AAAA,EACnB;AAEA,8DAAiB,SAAS,QAAQ,UAAU;AAC5C,MAAI,OAAO,QAAQ,mBAAmB,YAAY;AAC9C,YAAQ,UAAU,QAAQ,eAAe,QAAQ,OAAO;AAAA,EAC5D;AACJ;AAQO,6BACH,MACA,cACF;AACE,QAAM,wBAAwB,sCAAM,yBAAyB,YAAY;AAEzE,6CACI,MACA;AAAA,IACI,OAAO,CAAC,SAAS;AACb,YAAM,UAAU,kDAAS,KAAK,GAAG;AACjC,YAAM,UAAU,aAAa;AAC7B,UAAI,CAAC,SAAS;AACV,cAAM,IAAI,MACN,oDAAoD,UACxD;AAAA,MACJ;AACA,yBAAmB,MAAM,OAAO;AAAA,IACpC;AAAA,EACJ,GACA,EAAE,MAAM,sBAAsB,CAClC;AACJ;;;ACjDA,uCAAsB;AACtB,uCAAsB;AAEtB,2CAAyB;AASlB,IAAM,kCAIT,0CAA0C,SAAS;AACnD,QAAM,EAAE,eAAe,CAAC,MAAM,WAAW,CAAC;AAC1C,QAAM,wBAAwB,uCAAM,yBAAyB,YAAY;AAEzE,SAAO,CAAC,SAAS;AACb,QAAI,OAAO,KAAK,YAAY,EAAE,WAAW,GAAG;AACxC,cAAQ,KACJ,mEACJ;AAAA,IACJ;AAEA,gDACI,MACA;AAAA,MACI,OAAO,CAAC,SAAS;AACb,cAAM,UAAU,mDAAS,KAAK,GAAG;AACjC,cAAM,UAAU,aAAa;AAC7B,YAAI,CAAC,SAAS;AACV,gBAAM,IAAI,MACN,oDAAoD,UACxD;AAAA,QACJ;AACA,2BAAmB,MAAM,OAAO;AAAA,MACpC;AAAA,IACJ,GACA,EAAE,MAAM,sBAAsB,CAClC;AAAA,EACJ;AACJ;",
6
- "names": []
4
+ "sourcesContent": ["export * from \"./libs/process-environment\";\nexport * from \"./libs/unified-latex-process-environment\";\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 report on/manipulate environments in a `unified-latex` Abstract Syntax Tree (AST).\n *\n * ## When should I use this?\n *\n * If you are working on the internals of `unified-latex-util-parse` or need to make a custom parser\n * that treats environments differently.\n */\n", "import * as Ast from \"@unified-latex/unified-latex-types\";\nimport { EnvInfo, EnvInfoRecord } from \"@unified-latex/unified-latex-types\";\nimport { updateRenderInfo } from \"@unified-latex/unified-latex-util-render-info\";\nimport { gobbleArguments } from \"@unified-latex/unified-latex-util-arguments\";\nimport { match } from \"@unified-latex/unified-latex-util-match\";\nimport { visit } from \"@unified-latex/unified-latex-util-visit\";\nimport { printRaw } from \"@unified-latex/unified-latex-util-print-raw\";\n\n/**\n * Performs any needed processing on the environment (as specified by `envInfo`)\n * including attaching arguments and possibly manipulating the environment's body.\n */\nexport function processEnvironment(envNode: Ast.Environment, envInfo: EnvInfo) {\n if (envInfo.signature && envNode.args == null) {\n const { args } = gobbleArguments(envNode.content, envInfo.signature);\n envNode.args = args;\n }\n\n updateRenderInfo(envNode, envInfo.renderInfo);\n if (typeof envInfo.processContent === \"function\") {\n envNode.content = envInfo.processContent(envNode.content);\n }\n}\n\n/**\n * Recursively search for and process the specified environments. Arguments are\n * consumed according to the `signature` specified. The body is processed\n * with the specified `processContent` function (if given). Any specified `renderInfo`\n * is attached to the environment node.\n */\nexport function processEnvironments(\n tree: Ast.Ast,\n environments: EnvInfoRecord\n) {\n const isRelevantEnvironment = match.createEnvironmentMatcher(environments);\n\n visit(\n tree,\n {\n leave: (node) => {\n const envName = printRaw(node.env);\n const envInfo = environments[envName];\n if (!envInfo) {\n throw new Error(\n `Could not find environment info for environment \"${envName}\"`\n );\n }\n processEnvironment(node, envInfo);\n },\n },\n { test: isRelevantEnvironment }\n );\n}\n", "import * as Ast from \"@unified-latex/unified-latex-types\";\nimport { EnvInfoRecord } from \"@unified-latex/unified-latex-types\";\nimport { Plugin } from \"unified\";\nimport { visit } from \"@unified-latex/unified-latex-util-visit\";\nimport { match } from \"@unified-latex/unified-latex-util-match\";\nimport { processEnvironment } from \"./process-environment\";\nimport { printRaw } from \"@unified-latex/unified-latex-util-print-raw\";\n\ntype PluginOptions = { environments: EnvInfoRecord } | undefined;\n\n/**\n * Unified plugin to process environment content and attach arguments.\n *\n * @param environments An object whose keys are environment names and values contains information about the environment and its argument signature.\n */\nexport const unifiedLatexProcessEnvironments: Plugin<\n PluginOptions[],\n Ast.Root,\n Ast.Root\n> = function unifiedLatexAttachMacroArguments(options) {\n const { environments = {} } = options || {};\n const isRelevantEnvironment = match.createEnvironmentMatcher(environments);\n\n return (tree) => {\n if (Object.keys(environments).length === 0) {\n console.warn(\n \"Attempting to attach macro arguments but no macros are specified.\"\n );\n }\n\n visit(\n tree,\n {\n leave: (node) => {\n const envName = printRaw(node.env);\n const envInfo = environments[envName];\n if (!envInfo) {\n throw new Error(\n `Could not find environment info for environment \"${envName}\"`\n );\n }\n processEnvironment(node, envInfo);\n },\n },\n { test: isRelevantEnvironment }\n );\n };\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEA,4CAAiC;AACjC,0CAAgC;AAChC,sCAAsB;AACtB,sCAAsB;AACtB,0CAAyB;AAMlB,SAAS,mBAAmB,SAA0B,SAAkB;AAC3E,MAAI,QAAQ,aAAa,QAAQ,QAAQ,MAAM;AAC3C,UAAM,EAAE,KAAK,QAAI,qDAAgB,QAAQ,SAAS,QAAQ,SAAS;AACnE,YAAQ,OAAO;AAAA,EACnB;AAEA,8DAAiB,SAAS,QAAQ,UAAU;AAC5C,MAAI,OAAO,QAAQ,mBAAmB,YAAY;AAC9C,YAAQ,UAAU,QAAQ,eAAe,QAAQ,OAAO;AAAA,EAC5D;AACJ;AAQO,SAAS,oBACZ,MACA,cACF;AACE,QAAM,wBAAwB,sCAAM,yBAAyB,YAAY;AAEzE;AAAA,IACI;AAAA,IACA;AAAA,MACI,OAAO,CAAC,SAAS;AACb,cAAM,cAAU,8CAAS,KAAK,GAAG;AACjC,cAAM,UAAU,aAAa;AAC7B,YAAI,CAAC,SAAS;AACV,gBAAM,IAAI;AAAA,YACN,oDAAoD;AAAA,UACxD;AAAA,QACJ;AACA,2BAAmB,MAAM,OAAO;AAAA,MACpC;AAAA,IACJ;AAAA,IACA,EAAE,MAAM,sBAAsB;AAAA,EAClC;AACJ;;;ACjDA,IAAAA,mCAAsB;AACtB,IAAAC,mCAAsB;AAEtB,IAAAC,uCAAyB;AASlB,IAAM,kCAIT,SAAS,iCAAiC,SAAS;AACnD,QAAM,EAAE,eAAe,CAAC,EAAE,IAAI,WAAW,CAAC;AAC1C,QAAM,wBAAwB,uCAAM,yBAAyB,YAAY;AAEzE,SAAO,CAAC,SAAS;AACb,QAAI,OAAO,KAAK,YAAY,EAAE,WAAW,GAAG;AACxC,cAAQ;AAAA,QACJ;AAAA,MACJ;AAAA,IACJ;AAEA;AAAA,MACI;AAAA,MACA;AAAA,QACI,OAAO,CAAC,SAAS;AACb,gBAAM,cAAU,+CAAS,KAAK,GAAG;AACjC,gBAAM,UAAU,aAAa;AAC7B,cAAI,CAAC,SAAS;AACV,kBAAM,IAAI;AAAA,cACN,oDAAoD;AAAA,YACxD;AAAA,UACJ;AACA,6BAAmB,MAAM,OAAO;AAAA,QACpC;AAAA,MACJ;AAAA,MACA,EAAE,MAAM,sBAAsB;AAAA,IAClC;AAAA,EACJ;AACJ;",
6
+ "names": ["import_unified_latex_util_visit", "import_unified_latex_util_match", "import_unified_latex_util_print_raw"]
7
7
  }
package/index.js CHANGED
@@ -16,16 +16,22 @@ function processEnvironment(envNode, envInfo) {
16
16
  }
17
17
  function processEnvironments(tree, environments) {
18
18
  const isRelevantEnvironment = match.createEnvironmentMatcher(environments);
19
- visit(tree, {
20
- leave: (node) => {
21
- const envName = printRaw(node.env);
22
- const envInfo = environments[envName];
23
- if (!envInfo) {
24
- throw new Error(`Could not find environment info for environment "${envName}"`);
19
+ visit(
20
+ tree,
21
+ {
22
+ leave: (node) => {
23
+ const envName = printRaw(node.env);
24
+ const envInfo = environments[envName];
25
+ if (!envInfo) {
26
+ throw new Error(
27
+ `Could not find environment info for environment "${envName}"`
28
+ );
29
+ }
30
+ processEnvironment(node, envInfo);
25
31
  }
26
- processEnvironment(node, envInfo);
27
- }
28
- }, { test: isRelevantEnvironment });
32
+ },
33
+ { test: isRelevantEnvironment }
34
+ );
29
35
  }
30
36
 
31
37
  // libs/unified-latex-process-environment.ts
@@ -37,18 +43,26 @@ var unifiedLatexProcessEnvironments = function unifiedLatexAttachMacroArguments(
37
43
  const isRelevantEnvironment = match2.createEnvironmentMatcher(environments);
38
44
  return (tree) => {
39
45
  if (Object.keys(environments).length === 0) {
40
- console.warn("Attempting to attach macro arguments but no macros are specified.");
46
+ console.warn(
47
+ "Attempting to attach macro arguments but no macros are specified."
48
+ );
41
49
  }
42
- visit2(tree, {
43
- leave: (node) => {
44
- const envName = printRaw2(node.env);
45
- const envInfo = environments[envName];
46
- if (!envInfo) {
47
- throw new Error(`Could not find environment info for environment "${envName}"`);
50
+ visit2(
51
+ tree,
52
+ {
53
+ leave: (node) => {
54
+ const envName = printRaw2(node.env);
55
+ const envInfo = environments[envName];
56
+ if (!envInfo) {
57
+ throw new Error(
58
+ `Could not find environment info for environment "${envName}"`
59
+ );
60
+ }
61
+ processEnvironment(node, envInfo);
48
62
  }
49
- processEnvironment(node, envInfo);
50
- }
51
- }, { test: isRelevantEnvironment });
63
+ },
64
+ { test: isRelevantEnvironment }
65
+ );
52
66
  };
53
67
  };
54
68
  export {
package/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../libs/process-environment.ts", "../libs/unified-latex-process-environment.ts"],
4
- "sourcesContent": ["import * as Ast from \"@unified-latex/unified-latex-types\";\nimport { EnvInfo, EnvInfoRecord } from \"@unified-latex/unified-latex-types\";\nimport { updateRenderInfo } from \"@unified-latex/unified-latex-util-render-info\";\nimport { gobbleArguments } from \"@unified-latex/unified-latex-util-arguments\";\nimport { match } from \"@unified-latex/unified-latex-util-match\";\nimport { visit } from \"@unified-latex/unified-latex-util-visit\";\nimport { printRaw } from \"@unified-latex/unified-latex-util-print-raw\";\n\n/**\n * Performs any needed processing on the environment (as specified by `envInfo`)\n * include attaching arguments and possibly manipulating the environment's body.\n */\nexport function processEnvironment(envNode: Ast.Environment, envInfo: EnvInfo) {\n if (envInfo.signature && envNode.args == null) {\n const { args } = gobbleArguments(envNode.content, envInfo.signature);\n envNode.args = args;\n }\n\n updateRenderInfo(envNode, envInfo.renderInfo);\n if (typeof envInfo.processContent === \"function\") {\n envNode.content = envInfo.processContent(envNode.content);\n }\n}\n\n/**\n * Recursively search for and process the specified environments. Arguments are\n * consumed according to the `signature` specified. The body is processed\n * with the specified `processContent` function (if given). Any specified `renderInfo`\n * is attached to the environment node.\n */\nexport function processEnvironments(\n tree: Ast.Ast,\n environments: EnvInfoRecord\n) {\n const isRelevantEnvironment = match.createEnvironmentMatcher(environments);\n\n visit(\n tree,\n {\n leave: (node) => {\n const envName = printRaw(node.env);\n const envInfo = environments[envName];\n if (!envInfo) {\n throw new Error(\n `Could not find environment info for environment \"${envName}\"`\n );\n }\n processEnvironment(node, envInfo);\n },\n },\n { test: isRelevantEnvironment }\n );\n}\n", "import * as Ast from \"@unified-latex/unified-latex-types\";\nimport { EnvInfoRecord } from \"@unified-latex/unified-latex-types\";\nimport { Plugin } from \"unified\";\nimport { visit } from \"@unified-latex/unified-latex-util-visit\";\nimport { match } from \"@unified-latex/unified-latex-util-match\";\nimport { processEnvironment } from \"./process-environment\";\nimport { printRaw } from \"@unified-latex/unified-latex-util-print-raw\";\n\ntype PluginOptions = { environments: EnvInfoRecord } | undefined;\n\n/**\n * Unified plugin to process environment content and attach arguments.\n *\n * @param environments An object whose keys are environment names and values contains information about the environment and its argument signature.\n */\nexport const unifiedLatexProcessEnvironments: Plugin<\n PluginOptions[],\n Ast.Root,\n Ast.Root\n> = function unifiedLatexAttachMacroArguments(options) {\n const { environments = {} } = options || {};\n const isRelevantEnvironment = match.createEnvironmentMatcher(environments);\n\n return (tree) => {\n if (Object.keys(environments).length === 0) {\n console.warn(\n \"Attempting to attach macro arguments but no macros are specified.\"\n );\n }\n\n visit(\n tree,\n {\n leave: (node) => {\n const envName = printRaw(node.env);\n const envInfo = environments[envName];\n if (!envInfo) {\n throw new Error(\n `Could not find environment info for environment \"${envName}\"`\n );\n }\n processEnvironment(node, envInfo);\n },\n },\n { test: isRelevantEnvironment }\n );\n };\n};\n"],
5
- "mappings": ";AAEA;AACA;AACA;AACA;AACA;AAMO,4BAA4B,SAA0B,SAAkB;AAC3E,MAAI,QAAQ,aAAa,QAAQ,QAAQ,MAAM;AAC3C,UAAM,EAAE,SAAS,gBAAgB,QAAQ,SAAS,QAAQ,SAAS;AACnE,YAAQ,OAAO;AAAA,EACnB;AAEA,mBAAiB,SAAS,QAAQ,UAAU;AAC5C,MAAI,OAAO,QAAQ,mBAAmB,YAAY;AAC9C,YAAQ,UAAU,QAAQ,eAAe,QAAQ,OAAO;AAAA,EAC5D;AACJ;AAQO,6BACH,MACA,cACF;AACE,QAAM,wBAAwB,MAAM,yBAAyB,YAAY;AAEzE,QACI,MACA;AAAA,IACI,OAAO,CAAC,SAAS;AACb,YAAM,UAAU,SAAS,KAAK,GAAG;AACjC,YAAM,UAAU,aAAa;AAC7B,UAAI,CAAC,SAAS;AACV,cAAM,IAAI,MACN,oDAAoD,UACxD;AAAA,MACJ;AACA,yBAAmB,MAAM,OAAO;AAAA,IACpC;AAAA,EACJ,GACA,EAAE,MAAM,sBAAsB,CAClC;AACJ;;;ACjDA;AACA;AAEA;AASO,IAAM,kCAIT,0CAA0C,SAAS;AACnD,QAAM,EAAE,eAAe,CAAC,MAAM,WAAW,CAAC;AAC1C,QAAM,wBAAwB,OAAM,yBAAyB,YAAY;AAEzE,SAAO,CAAC,SAAS;AACb,QAAI,OAAO,KAAK,YAAY,EAAE,WAAW,GAAG;AACxC,cAAQ,KACJ,mEACJ;AAAA,IACJ;AAEA,WACI,MACA;AAAA,MACI,OAAO,CAAC,SAAS;AACb,cAAM,UAAU,UAAS,KAAK,GAAG;AACjC,cAAM,UAAU,aAAa;AAC7B,YAAI,CAAC,SAAS;AACV,gBAAM,IAAI,MACN,oDAAoD,UACxD;AAAA,QACJ;AACA,2BAAmB,MAAM,OAAO;AAAA,MACpC;AAAA,IACJ,GACA,EAAE,MAAM,sBAAsB,CAClC;AAAA,EACJ;AACJ;",
6
- "names": []
4
+ "sourcesContent": ["import * as Ast from \"@unified-latex/unified-latex-types\";\nimport { EnvInfo, EnvInfoRecord } from \"@unified-latex/unified-latex-types\";\nimport { updateRenderInfo } from \"@unified-latex/unified-latex-util-render-info\";\nimport { gobbleArguments } from \"@unified-latex/unified-latex-util-arguments\";\nimport { match } from \"@unified-latex/unified-latex-util-match\";\nimport { visit } from \"@unified-latex/unified-latex-util-visit\";\nimport { printRaw } from \"@unified-latex/unified-latex-util-print-raw\";\n\n/**\n * Performs any needed processing on the environment (as specified by `envInfo`)\n * including attaching arguments and possibly manipulating the environment's body.\n */\nexport function processEnvironment(envNode: Ast.Environment, envInfo: EnvInfo) {\n if (envInfo.signature && envNode.args == null) {\n const { args } = gobbleArguments(envNode.content, envInfo.signature);\n envNode.args = args;\n }\n\n updateRenderInfo(envNode, envInfo.renderInfo);\n if (typeof envInfo.processContent === \"function\") {\n envNode.content = envInfo.processContent(envNode.content);\n }\n}\n\n/**\n * Recursively search for and process the specified environments. Arguments are\n * consumed according to the `signature` specified. The body is processed\n * with the specified `processContent` function (if given). Any specified `renderInfo`\n * is attached to the environment node.\n */\nexport function processEnvironments(\n tree: Ast.Ast,\n environments: EnvInfoRecord\n) {\n const isRelevantEnvironment = match.createEnvironmentMatcher(environments);\n\n visit(\n tree,\n {\n leave: (node) => {\n const envName = printRaw(node.env);\n const envInfo = environments[envName];\n if (!envInfo) {\n throw new Error(\n `Could not find environment info for environment \"${envName}\"`\n );\n }\n processEnvironment(node, envInfo);\n },\n },\n { test: isRelevantEnvironment }\n );\n}\n", "import * as Ast from \"@unified-latex/unified-latex-types\";\nimport { EnvInfoRecord } from \"@unified-latex/unified-latex-types\";\nimport { Plugin } from \"unified\";\nimport { visit } from \"@unified-latex/unified-latex-util-visit\";\nimport { match } from \"@unified-latex/unified-latex-util-match\";\nimport { processEnvironment } from \"./process-environment\";\nimport { printRaw } from \"@unified-latex/unified-latex-util-print-raw\";\n\ntype PluginOptions = { environments: EnvInfoRecord } | undefined;\n\n/**\n * Unified plugin to process environment content and attach arguments.\n *\n * @param environments An object whose keys are environment names and values contains information about the environment and its argument signature.\n */\nexport const unifiedLatexProcessEnvironments: Plugin<\n PluginOptions[],\n Ast.Root,\n Ast.Root\n> = function unifiedLatexAttachMacroArguments(options) {\n const { environments = {} } = options || {};\n const isRelevantEnvironment = match.createEnvironmentMatcher(environments);\n\n return (tree) => {\n if (Object.keys(environments).length === 0) {\n console.warn(\n \"Attempting to attach macro arguments but no macros are specified.\"\n );\n }\n\n visit(\n tree,\n {\n leave: (node) => {\n const envName = printRaw(node.env);\n const envInfo = environments[envName];\n if (!envInfo) {\n throw new Error(\n `Could not find environment info for environment \"${envName}\"`\n );\n }\n processEnvironment(node, envInfo);\n },\n },\n { test: isRelevantEnvironment }\n );\n };\n};\n"],
5
+ "mappings": ";AAEA,SAAS,wBAAwB;AACjC,SAAS,uBAAuB;AAChC,SAAS,aAAa;AACtB,SAAS,aAAa;AACtB,SAAS,gBAAgB;AAMlB,SAAS,mBAAmB,SAA0B,SAAkB;AAC3E,MAAI,QAAQ,aAAa,QAAQ,QAAQ,MAAM;AAC3C,UAAM,EAAE,KAAK,IAAI,gBAAgB,QAAQ,SAAS,QAAQ,SAAS;AACnE,YAAQ,OAAO;AAAA,EACnB;AAEA,mBAAiB,SAAS,QAAQ,UAAU;AAC5C,MAAI,OAAO,QAAQ,mBAAmB,YAAY;AAC9C,YAAQ,UAAU,QAAQ,eAAe,QAAQ,OAAO;AAAA,EAC5D;AACJ;AAQO,SAAS,oBACZ,MACA,cACF;AACE,QAAM,wBAAwB,MAAM,yBAAyB,YAAY;AAEzE;AAAA,IACI;AAAA,IACA;AAAA,MACI,OAAO,CAAC,SAAS;AACb,cAAM,UAAU,SAAS,KAAK,GAAG;AACjC,cAAM,UAAU,aAAa;AAC7B,YAAI,CAAC,SAAS;AACV,gBAAM,IAAI;AAAA,YACN,oDAAoD;AAAA,UACxD;AAAA,QACJ;AACA,2BAAmB,MAAM,OAAO;AAAA,MACpC;AAAA,IACJ;AAAA,IACA,EAAE,MAAM,sBAAsB;AAAA,EAClC;AACJ;;;ACjDA,SAAS,SAAAA,cAAa;AACtB,SAAS,SAAAC,cAAa;AAEtB,SAAS,YAAAC,iBAAgB;AASlB,IAAM,kCAIT,SAAS,iCAAiC,SAAS;AACnD,QAAM,EAAE,eAAe,CAAC,EAAE,IAAI,WAAW,CAAC;AAC1C,QAAM,wBAAwBC,OAAM,yBAAyB,YAAY;AAEzE,SAAO,CAAC,SAAS;AACb,QAAI,OAAO,KAAK,YAAY,EAAE,WAAW,GAAG;AACxC,cAAQ;AAAA,QACJ;AAAA,MACJ;AAAA,IACJ;AAEA,IAAAC;AAAA,MACI;AAAA,MACA;AAAA,QACI,OAAO,CAAC,SAAS;AACb,gBAAM,UAAUF,UAAS,KAAK,GAAG;AACjC,gBAAM,UAAU,aAAa;AAC7B,cAAI,CAAC,SAAS;AACV,kBAAM,IAAI;AAAA,cACN,oDAAoD;AAAA,YACxD;AAAA,UACJ;AACA,6BAAmB,MAAM,OAAO;AAAA,QACpC;AAAA,MACJ;AAAA,MACA,EAAE,MAAM,sBAAsB;AAAA,IAClC;AAAA,EACJ;AACJ;",
6
+ "names": ["visit", "match", "printRaw", "match", "visit"]
7
7
  }
@@ -2,7 +2,7 @@ import * as Ast from "@unified-latex/unified-latex-types";
2
2
  import { EnvInfo, EnvInfoRecord } from "@unified-latex/unified-latex-types";
3
3
  /**
4
4
  * Performs any needed processing on the environment (as specified by `envInfo`)
5
- * include attaching arguments and possibly manipulating the environment's body.
5
+ * including attaching arguments and possibly manipulating the environment's body.
6
6
  */
7
7
  export declare function processEnvironment(envNode: Ast.Environment, envInfo: EnvInfo): void;
8
8
  /**
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@unified-latex/unified-latex-util-environments",
3
- "version": "1.0.12",
3
+ "version": "1.2.0",
4
4
  "description": "Tools for manipulating unified-latex ASTs",
5
5
  "main": "index.js",
6
6
  "type": "module",
7
7
  "dependencies": {
8
- "@unified-latex/unified-latex-types": "^1.0.12",
9
- "@unified-latex/unified-latex-util-arguments": "^1.0.12",
10
- "@unified-latex/unified-latex-util-match": "^1.0.12",
11
- "@unified-latex/unified-latex-util-print-raw": "^1.0.12",
12
- "@unified-latex/unified-latex-util-render-info": "^1.0.12",
13
- "@unified-latex/unified-latex-util-visit": "^1.0.12",
8
+ "@unified-latex/unified-latex-types": "^1.2.0",
9
+ "@unified-latex/unified-latex-util-arguments": "^1.2.0",
10
+ "@unified-latex/unified-latex-util-match": "^1.2.0",
11
+ "@unified-latex/unified-latex-util-print-raw": "^1.2.0",
12
+ "@unified-latex/unified-latex-util-render-info": "^1.2.0",
13
+ "@unified-latex/unified-latex-util-visit": "^1.2.0",
14
14
  "unified": "^10.1.2"
15
15
  },
16
16
  "repository": {