@unified-latex/unified-latex-util-environments 1.0.8 → 1.0.12
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 +91 -0
- package/index.cjs +81 -0
- package/package.json +11 -11
package/README.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
<!-- DO NOT MODIFY -->
|
|
2
|
+
<!-- This file was autogenerated by build-docs.ts -->
|
|
3
|
+
<!-- Edit the docstring in index.ts and regenerate -->
|
|
4
|
+
<!-- rather than editing this file directly. -->
|
|
5
|
+
# unified-latex-util-environments
|
|
6
|
+
|
|
7
|
+
## What is this?
|
|
8
|
+
|
|
9
|
+
Functions to report on/manipulate environments in a `unified-latex` Abstract Syntax Tree (AST).
|
|
10
|
+
|
|
11
|
+
## When should I use this?
|
|
12
|
+
|
|
13
|
+
If you are working on the internals of `unified-latex-util-parse` or need to make a custom parser
|
|
14
|
+
that treats environments differently.
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @unified-latex/unified-latex-util-environments
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
This package contains both esm and commonjs exports. To explicitly access the esm export,
|
|
23
|
+
import the `.js` file. To explicitly access the commonjs export, import the `.cjs` file.
|
|
24
|
+
|
|
25
|
+
# Plugins
|
|
26
|
+
|
|
27
|
+
## `unifiedLatexProcessEnvironments`
|
|
28
|
+
|
|
29
|
+
Unified plugin to process environment content and attach arguments.
|
|
30
|
+
|
|
31
|
+
### Usage
|
|
32
|
+
|
|
33
|
+
`unified().use(unifiedLatexProcessEnvironments[, options])`
|
|
34
|
+
|
|
35
|
+
#### options
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
{ environments: Ast.EnvInfoRecord; }
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Type
|
|
42
|
+
|
|
43
|
+
`Plugin<{ environments: Ast.EnvInfoRecord; }[], Ast.Root, Ast.Root>`
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
function unifiedLatexProcessEnvironments(options: {
|
|
47
|
+
environments: Ast.EnvInfoRecord;
|
|
48
|
+
}): (tree: Ast.Root) => void;
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
# Functions
|
|
52
|
+
|
|
53
|
+
## `processEnvironment(envNode, envInfo)`
|
|
54
|
+
|
|
55
|
+
Performs any needed processing on the environment (as specified by `envInfo`)
|
|
56
|
+
include attaching arguments and possibly manipulating the environment's body.
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
function processEnvironment(
|
|
60
|
+
envNode: Ast.Environment,
|
|
61
|
+
envInfo: Ast.EnvInfo
|
|
62
|
+
): void;
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
**Parameters**
|
|
66
|
+
|
|
67
|
+
| Param | Type |
|
|
68
|
+
| :------ | :---------------- |
|
|
69
|
+
| envNode | `Ast.Environment` |
|
|
70
|
+
| envInfo | `Ast.EnvInfo` |
|
|
71
|
+
|
|
72
|
+
## `processEnvironments(tree, environments)`
|
|
73
|
+
|
|
74
|
+
Recursively search for and process the specified environments. Arguments are
|
|
75
|
+
consumed according to the `signature` specified. The body is processed
|
|
76
|
+
with the specified `processContent` function (if given). Any specified `renderInfo`
|
|
77
|
+
is attached to the environment node.
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
function processEnvironments(
|
|
81
|
+
tree: Ast.Ast,
|
|
82
|
+
environments: Ast.EnvInfoRecord
|
|
83
|
+
): void;
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
**Parameters**
|
|
87
|
+
|
|
88
|
+
| Param | Type |
|
|
89
|
+
| :----------- | :------------------ |
|
|
90
|
+
| tree | `Ast.Ast` |
|
|
91
|
+
| environments | `Ast.EnvInfoRecord` |
|
package/index.cjs
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// index.ts
|
|
20
|
+
var unified_latex_util_environments_exports = {};
|
|
21
|
+
__export(unified_latex_util_environments_exports, {
|
|
22
|
+
processEnvironment: () => processEnvironment,
|
|
23
|
+
processEnvironments: () => processEnvironments,
|
|
24
|
+
unifiedLatexProcessEnvironments: () => unifiedLatexProcessEnvironments
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(unified_latex_util_environments_exports);
|
|
27
|
+
|
|
28
|
+
// libs/process-environment.ts
|
|
29
|
+
var import_unified_latex_util_render_info = require("@unified-latex/unified-latex-util-render-info");
|
|
30
|
+
var import_unified_latex_util_arguments = require("@unified-latex/unified-latex-util-arguments");
|
|
31
|
+
var import_unified_latex_util_match = require("@unified-latex/unified-latex-util-match");
|
|
32
|
+
var import_unified_latex_util_visit = require("@unified-latex/unified-latex-util-visit");
|
|
33
|
+
var import_unified_latex_util_print_raw = require("@unified-latex/unified-latex-util-print-raw");
|
|
34
|
+
function processEnvironment(envNode, envInfo) {
|
|
35
|
+
if (envInfo.signature && envNode.args == null) {
|
|
36
|
+
const { args } = (0, import_unified_latex_util_arguments.gobbleArguments)(envNode.content, envInfo.signature);
|
|
37
|
+
envNode.args = args;
|
|
38
|
+
}
|
|
39
|
+
(0, import_unified_latex_util_render_info.updateRenderInfo)(envNode, envInfo.renderInfo);
|
|
40
|
+
if (typeof envInfo.processContent === "function") {
|
|
41
|
+
envNode.content = envInfo.processContent(envNode.content);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function processEnvironments(tree, environments) {
|
|
45
|
+
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}"`);
|
|
52
|
+
}
|
|
53
|
+
processEnvironment(node, envInfo);
|
|
54
|
+
}
|
|
55
|
+
}, { test: isRelevantEnvironment });
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// libs/unified-latex-process-environment.ts
|
|
59
|
+
var import_unified_latex_util_visit2 = require("@unified-latex/unified-latex-util-visit");
|
|
60
|
+
var import_unified_latex_util_match2 = require("@unified-latex/unified-latex-util-match");
|
|
61
|
+
var import_unified_latex_util_print_raw2 = require("@unified-latex/unified-latex-util-print-raw");
|
|
62
|
+
var unifiedLatexProcessEnvironments = function unifiedLatexAttachMacroArguments(options) {
|
|
63
|
+
const { environments = {} } = options || {};
|
|
64
|
+
const isRelevantEnvironment = import_unified_latex_util_match2.match.createEnvironmentMatcher(environments);
|
|
65
|
+
return (tree) => {
|
|
66
|
+
if (Object.keys(environments).length === 0) {
|
|
67
|
+
console.warn("Attempting to attach macro arguments but no macros are specified.");
|
|
68
|
+
}
|
|
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}"`);
|
|
75
|
+
}
|
|
76
|
+
processEnvironment(node, envInfo);
|
|
77
|
+
}
|
|
78
|
+
}, { test: isRelevantEnvironment });
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
//# sourceMappingURL=index.cjs.map
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unified-latex/unified-latex-util-environments",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.12",
|
|
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.
|
|
9
|
-
"@unified-latex/unified-latex-util-arguments": "^1.0.
|
|
10
|
-
"@unified-latex/unified-latex-util-match": "^1.0.
|
|
11
|
-
"@unified-latex/unified-latex-util-print-raw": "^1.0.
|
|
12
|
-
"@unified-latex/unified-latex-util-render-info": "^1.0.
|
|
13
|
-
"@unified-latex/unified-latex-util-visit": "^1.0.
|
|
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",
|
|
14
14
|
"unified": "^10.1.2"
|
|
15
15
|
},
|
|
16
16
|
"repository": {
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
"homepage": "https://github.com/siefkenj/unified-latex#readme",
|
|
34
34
|
"exports": {
|
|
35
35
|
".": {
|
|
36
|
-
"import": "index.js",
|
|
37
|
-
"require": "index.cjs"
|
|
36
|
+
"import": "./index.js",
|
|
37
|
+
"require": "./index.cjs"
|
|
38
38
|
},
|
|
39
39
|
"./*js": "./*js",
|
|
40
40
|
"./*": {
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
}
|
|
49
49
|
},
|
|
50
50
|
"files": [
|
|
51
|
-
"
|
|
52
|
-
"
|
|
51
|
+
"**/*ts",
|
|
52
|
+
"**/*js",
|
|
53
53
|
"**/*.map",
|
|
54
54
|
"**/*.json"
|
|
55
55
|
]
|