@thi.ng/tangle 0.1.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/CHANGELOG.md +22 -0
- package/LICENSE +201 -0
- package/README.md +360 -0
- package/api.d.ts +47 -0
- package/api.js +59 -0
- package/bin/tangle +12 -0
- package/cli.d.ts +5 -0
- package/cli.js +64 -0
- package/doc/assets/main.js +52 -0
- package/doc/assets/search.js +1 -0
- package/index.d.ts +3 -0
- package/index.js +2 -0
- package/package.json +95 -0
- package/tangle.d.ts +19 -0
- package/tangle.js +205 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
- **Last updated**: 2022-09-21T21:37:59Z
|
|
4
|
+
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
|
|
5
|
+
|
|
6
|
+
All notable changes to this project will be documented in this file.
|
|
7
|
+
See [Conventional Commits](https://conventionalcommits.org/) for commit guidelines.
|
|
8
|
+
|
|
9
|
+
**Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
|
|
10
|
+
and/or version bumps of transitive dependencies.
|
|
11
|
+
|
|
12
|
+
## [0.1.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/tangle@0.1.0) (2022-09-21)
|
|
13
|
+
|
|
14
|
+
#### 🚀 Features
|
|
15
|
+
|
|
16
|
+
- update/fix tangle logic, filesys context, CLI ([85a3968](https://github.com/thi-ng/umbrella/commit/85a3968))
|
|
17
|
+
- add block concatenation if multiple blocks w/ same target
|
|
18
|
+
- fix block boundary regex
|
|
19
|
+
- add absolute path checks for outputs
|
|
20
|
+
- refactor TangleCtx, extract FileSys, update in-memory impl
|
|
21
|
+
- expose CLI in package.json
|
|
22
|
+
- import as new package ([99e789e](https://github.com/thi-ng/umbrella/commit/99e789e))
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright {yyyy} {name of copyright owner}
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
<!-- This file is generated - DO NOT EDIT! -->
|
|
2
|
+
|
|
3
|
+
# 
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@thi.ng/tangle)
|
|
6
|
+

|
|
7
|
+
[](https://twitter.com/thing_umbrella)
|
|
8
|
+
|
|
9
|
+
This project is part of the
|
|
10
|
+
[@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo.
|
|
11
|
+
|
|
12
|
+
- [About](#about)
|
|
13
|
+
- [Document front matter](#document-front-matter)
|
|
14
|
+
- [`tangle`](#tangle)
|
|
15
|
+
- [`pubish`](#pubish)
|
|
16
|
+
- [Code block metadata](#code-block-metadata)
|
|
17
|
+
- [`id`](#id)
|
|
18
|
+
- [`noweb`](#noweb)
|
|
19
|
+
- [`publish`](#publish)
|
|
20
|
+
- [`tangle`](#tangle)
|
|
21
|
+
- [Basic usage](#basic-usage)
|
|
22
|
+
- [Generated Outputs](#generated-outputs)
|
|
23
|
+
- [Editor integrations](#editor-integrations)
|
|
24
|
+
- [VSCode](#vscode)
|
|
25
|
+
- [Other editors](#other-editors)
|
|
26
|
+
- [Status](#status)
|
|
27
|
+
- [Installation](#installation)
|
|
28
|
+
- [Dependencies](#dependencies)
|
|
29
|
+
- [API](#api)
|
|
30
|
+
- [Authors](#authors)
|
|
31
|
+
- [License](#license)
|
|
32
|
+
|
|
33
|
+
## About
|
|
34
|
+
|
|
35
|
+
Literate programming code block tangling / codegen utility, inspired by org-mode & noweb.
|
|
36
|
+
|
|
37
|
+
[Literate Programming](https://en.wikipedia.org/wiki/Literate_programming) (LP)
|
|
38
|
+
is a form of programming focused on creating documents of interleaved prose,
|
|
39
|
+
code, and supporting diagrams/illustrations, pioneered by [Donald
|
|
40
|
+
Knuth](https://en.wikipedia.org/wiki/Donald_Knuth) for his TeX system. If you're
|
|
41
|
+
new to this approach, please first read the Wikipedia article for a basic
|
|
42
|
+
introduction. For all LP projects, a so-called "tangling" step is required to
|
|
43
|
+
produce workable, standard source code files from these documents. This package
|
|
44
|
+
provides just that:
|
|
45
|
+
|
|
46
|
+
Extract, expand, transclude, combine and assemble code blocks from Markdown or
|
|
47
|
+
[Org-mode](https://orgmode.org) files into actual/traditional source files. A
|
|
48
|
+
single LP source file can contain code for multiple languages. Each code block
|
|
49
|
+
can define its target file and include [noweb-style
|
|
50
|
+
references](https://orgmode.org/manual/Noweb-Reference-Syntax.html) to other
|
|
51
|
+
code blocks, either from the same or even from other files.
|
|
52
|
+
|
|
53
|
+
The package provides both a basic API and a CLI wrapper to perform the
|
|
54
|
+
"tangling" tasks (an expression borrowed from
|
|
55
|
+
[Org-mode](https://orgmode.org/manual/Extracting-Source-Code.html)).
|
|
56
|
+
|
|
57
|
+
(FWIW all early [thi.ng](https://thi.ng) libraries created between 2011-2016
|
|
58
|
+
were written in this format, e.g.
|
|
59
|
+
[thi.ng/fabric](https://github.com/thi-ng/fabric),
|
|
60
|
+
[thi.ng/geom](https://github.com/thi-ng/geom),
|
|
61
|
+
[thi.ng/luxor](https://github.com/thi-ng/luxor),
|
|
62
|
+
[thi.ng/morphogen](https://github.com/thi-ng/morphogen))
|
|
63
|
+
|
|
64
|
+
### Document front matter
|
|
65
|
+
|
|
66
|
+
LP source files can contain a front matter section, currently supporting the
|
|
67
|
+
following properties (all optional, also see example document further below):
|
|
68
|
+
|
|
69
|
+
#### `tangle`
|
|
70
|
+
|
|
71
|
+
Absolute or relative path to base output directory for tangled code blocks. This
|
|
72
|
+
is only used if a code block's `tangle` path is a relative path.
|
|
73
|
+
|
|
74
|
+
#### `pubish`
|
|
75
|
+
|
|
76
|
+
Absolute or relative path to write a "published" version of the LP source file,
|
|
77
|
+
in which all code blocks have been transformed & code block references
|
|
78
|
+
resolved/expanded/transcluded. If this property is omitted, no such output will
|
|
79
|
+
be generated.
|
|
80
|
+
|
|
81
|
+
### Code block metadata
|
|
82
|
+
|
|
83
|
+
In addition to the optional document front matter configuration, each code block
|
|
84
|
+
can specify the following metadata `key:value` pairs:
|
|
85
|
+
|
|
86
|
+
#### `id`
|
|
87
|
+
|
|
88
|
+
Unique (within the current doc) code block identifier. Only required if the
|
|
89
|
+
contents of this code block are to be referenced/transcluded elsewhere.
|
|
90
|
+
|
|
91
|
+
#### `noweb`
|
|
92
|
+
|
|
93
|
+
If set to `noweb:no`, any code block references in this block will **not** be
|
|
94
|
+
expanded. See section below for more details about these reference.
|
|
95
|
+
|
|
96
|
+
#### `publish`
|
|
97
|
+
|
|
98
|
+
If set to `publish:no`, the code block will be omitted in the published version
|
|
99
|
+
of the current document.
|
|
100
|
+
|
|
101
|
+
#### `tangle`
|
|
102
|
+
|
|
103
|
+
Absolute or relative path of the target file where the expanded contents of this
|
|
104
|
+
code block should be written to. If a relative path, it'll be relative to the
|
|
105
|
+
path stated in the front matter. If omitted, the code block will **not** be
|
|
106
|
+
extracted to its own file. If multiple code blocks in the _same_ source file are
|
|
107
|
+
specifying the same target file, their contents will be concatenated (in order
|
|
108
|
+
of appearance).
|
|
109
|
+
|
|
110
|
+
## Basic usage
|
|
111
|
+
|
|
112
|
+
The following Markdown example acts as a source file (presumably for Literate
|
|
113
|
+
Programming purposes) from which various interlinked code blocks will be
|
|
114
|
+
extracted (into any number of new files). Additionally, this file itself is also
|
|
115
|
+
being transformed for "publishing", meaning all code block references &
|
|
116
|
+
transclusions are getting resolved/replaced in the published version of this
|
|
117
|
+
file.
|
|
118
|
+
|
|
119
|
+
main.md:
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
publish: out/main.md
|
|
123
|
+
tangle: out
|
|
124
|
+
---
|
|
125
|
+
# Tangle test
|
|
126
|
+
|
|
127
|
+
This next code block will be tangled/extracted to the specified file and since
|
|
128
|
+
its body entirely consists of a reference to another code block, it will be
|
|
129
|
+
replaced with the contents of the code block with ID `imports` in the file
|
|
130
|
+
`lib.md` (see further below)
|
|
131
|
+
|
|
132
|
+
```ts tangle:src/index.ts
|
|
133
|
+
<<lib.md#imports>>
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Next we transclude the contents of the code block with ID `foo` and perform some
|
|
137
|
+
other computation. This block (and the next one too) will be tangled to the same
|
|
138
|
+
target file (concatenated):
|
|
139
|
+
|
|
140
|
+
```ts tangle:src/index.ts
|
|
141
|
+
<<foo>>
|
|
142
|
+
|
|
143
|
+
const bar = 42;
|
|
144
|
+
|
|
145
|
+
console.log(foo + bar);
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Finally, here's a demonstration of how transcluded code blocks can also receive
|
|
149
|
+
parameters (supplied via an options object as argument):
|
|
150
|
+
|
|
151
|
+
```ts tangle:src/index.ts
|
|
152
|
+
<<lib.md#parametric { "hello": "world" }>>
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## Misc
|
|
156
|
+
|
|
157
|
+
The following block will be only transcluded in the first one, however has its
|
|
158
|
+
`publish` flag disabled so that it will **not** be included in the published
|
|
159
|
+
version of this file.
|
|
160
|
+
|
|
161
|
+
```ts id:foo publish:no
|
|
162
|
+
const foo = 23;
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
lib.md (e.g. maybe a library of useful snippets for a larger project):
|
|
166
|
+
|
|
167
|
+
# Library of snippets
|
|
168
|
+
|
|
169
|
+
```ts id:imports
|
|
170
|
+
// @ts-ignore
|
|
171
|
+
import type { Fn } from "@thi.ng/api";
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
```ts id:parametric
|
|
175
|
+
export const hello = "Hi, {{hello}}!";
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Calling the `tangle` CLI util, we can process these example files and produce
|
|
179
|
+
the following two outputs:
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
npx @thi.ng/tangle --help
|
|
183
|
+
|
|
184
|
+
# █ █ █ │
|
|
185
|
+
# ██ █ │
|
|
186
|
+
# █ █ █ █ █ █ █ █ │ @thi.ng/tangle 0.1.0
|
|
187
|
+
# █ █ █ █ █ █ █ █ █ │ Literate programming code block tangling
|
|
188
|
+
# █ │
|
|
189
|
+
# █ █ │
|
|
190
|
+
#
|
|
191
|
+
# usage: tangle [OPTS] SOURCE-FILES(S) ...
|
|
192
|
+
# tangle --help
|
|
193
|
+
#
|
|
194
|
+
# Flags:
|
|
195
|
+
#
|
|
196
|
+
# -d, --debug enable debug output
|
|
197
|
+
# --dry-run enable dry run (don't overwrite files)
|
|
198
|
+
# --no-comments don't generate comments
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
```bash
|
|
202
|
+
npx @thi.ng/tangle main.md
|
|
203
|
+
# [INFO] tangle: writing file: <...>/out/src/index.ts
|
|
204
|
+
# [INFO] tangle: writing file: <...>/out/main.md
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
#### Generated Outputs
|
|
208
|
+
|
|
209
|
+
The generated/tangled source file: `out/src/index.ts`
|
|
210
|
+
|
|
211
|
+
```ts
|
|
212
|
+
// Tangled @ 2022-09-21T16:57:43+02:00 - DO NOT EDIT!
|
|
213
|
+
// Source: <...>/main.lit.md
|
|
214
|
+
|
|
215
|
+
// @ts-ignore
|
|
216
|
+
import type { Fn } from "@thi.ng/api";
|
|
217
|
+
|
|
218
|
+
const foo = 23;
|
|
219
|
+
|
|
220
|
+
const bar = 42;
|
|
221
|
+
|
|
222
|
+
console.log(foo + bar);
|
|
223
|
+
|
|
224
|
+
export const hello = "Hi, world!";
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
The published version of the input markdown file: `out/main.md`
|
|
228
|
+
|
|
229
|
+
---
|
|
230
|
+
publish: out/main.md
|
|
231
|
+
tangle: out
|
|
232
|
+
---
|
|
233
|
+
# Tangle test
|
|
234
|
+
|
|
235
|
+
This next code block will be tangled/extracted to the specified file and since
|
|
236
|
+
its body entirely consists of a reference to another code block, it will be
|
|
237
|
+
replaced with the contents of the code block with ID `imports` in the file
|
|
238
|
+
`lib.md` (see further below)
|
|
239
|
+
|
|
240
|
+
```ts
|
|
241
|
+
// @ts-ignore
|
|
242
|
+
import type { Fn } from "@thi.ng/api";
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
Next we transclude the contents of the code block with ID `foo` and perform some
|
|
246
|
+
other computation. This block (and the next one too) will be tangled to the same
|
|
247
|
+
target file (concatenated):
|
|
248
|
+
|
|
249
|
+
```ts
|
|
250
|
+
const foo = 23;
|
|
251
|
+
|
|
252
|
+
const bar = 42;
|
|
253
|
+
|
|
254
|
+
console.log(foo + bar);
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
Finally, here's a demonstration of how transcluded code blocks can also receive
|
|
258
|
+
parameters (supplied via an options object as argument):
|
|
259
|
+
|
|
260
|
+
```ts
|
|
261
|
+
export const hello = "Hi, world!";
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
## Misc
|
|
265
|
+
|
|
266
|
+
The following block will be only transcluded in the first one, however has its
|
|
267
|
+
`publish` flag disabled so that it will **not** be included in the published
|
|
268
|
+
version of this file.
|
|
269
|
+
|
|
270
|
+
## Editor integrations
|
|
271
|
+
|
|
272
|
+
### VSCode
|
|
273
|
+
|
|
274
|
+
Using the [Run On Save extension](https://marketplace.visualstudio.com/items?itemName=emeraldwalk.RunOnSave), tangling can be automatically performed on each save of an Literate Programming source file. E.g. this configuration (add to your VSCode workspace `settings.json`) runs the tangle command on each save of a `*.lit.md` file.
|
|
275
|
+
|
|
276
|
+
```json
|
|
277
|
+
"emeraldwalk.runonsave": {
|
|
278
|
+
"commands": [
|
|
279
|
+
{
|
|
280
|
+
"match": "\\.lit\\.md$",
|
|
281
|
+
"cmd": "${workspaceFolder}/node_modules/.bin/tangle ${file}"
|
|
282
|
+
}
|
|
283
|
+
]
|
|
284
|
+
}
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
Note: This also assumes you have this package (@thi.ng/tangle) added to your dependencies...
|
|
288
|
+
|
|
289
|
+
### Other editors
|
|
290
|
+
|
|
291
|
+
Accepting PRs with instructruction for other editors & IDEs.
|
|
292
|
+
|
|
293
|
+
## Status
|
|
294
|
+
|
|
295
|
+
**ALPHA** - bleeding edge / work-in-progress
|
|
296
|
+
|
|
297
|
+
[Search or submit any issues for this package](https://github.com/thi-ng/umbrella/issues?q=%5Btangle%5D+in%3Atitle)
|
|
298
|
+
|
|
299
|
+
## Installation
|
|
300
|
+
|
|
301
|
+
```bash
|
|
302
|
+
yarn add @thi.ng/tangle
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
ES module import:
|
|
306
|
+
|
|
307
|
+
```html
|
|
308
|
+
<script type="module" src="https://cdn.skypack.dev/@thi.ng/tangle"></script>
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
[Skypack documentation](https://docs.skypack.dev/)
|
|
312
|
+
|
|
313
|
+
For Node.js REPL:
|
|
314
|
+
|
|
315
|
+
```text
|
|
316
|
+
# with flag only for < v16
|
|
317
|
+
node --experimental-repl-await
|
|
318
|
+
|
|
319
|
+
> const tangle = await import("@thi.ng/tangle");
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
Package sizes (gzipped, pre-treeshake): ESM: 1.96 KB
|
|
323
|
+
|
|
324
|
+
## Dependencies
|
|
325
|
+
|
|
326
|
+
- [@thi.ng/api](https://github.com/thi-ng/umbrella/tree/develop/packages/api)
|
|
327
|
+
- [@thi.ng/args](https://github.com/thi-ng/umbrella/tree/develop/packages/args)
|
|
328
|
+
- [@thi.ng/checks](https://github.com/thi-ng/umbrella/tree/develop/packages/checks)
|
|
329
|
+
- [@thi.ng/compare](https://github.com/thi-ng/umbrella/tree/develop/packages/compare)
|
|
330
|
+
- [@thi.ng/date](https://github.com/thi-ng/umbrella/tree/develop/packages/date)
|
|
331
|
+
- [@thi.ng/errors](https://github.com/thi-ng/umbrella/tree/develop/packages/errors)
|
|
332
|
+
- [@thi.ng/file-io](https://github.com/thi-ng/umbrella/tree/develop/packages/file-io)
|
|
333
|
+
- [@thi.ng/logger](https://github.com/thi-ng/umbrella/tree/develop/packages/logger)
|
|
334
|
+
- [@thi.ng/strings](https://github.com/thi-ng/umbrella/tree/develop/packages/strings)
|
|
335
|
+
- [@thi.ng/transducers](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers)
|
|
336
|
+
|
|
337
|
+
## API
|
|
338
|
+
|
|
339
|
+
[Generated API docs](https://docs.thi.ng/umbrella/tangle/)
|
|
340
|
+
|
|
341
|
+
TODO
|
|
342
|
+
|
|
343
|
+
## Authors
|
|
344
|
+
|
|
345
|
+
Karsten Schmidt
|
|
346
|
+
|
|
347
|
+
If this project contributes to an academic publication, please cite it as:
|
|
348
|
+
|
|
349
|
+
```bibtex
|
|
350
|
+
@misc{thing-tangle,
|
|
351
|
+
title = "@thi.ng/tangle",
|
|
352
|
+
author = "Karsten Schmidt",
|
|
353
|
+
note = "https://thi.ng/tangle",
|
|
354
|
+
year = 2022
|
|
355
|
+
}
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
## License
|
|
359
|
+
|
|
360
|
+
© 2022 Karsten Schmidt // Apache Software License 2.0
|
package/api.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Fn2, FnAnyT, IObjectOf, Predicate } from "@thi.ng/api";
|
|
2
|
+
import { ILogger } from "@thi.ng/logger";
|
|
3
|
+
export interface Block {
|
|
4
|
+
id: string;
|
|
5
|
+
tangle?: string;
|
|
6
|
+
publish?: string;
|
|
7
|
+
noweb: string;
|
|
8
|
+
lang: string;
|
|
9
|
+
matchStart: number;
|
|
10
|
+
matchEnd: number;
|
|
11
|
+
start: number;
|
|
12
|
+
end: number;
|
|
13
|
+
body: string;
|
|
14
|
+
edited?: boolean;
|
|
15
|
+
resolved?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export interface TangleRef {
|
|
18
|
+
path: string;
|
|
19
|
+
src: string;
|
|
20
|
+
blocks: Record<string, Block>;
|
|
21
|
+
}
|
|
22
|
+
export declare type Blocks = Record<string, Block>;
|
|
23
|
+
export interface TangleCtx {
|
|
24
|
+
format: CodeBlockFormat;
|
|
25
|
+
files: Record<string, TangleRef>;
|
|
26
|
+
outputs: Record<string, string>;
|
|
27
|
+
logger: ILogger;
|
|
28
|
+
fs: FileSystem;
|
|
29
|
+
opts: Partial<TangleOpts>;
|
|
30
|
+
}
|
|
31
|
+
export interface FileSystem {
|
|
32
|
+
isAbsolute: Predicate<string>;
|
|
33
|
+
resolve: FnAnyT<string, string>;
|
|
34
|
+
read: Fn2<string, ILogger, string>;
|
|
35
|
+
}
|
|
36
|
+
export interface TangleOpts {
|
|
37
|
+
comments: boolean;
|
|
38
|
+
}
|
|
39
|
+
export interface CodeBlockFormat {
|
|
40
|
+
prefix: string;
|
|
41
|
+
suffix: string;
|
|
42
|
+
}
|
|
43
|
+
export declare const BLOCK_FORMATS: IObjectOf<CodeBlockFormat>;
|
|
44
|
+
export declare const COMMENT_FORMATS: IObjectOf<string | [string, string]>;
|
|
45
|
+
export declare let LOGGER: ILogger;
|
|
46
|
+
export declare const setLogger: (logger: ILogger) => void;
|
|
47
|
+
//# sourceMappingURL=api.d.ts.map
|
package/api.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { LogLevel } from "@thi.ng/logger";
|
|
2
|
+
import { ConsoleLogger } from "@thi.ng/logger/console";
|
|
3
|
+
export const BLOCK_FORMATS = {
|
|
4
|
+
".md": {
|
|
5
|
+
prefix: "```",
|
|
6
|
+
suffix: "```",
|
|
7
|
+
},
|
|
8
|
+
".org": {
|
|
9
|
+
prefix: "#+BEGIN_SRC ",
|
|
10
|
+
suffix: "#+END_SRC",
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
const C = "//";
|
|
14
|
+
const P = "#";
|
|
15
|
+
const L = "--";
|
|
16
|
+
const S = ";;";
|
|
17
|
+
const C89 = ["/*", "*/"];
|
|
18
|
+
const HTML = ["<!--", "-->"];
|
|
19
|
+
export const COMMENT_FORMATS = {
|
|
20
|
+
c: C89,
|
|
21
|
+
clj: S,
|
|
22
|
+
cljs: S,
|
|
23
|
+
cpp: C,
|
|
24
|
+
cs: C,
|
|
25
|
+
css: C89,
|
|
26
|
+
docker: "::",
|
|
27
|
+
elm: L,
|
|
28
|
+
erl: "%",
|
|
29
|
+
fs: "\\",
|
|
30
|
+
go: C,
|
|
31
|
+
h: C,
|
|
32
|
+
html: HTML,
|
|
33
|
+
java: C,
|
|
34
|
+
js: C,
|
|
35
|
+
jsonc: C,
|
|
36
|
+
lua: L,
|
|
37
|
+
md: HTML,
|
|
38
|
+
ml: ["(*", "*)"],
|
|
39
|
+
pde: C,
|
|
40
|
+
py: P,
|
|
41
|
+
rs: C,
|
|
42
|
+
scala: C,
|
|
43
|
+
scm: S,
|
|
44
|
+
sh: P,
|
|
45
|
+
sql: L,
|
|
46
|
+
swift: C,
|
|
47
|
+
tex: "%",
|
|
48
|
+
toml: P,
|
|
49
|
+
ts: C,
|
|
50
|
+
ttl: P,
|
|
51
|
+
wast: S,
|
|
52
|
+
xml: HTML,
|
|
53
|
+
yaml: P,
|
|
54
|
+
zig: C,
|
|
55
|
+
};
|
|
56
|
+
export let LOGGER = new ConsoleLogger("tangle", LogLevel.INFO);
|
|
57
|
+
export const setLogger = (logger) => {
|
|
58
|
+
LOGGER = logger;
|
|
59
|
+
};
|
package/bin/tangle
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
# https://stackoverflow.com/a/246128/294515
|
|
4
|
+
SOURCE="${BASH_SOURCE[0]}"
|
|
5
|
+
while [ -h "$SOURCE" ]; do
|
|
6
|
+
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
|
|
7
|
+
SOURCE="$(readlink "$SOURCE")"
|
|
8
|
+
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
|
|
9
|
+
done
|
|
10
|
+
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
|
|
11
|
+
|
|
12
|
+
/usr/bin/env node "$DIR/../cli.js" "$DIR" "$@"
|
package/cli.d.ts
ADDED
package/cli.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// thing:no-export
|
|
2
|
+
import { flag, parse, ParseError, usage } from "@thi.ng/args";
|
|
3
|
+
import { readJSON, writeText } from "@thi.ng/file-io";
|
|
4
|
+
import { ConsoleLogger } from "@thi.ng/logger";
|
|
5
|
+
import { resolve } from "path";
|
|
6
|
+
import { tangleFile } from "./tangle.js";
|
|
7
|
+
const argOpts = {
|
|
8
|
+
noComments: flag({ default: false, desc: "don't generate comments" }),
|
|
9
|
+
debug: flag({ alias: "d", default: false, desc: "enable debug output" }),
|
|
10
|
+
dryRun: flag({
|
|
11
|
+
default: false,
|
|
12
|
+
desc: "enable dry run (don't overwrite files)",
|
|
13
|
+
}),
|
|
14
|
+
};
|
|
15
|
+
export const INSTALL_DIR = resolve(`${process.argv[2]}/..`);
|
|
16
|
+
export const PKG = readJSON(`${INSTALL_DIR}/package.json`);
|
|
17
|
+
export const APP_NAME = PKG.name.split("/")[1];
|
|
18
|
+
export const HEADER = `
|
|
19
|
+
█ █ █ │
|
|
20
|
+
██ █ │
|
|
21
|
+
█ █ █ █ █ █ █ █ │ ${PKG.name} ${PKG.version}
|
|
22
|
+
█ █ █ █ █ █ █ █ █ │ Literate programming code block tangling
|
|
23
|
+
█ │
|
|
24
|
+
█ █ │
|
|
25
|
+
`;
|
|
26
|
+
const usageOpts = {
|
|
27
|
+
lineWidth: process.stdout.columns,
|
|
28
|
+
prefix: `${HEADER}
|
|
29
|
+
usage: ${APP_NAME} [OPTS] SOURCE-FILES(S) ...
|
|
30
|
+
${APP_NAME} --help
|
|
31
|
+
|
|
32
|
+
`,
|
|
33
|
+
showGroupNames: true,
|
|
34
|
+
paramWidth: 20,
|
|
35
|
+
};
|
|
36
|
+
const showUsage = () => {
|
|
37
|
+
process.stderr.write(usage(argOpts, usageOpts));
|
|
38
|
+
process.exit(1);
|
|
39
|
+
};
|
|
40
|
+
try {
|
|
41
|
+
const result = parse(argOpts, process.argv, { start: 3, usageOpts });
|
|
42
|
+
if (!result)
|
|
43
|
+
process.exit(1);
|
|
44
|
+
const { result: opts, rest } = result;
|
|
45
|
+
if (!rest.length)
|
|
46
|
+
showUsage();
|
|
47
|
+
let ctx = {
|
|
48
|
+
logger: new ConsoleLogger("tangle", opts.debug ? "DEBUG" : "INFO"),
|
|
49
|
+
opts: {
|
|
50
|
+
comments: opts.noComments !== true,
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
for (let file of rest) {
|
|
54
|
+
ctx = tangleFile(file, ctx);
|
|
55
|
+
}
|
|
56
|
+
for (let out in ctx.outputs) {
|
|
57
|
+
writeText(out, ctx.outputs[out], ctx.logger, opts.dryRun);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
catch (e) {
|
|
61
|
+
if (!(e instanceof ParseError))
|
|
62
|
+
process.stderr.write(e.message);
|
|
63
|
+
process.exit(1);
|
|
64
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
(()=>{var Ce=Object.create;var ue=Object.defineProperty;var Pe=Object.getOwnPropertyDescriptor;var Oe=Object.getOwnPropertyNames;var Re=Object.getPrototypeOf,_e=Object.prototype.hasOwnProperty;var Me=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var De=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Oe(e))!_e.call(t,i)&&i!==r&&ue(t,i,{get:()=>e[i],enumerable:!(n=Pe(e,i))||n.enumerable});return t};var Fe=(t,e,r)=>(r=t!=null?Ce(Re(t)):{},De(e||!t||!t.__esModule?ue(r,"default",{value:t,enumerable:!0}):r,t));var pe=Me((de,fe)=>{(function(){var t=function(e){var r=new t.Builder;return r.pipeline.add(t.trimmer,t.stopWordFilter,t.stemmer),r.searchPipeline.add(t.stemmer),e.call(r,r),r.build()};t.version="2.3.9";t.utils={},t.utils.warn=function(e){return function(r){e.console&&console.warn&&console.warn(r)}}(this),t.utils.asString=function(e){return e==null?"":e.toString()},t.utils.clone=function(e){if(e==null)return e;for(var r=Object.create(null),n=Object.keys(e),i=0;i<n.length;i++){var s=n[i],o=e[s];if(Array.isArray(o)){r[s]=o.slice();continue}if(typeof o=="string"||typeof o=="number"||typeof o=="boolean"){r[s]=o;continue}throw new TypeError("clone is not deep and does not support nested objects")}return r},t.FieldRef=function(e,r,n){this.docRef=e,this.fieldName=r,this._stringValue=n},t.FieldRef.joiner="/",t.FieldRef.fromString=function(e){var r=e.indexOf(t.FieldRef.joiner);if(r===-1)throw"malformed field ref string";var n=e.slice(0,r),i=e.slice(r+1);return new t.FieldRef(i,n,e)},t.FieldRef.prototype.toString=function(){return this._stringValue==null&&(this._stringValue=this.fieldName+t.FieldRef.joiner+this.docRef),this._stringValue};t.Set=function(e){if(this.elements=Object.create(null),e){this.length=e.length;for(var r=0;r<this.length;r++)this.elements[e[r]]=!0}else this.length=0},t.Set.complete={intersect:function(e){return e},union:function(){return this},contains:function(){return!0}},t.Set.empty={intersect:function(){return this},union:function(e){return e},contains:function(){return!1}},t.Set.prototype.contains=function(e){return!!this.elements[e]},t.Set.prototype.intersect=function(e){var r,n,i,s=[];if(e===t.Set.complete)return this;if(e===t.Set.empty)return e;this.length<e.length?(r=this,n=e):(r=e,n=this),i=Object.keys(r.elements);for(var o=0;o<i.length;o++){var a=i[o];a in n.elements&&s.push(a)}return new t.Set(s)},t.Set.prototype.union=function(e){return e===t.Set.complete?t.Set.complete:e===t.Set.empty?this:new t.Set(Object.keys(this.elements).concat(Object.keys(e.elements)))},t.idf=function(e,r){var n=0;for(var i in e)i!="_index"&&(n+=Object.keys(e[i]).length);var s=(r-n+.5)/(n+.5);return Math.log(1+Math.abs(s))},t.Token=function(e,r){this.str=e||"",this.metadata=r||{}},t.Token.prototype.toString=function(){return this.str},t.Token.prototype.update=function(e){return this.str=e(this.str,this.metadata),this},t.Token.prototype.clone=function(e){return e=e||function(r){return r},new t.Token(e(this.str,this.metadata),this.metadata)};t.tokenizer=function(e,r){if(e==null||e==null)return[];if(Array.isArray(e))return e.map(function(f){return new t.Token(t.utils.asString(f).toLowerCase(),t.utils.clone(r))});for(var n=e.toString().toLowerCase(),i=n.length,s=[],o=0,a=0;o<=i;o++){var l=n.charAt(o),u=o-a;if(l.match(t.tokenizer.separator)||o==i){if(u>0){var h=t.utils.clone(r)||{};h.position=[a,u],h.index=s.length,s.push(new t.Token(n.slice(a,o),h))}a=o+1}}return s},t.tokenizer.separator=/[\s\-]+/;t.Pipeline=function(){this._stack=[]},t.Pipeline.registeredFunctions=Object.create(null),t.Pipeline.registerFunction=function(e,r){r in this.registeredFunctions&&t.utils.warn("Overwriting existing registered function: "+r),e.label=r,t.Pipeline.registeredFunctions[e.label]=e},t.Pipeline.warnIfFunctionNotRegistered=function(e){var r=e.label&&e.label in this.registeredFunctions;r||t.utils.warn(`Function is not registered with pipeline. This may cause problems when serialising the index.
|
|
2
|
+
`,e)},t.Pipeline.load=function(e){var r=new t.Pipeline;return e.forEach(function(n){var i=t.Pipeline.registeredFunctions[n];if(i)r.add(i);else throw new Error("Cannot load unregistered function: "+n)}),r},t.Pipeline.prototype.add=function(){var e=Array.prototype.slice.call(arguments);e.forEach(function(r){t.Pipeline.warnIfFunctionNotRegistered(r),this._stack.push(r)},this)},t.Pipeline.prototype.after=function(e,r){t.Pipeline.warnIfFunctionNotRegistered(r);var n=this._stack.indexOf(e);if(n==-1)throw new Error("Cannot find existingFn");n=n+1,this._stack.splice(n,0,r)},t.Pipeline.prototype.before=function(e,r){t.Pipeline.warnIfFunctionNotRegistered(r);var n=this._stack.indexOf(e);if(n==-1)throw new Error("Cannot find existingFn");this._stack.splice(n,0,r)},t.Pipeline.prototype.remove=function(e){var r=this._stack.indexOf(e);r!=-1&&this._stack.splice(r,1)},t.Pipeline.prototype.run=function(e){for(var r=this._stack.length,n=0;n<r;n++){for(var i=this._stack[n],s=[],o=0;o<e.length;o++){var a=i(e[o],o,e);if(!(a==null||a===""))if(Array.isArray(a))for(var l=0;l<a.length;l++)s.push(a[l]);else s.push(a)}e=s}return e},t.Pipeline.prototype.runString=function(e,r){var n=new t.Token(e,r);return this.run([n]).map(function(i){return i.toString()})},t.Pipeline.prototype.reset=function(){this._stack=[]},t.Pipeline.prototype.toJSON=function(){return this._stack.map(function(e){return t.Pipeline.warnIfFunctionNotRegistered(e),e.label})};t.Vector=function(e){this._magnitude=0,this.elements=e||[]},t.Vector.prototype.positionForIndex=function(e){if(this.elements.length==0)return 0;for(var r=0,n=this.elements.length/2,i=n-r,s=Math.floor(i/2),o=this.elements[s*2];i>1&&(o<e&&(r=s),o>e&&(n=s),o!=e);)i=n-r,s=r+Math.floor(i/2),o=this.elements[s*2];if(o==e||o>e)return s*2;if(o<e)return(s+1)*2},t.Vector.prototype.insert=function(e,r){this.upsert(e,r,function(){throw"duplicate index"})},t.Vector.prototype.upsert=function(e,r,n){this._magnitude=0;var i=this.positionForIndex(e);this.elements[i]==e?this.elements[i+1]=n(this.elements[i+1],r):this.elements.splice(i,0,e,r)},t.Vector.prototype.magnitude=function(){if(this._magnitude)return this._magnitude;for(var e=0,r=this.elements.length,n=1;n<r;n+=2){var i=this.elements[n];e+=i*i}return this._magnitude=Math.sqrt(e)},t.Vector.prototype.dot=function(e){for(var r=0,n=this.elements,i=e.elements,s=n.length,o=i.length,a=0,l=0,u=0,h=0;u<s&&h<o;)a=n[u],l=i[h],a<l?u+=2:a>l?h+=2:a==l&&(r+=n[u+1]*i[h+1],u+=2,h+=2);return r},t.Vector.prototype.similarity=function(e){return this.dot(e)/this.magnitude()||0},t.Vector.prototype.toArray=function(){for(var e=new Array(this.elements.length/2),r=1,n=0;r<this.elements.length;r+=2,n++)e[n]=this.elements[r];return e},t.Vector.prototype.toJSON=function(){return this.elements};t.stemmer=function(){var e={ational:"ate",tional:"tion",enci:"ence",anci:"ance",izer:"ize",bli:"ble",alli:"al",entli:"ent",eli:"e",ousli:"ous",ization:"ize",ation:"ate",ator:"ate",alism:"al",iveness:"ive",fulness:"ful",ousness:"ous",aliti:"al",iviti:"ive",biliti:"ble",logi:"log"},r={icate:"ic",ative:"",alize:"al",iciti:"ic",ical:"ic",ful:"",ness:""},n="[^aeiou]",i="[aeiouy]",s=n+"[^aeiouy]*",o=i+"[aeiou]*",a="^("+s+")?"+o+s,l="^("+s+")?"+o+s+"("+o+")?$",u="^("+s+")?"+o+s+o+s,h="^("+s+")?"+i,f=new RegExp(a),p=new RegExp(u),E=new RegExp(l),y=new RegExp(h),b=/^(.+?)(ss|i)es$/,m=/^(.+?)([^s])s$/,v=/^(.+?)eed$/,T=/^(.+?)(ed|ing)$/,w=/.$/,I=/(at|bl|iz)$/,M=new RegExp("([^aeiouylsz])\\1$"),B=new RegExp("^"+s+i+"[^aeiouwxy]$"),V=/^(.+?[^aeiou])y$/,q=/^(.+?)(ational|tional|enci|anci|izer|bli|alli|entli|eli|ousli|ization|ation|ator|alism|iveness|fulness|ousness|aliti|iviti|biliti|logi)$/,$=/^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/,H=/^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/,W=/^(.+?)(s|t)(ion)$/,P=/^(.+?)e$/,U=/ll$/,G=new RegExp("^"+s+i+"[^aeiouwxy]$"),z=function(c){var g,O,S,d,x,R,F;if(c.length<3)return c;if(S=c.substr(0,1),S=="y"&&(c=S.toUpperCase()+c.substr(1)),d=b,x=m,d.test(c)?c=c.replace(d,"$1$2"):x.test(c)&&(c=c.replace(x,"$1$2")),d=v,x=T,d.test(c)){var L=d.exec(c);d=f,d.test(L[1])&&(d=w,c=c.replace(d,""))}else if(x.test(c)){var L=x.exec(c);g=L[1],x=y,x.test(g)&&(c=g,x=I,R=M,F=B,x.test(c)?c=c+"e":R.test(c)?(d=w,c=c.replace(d,"")):F.test(c)&&(c=c+"e"))}if(d=V,d.test(c)){var L=d.exec(c);g=L[1],c=g+"i"}if(d=q,d.test(c)){var L=d.exec(c);g=L[1],O=L[2],d=f,d.test(g)&&(c=g+e[O])}if(d=$,d.test(c)){var L=d.exec(c);g=L[1],O=L[2],d=f,d.test(g)&&(c=g+r[O])}if(d=H,x=W,d.test(c)){var L=d.exec(c);g=L[1],d=p,d.test(g)&&(c=g)}else if(x.test(c)){var L=x.exec(c);g=L[1]+L[2],x=p,x.test(g)&&(c=g)}if(d=P,d.test(c)){var L=d.exec(c);g=L[1],d=p,x=E,R=G,(d.test(g)||x.test(g)&&!R.test(g))&&(c=g)}return d=U,x=p,d.test(c)&&x.test(c)&&(d=w,c=c.replace(d,"")),S=="y"&&(c=S.toLowerCase()+c.substr(1)),c};return function(D){return D.update(z)}}(),t.Pipeline.registerFunction(t.stemmer,"stemmer");t.generateStopWordFilter=function(e){var r=e.reduce(function(n,i){return n[i]=i,n},{});return function(n){if(n&&r[n.toString()]!==n.toString())return n}},t.stopWordFilter=t.generateStopWordFilter(["a","able","about","across","after","all","almost","also","am","among","an","and","any","are","as","at","be","because","been","but","by","can","cannot","could","dear","did","do","does","either","else","ever","every","for","from","get","got","had","has","have","he","her","hers","him","his","how","however","i","if","in","into","is","it","its","just","least","let","like","likely","may","me","might","most","must","my","neither","no","nor","not","of","off","often","on","only","or","other","our","own","rather","said","say","says","she","should","since","so","some","than","that","the","their","them","then","there","these","they","this","tis","to","too","twas","us","wants","was","we","were","what","when","where","which","while","who","whom","why","will","with","would","yet","you","your"]),t.Pipeline.registerFunction(t.stopWordFilter,"stopWordFilter");t.trimmer=function(e){return e.update(function(r){return r.replace(/^\W+/,"").replace(/\W+$/,"")})},t.Pipeline.registerFunction(t.trimmer,"trimmer");t.TokenSet=function(){this.final=!1,this.edges={},this.id=t.TokenSet._nextId,t.TokenSet._nextId+=1},t.TokenSet._nextId=1,t.TokenSet.fromArray=function(e){for(var r=new t.TokenSet.Builder,n=0,i=e.length;n<i;n++)r.insert(e[n]);return r.finish(),r.root},t.TokenSet.fromClause=function(e){return"editDistance"in e?t.TokenSet.fromFuzzyString(e.term,e.editDistance):t.TokenSet.fromString(e.term)},t.TokenSet.fromFuzzyString=function(e,r){for(var n=new t.TokenSet,i=[{node:n,editsRemaining:r,str:e}];i.length;){var s=i.pop();if(s.str.length>0){var o=s.str.charAt(0),a;o in s.node.edges?a=s.node.edges[o]:(a=new t.TokenSet,s.node.edges[o]=a),s.str.length==1&&(a.final=!0),i.push({node:a,editsRemaining:s.editsRemaining,str:s.str.slice(1)})}if(s.editsRemaining!=0){if("*"in s.node.edges)var l=s.node.edges["*"];else{var l=new t.TokenSet;s.node.edges["*"]=l}if(s.str.length==0&&(l.final=!0),i.push({node:l,editsRemaining:s.editsRemaining-1,str:s.str}),s.str.length>1&&i.push({node:s.node,editsRemaining:s.editsRemaining-1,str:s.str.slice(1)}),s.str.length==1&&(s.node.final=!0),s.str.length>=1){if("*"in s.node.edges)var u=s.node.edges["*"];else{var u=new t.TokenSet;s.node.edges["*"]=u}s.str.length==1&&(u.final=!0),i.push({node:u,editsRemaining:s.editsRemaining-1,str:s.str.slice(1)})}if(s.str.length>1){var h=s.str.charAt(0),f=s.str.charAt(1),p;f in s.node.edges?p=s.node.edges[f]:(p=new t.TokenSet,s.node.edges[f]=p),s.str.length==1&&(p.final=!0),i.push({node:p,editsRemaining:s.editsRemaining-1,str:h+s.str.slice(2)})}}}return n},t.TokenSet.fromString=function(e){for(var r=new t.TokenSet,n=r,i=0,s=e.length;i<s;i++){var o=e[i],a=i==s-1;if(o=="*")r.edges[o]=r,r.final=a;else{var l=new t.TokenSet;l.final=a,r.edges[o]=l,r=l}}return n},t.TokenSet.prototype.toArray=function(){for(var e=[],r=[{prefix:"",node:this}];r.length;){var n=r.pop(),i=Object.keys(n.node.edges),s=i.length;n.node.final&&(n.prefix.charAt(0),e.push(n.prefix));for(var o=0;o<s;o++){var a=i[o];r.push({prefix:n.prefix.concat(a),node:n.node.edges[a]})}}return e},t.TokenSet.prototype.toString=function(){if(this._str)return this._str;for(var e=this.final?"1":"0",r=Object.keys(this.edges).sort(),n=r.length,i=0;i<n;i++){var s=r[i],o=this.edges[s];e=e+s+o.id}return e},t.TokenSet.prototype.intersect=function(e){for(var r=new t.TokenSet,n=void 0,i=[{qNode:e,output:r,node:this}];i.length;){n=i.pop();for(var s=Object.keys(n.qNode.edges),o=s.length,a=Object.keys(n.node.edges),l=a.length,u=0;u<o;u++)for(var h=s[u],f=0;f<l;f++){var p=a[f];if(p==h||h=="*"){var E=n.node.edges[p],y=n.qNode.edges[h],b=E.final&&y.final,m=void 0;p in n.output.edges?(m=n.output.edges[p],m.final=m.final||b):(m=new t.TokenSet,m.final=b,n.output.edges[p]=m),i.push({qNode:y,output:m,node:E})}}}return r},t.TokenSet.Builder=function(){this.previousWord="",this.root=new t.TokenSet,this.uncheckedNodes=[],this.minimizedNodes={}},t.TokenSet.Builder.prototype.insert=function(e){var r,n=0;if(e<this.previousWord)throw new Error("Out of order word insertion");for(var i=0;i<e.length&&i<this.previousWord.length&&e[i]==this.previousWord[i];i++)n++;this.minimize(n),this.uncheckedNodes.length==0?r=this.root:r=this.uncheckedNodes[this.uncheckedNodes.length-1].child;for(var i=n;i<e.length;i++){var s=new t.TokenSet,o=e[i];r.edges[o]=s,this.uncheckedNodes.push({parent:r,char:o,child:s}),r=s}r.final=!0,this.previousWord=e},t.TokenSet.Builder.prototype.finish=function(){this.minimize(0)},t.TokenSet.Builder.prototype.minimize=function(e){for(var r=this.uncheckedNodes.length-1;r>=e;r--){var n=this.uncheckedNodes[r],i=n.child.toString();i in this.minimizedNodes?n.parent.edges[n.char]=this.minimizedNodes[i]:(n.child._str=i,this.minimizedNodes[i]=n.child),this.uncheckedNodes.pop()}};t.Index=function(e){this.invertedIndex=e.invertedIndex,this.fieldVectors=e.fieldVectors,this.tokenSet=e.tokenSet,this.fields=e.fields,this.pipeline=e.pipeline},t.Index.prototype.search=function(e){return this.query(function(r){var n=new t.QueryParser(e,r);n.parse()})},t.Index.prototype.query=function(e){for(var r=new t.Query(this.fields),n=Object.create(null),i=Object.create(null),s=Object.create(null),o=Object.create(null),a=Object.create(null),l=0;l<this.fields.length;l++)i[this.fields[l]]=new t.Vector;e.call(r,r);for(var l=0;l<r.clauses.length;l++){var u=r.clauses[l],h=null,f=t.Set.empty;u.usePipeline?h=this.pipeline.runString(u.term,{fields:u.fields}):h=[u.term];for(var p=0;p<h.length;p++){var E=h[p];u.term=E;var y=t.TokenSet.fromClause(u),b=this.tokenSet.intersect(y).toArray();if(b.length===0&&u.presence===t.Query.presence.REQUIRED){for(var m=0;m<u.fields.length;m++){var v=u.fields[m];o[v]=t.Set.empty}break}for(var T=0;T<b.length;T++)for(var w=b[T],I=this.invertedIndex[w],M=I._index,m=0;m<u.fields.length;m++){var v=u.fields[m],B=I[v],V=Object.keys(B),q=w+"/"+v,$=new t.Set(V);if(u.presence==t.Query.presence.REQUIRED&&(f=f.union($),o[v]===void 0&&(o[v]=t.Set.complete)),u.presence==t.Query.presence.PROHIBITED){a[v]===void 0&&(a[v]=t.Set.empty),a[v]=a[v].union($);continue}if(i[v].upsert(M,u.boost,function(Qe,Ie){return Qe+Ie}),!s[q]){for(var H=0;H<V.length;H++){var W=V[H],P=new t.FieldRef(W,v),U=B[W],G;(G=n[P])===void 0?n[P]=new t.MatchData(w,v,U):G.add(w,v,U)}s[q]=!0}}}if(u.presence===t.Query.presence.REQUIRED)for(var m=0;m<u.fields.length;m++){var v=u.fields[m];o[v]=o[v].intersect(f)}}for(var z=t.Set.complete,D=t.Set.empty,l=0;l<this.fields.length;l++){var v=this.fields[l];o[v]&&(z=z.intersect(o[v])),a[v]&&(D=D.union(a[v]))}var c=Object.keys(n),g=[],O=Object.create(null);if(r.isNegated()){c=Object.keys(this.fieldVectors);for(var l=0;l<c.length;l++){var P=c[l],S=t.FieldRef.fromString(P);n[P]=new t.MatchData}}for(var l=0;l<c.length;l++){var S=t.FieldRef.fromString(c[l]),d=S.docRef;if(!!z.contains(d)&&!D.contains(d)){var x=this.fieldVectors[S],R=i[S.fieldName].similarity(x),F;if((F=O[d])!==void 0)F.score+=R,F.matchData.combine(n[S]);else{var L={ref:d,score:R,matchData:n[S]};O[d]=L,g.push(L)}}}return g.sort(function(Se,ke){return ke.score-Se.score})},t.Index.prototype.toJSON=function(){var e=Object.keys(this.invertedIndex).sort().map(function(n){return[n,this.invertedIndex[n]]},this),r=Object.keys(this.fieldVectors).map(function(n){return[n,this.fieldVectors[n].toJSON()]},this);return{version:t.version,fields:this.fields,fieldVectors:r,invertedIndex:e,pipeline:this.pipeline.toJSON()}},t.Index.load=function(e){var r={},n={},i=e.fieldVectors,s=Object.create(null),o=e.invertedIndex,a=new t.TokenSet.Builder,l=t.Pipeline.load(e.pipeline);e.version!=t.version&&t.utils.warn("Version mismatch when loading serialised index. Current version of lunr '"+t.version+"' does not match serialized index '"+e.version+"'");for(var u=0;u<i.length;u++){var h=i[u],f=h[0],p=h[1];n[f]=new t.Vector(p)}for(var u=0;u<o.length;u++){var h=o[u],E=h[0],y=h[1];a.insert(E),s[E]=y}return a.finish(),r.fields=e.fields,r.fieldVectors=n,r.invertedIndex=s,r.tokenSet=a.root,r.pipeline=l,new t.Index(r)};t.Builder=function(){this._ref="id",this._fields=Object.create(null),this._documents=Object.create(null),this.invertedIndex=Object.create(null),this.fieldTermFrequencies={},this.fieldLengths={},this.tokenizer=t.tokenizer,this.pipeline=new t.Pipeline,this.searchPipeline=new t.Pipeline,this.documentCount=0,this._b=.75,this._k1=1.2,this.termIndex=0,this.metadataWhitelist=[]},t.Builder.prototype.ref=function(e){this._ref=e},t.Builder.prototype.field=function(e,r){if(/\//.test(e))throw new RangeError("Field '"+e+"' contains illegal character '/'");this._fields[e]=r||{}},t.Builder.prototype.b=function(e){e<0?this._b=0:e>1?this._b=1:this._b=e},t.Builder.prototype.k1=function(e){this._k1=e},t.Builder.prototype.add=function(e,r){var n=e[this._ref],i=Object.keys(this._fields);this._documents[n]=r||{},this.documentCount+=1;for(var s=0;s<i.length;s++){var o=i[s],a=this._fields[o].extractor,l=a?a(e):e[o],u=this.tokenizer(l,{fields:[o]}),h=this.pipeline.run(u),f=new t.FieldRef(n,o),p=Object.create(null);this.fieldTermFrequencies[f]=p,this.fieldLengths[f]=0,this.fieldLengths[f]+=h.length;for(var E=0;E<h.length;E++){var y=h[E];if(p[y]==null&&(p[y]=0),p[y]+=1,this.invertedIndex[y]==null){var b=Object.create(null);b._index=this.termIndex,this.termIndex+=1;for(var m=0;m<i.length;m++)b[i[m]]=Object.create(null);this.invertedIndex[y]=b}this.invertedIndex[y][o][n]==null&&(this.invertedIndex[y][o][n]=Object.create(null));for(var v=0;v<this.metadataWhitelist.length;v++){var T=this.metadataWhitelist[v],w=y.metadata[T];this.invertedIndex[y][o][n][T]==null&&(this.invertedIndex[y][o][n][T]=[]),this.invertedIndex[y][o][n][T].push(w)}}}},t.Builder.prototype.calculateAverageFieldLengths=function(){for(var e=Object.keys(this.fieldLengths),r=e.length,n={},i={},s=0;s<r;s++){var o=t.FieldRef.fromString(e[s]),a=o.fieldName;i[a]||(i[a]=0),i[a]+=1,n[a]||(n[a]=0),n[a]+=this.fieldLengths[o]}for(var l=Object.keys(this._fields),s=0;s<l.length;s++){var u=l[s];n[u]=n[u]/i[u]}this.averageFieldLength=n},t.Builder.prototype.createFieldVectors=function(){for(var e={},r=Object.keys(this.fieldTermFrequencies),n=r.length,i=Object.create(null),s=0;s<n;s++){for(var o=t.FieldRef.fromString(r[s]),a=o.fieldName,l=this.fieldLengths[o],u=new t.Vector,h=this.fieldTermFrequencies[o],f=Object.keys(h),p=f.length,E=this._fields[a].boost||1,y=this._documents[o.docRef].boost||1,b=0;b<p;b++){var m=f[b],v=h[m],T=this.invertedIndex[m]._index,w,I,M;i[m]===void 0?(w=t.idf(this.invertedIndex[m],this.documentCount),i[m]=w):w=i[m],I=w*((this._k1+1)*v)/(this._k1*(1-this._b+this._b*(l/this.averageFieldLength[a]))+v),I*=E,I*=y,M=Math.round(I*1e3)/1e3,u.insert(T,M)}e[o]=u}this.fieldVectors=e},t.Builder.prototype.createTokenSet=function(){this.tokenSet=t.TokenSet.fromArray(Object.keys(this.invertedIndex).sort())},t.Builder.prototype.build=function(){return this.calculateAverageFieldLengths(),this.createFieldVectors(),this.createTokenSet(),new t.Index({invertedIndex:this.invertedIndex,fieldVectors:this.fieldVectors,tokenSet:this.tokenSet,fields:Object.keys(this._fields),pipeline:this.searchPipeline})},t.Builder.prototype.use=function(e){var r=Array.prototype.slice.call(arguments,1);r.unshift(this),e.apply(this,r)},t.MatchData=function(e,r,n){for(var i=Object.create(null),s=Object.keys(n||{}),o=0;o<s.length;o++){var a=s[o];i[a]=n[a].slice()}this.metadata=Object.create(null),e!==void 0&&(this.metadata[e]=Object.create(null),this.metadata[e][r]=i)},t.MatchData.prototype.combine=function(e){for(var r=Object.keys(e.metadata),n=0;n<r.length;n++){var i=r[n],s=Object.keys(e.metadata[i]);this.metadata[i]==null&&(this.metadata[i]=Object.create(null));for(var o=0;o<s.length;o++){var a=s[o],l=Object.keys(e.metadata[i][a]);this.metadata[i][a]==null&&(this.metadata[i][a]=Object.create(null));for(var u=0;u<l.length;u++){var h=l[u];this.metadata[i][a][h]==null?this.metadata[i][a][h]=e.metadata[i][a][h]:this.metadata[i][a][h]=this.metadata[i][a][h].concat(e.metadata[i][a][h])}}}},t.MatchData.prototype.add=function(e,r,n){if(!(e in this.metadata)){this.metadata[e]=Object.create(null),this.metadata[e][r]=n;return}if(!(r in this.metadata[e])){this.metadata[e][r]=n;return}for(var i=Object.keys(n),s=0;s<i.length;s++){var o=i[s];o in this.metadata[e][r]?this.metadata[e][r][o]=this.metadata[e][r][o].concat(n[o]):this.metadata[e][r][o]=n[o]}},t.Query=function(e){this.clauses=[],this.allFields=e},t.Query.wildcard=new String("*"),t.Query.wildcard.NONE=0,t.Query.wildcard.LEADING=1,t.Query.wildcard.TRAILING=2,t.Query.presence={OPTIONAL:1,REQUIRED:2,PROHIBITED:3},t.Query.prototype.clause=function(e){return"fields"in e||(e.fields=this.allFields),"boost"in e||(e.boost=1),"usePipeline"in e||(e.usePipeline=!0),"wildcard"in e||(e.wildcard=t.Query.wildcard.NONE),e.wildcard&t.Query.wildcard.LEADING&&e.term.charAt(0)!=t.Query.wildcard&&(e.term="*"+e.term),e.wildcard&t.Query.wildcard.TRAILING&&e.term.slice(-1)!=t.Query.wildcard&&(e.term=""+e.term+"*"),"presence"in e||(e.presence=t.Query.presence.OPTIONAL),this.clauses.push(e),this},t.Query.prototype.isNegated=function(){for(var e=0;e<this.clauses.length;e++)if(this.clauses[e].presence!=t.Query.presence.PROHIBITED)return!1;return!0},t.Query.prototype.term=function(e,r){if(Array.isArray(e))return e.forEach(function(i){this.term(i,t.utils.clone(r))},this),this;var n=r||{};return n.term=e.toString(),this.clause(n),this},t.QueryParseError=function(e,r,n){this.name="QueryParseError",this.message=e,this.start=r,this.end=n},t.QueryParseError.prototype=new Error,t.QueryLexer=function(e){this.lexemes=[],this.str=e,this.length=e.length,this.pos=0,this.start=0,this.escapeCharPositions=[]},t.QueryLexer.prototype.run=function(){for(var e=t.QueryLexer.lexText;e;)e=e(this)},t.QueryLexer.prototype.sliceString=function(){for(var e=[],r=this.start,n=this.pos,i=0;i<this.escapeCharPositions.length;i++)n=this.escapeCharPositions[i],e.push(this.str.slice(r,n)),r=n+1;return e.push(this.str.slice(r,this.pos)),this.escapeCharPositions.length=0,e.join("")},t.QueryLexer.prototype.emit=function(e){this.lexemes.push({type:e,str:this.sliceString(),start:this.start,end:this.pos}),this.start=this.pos},t.QueryLexer.prototype.escapeCharacter=function(){this.escapeCharPositions.push(this.pos-1),this.pos+=1},t.QueryLexer.prototype.next=function(){if(this.pos>=this.length)return t.QueryLexer.EOS;var e=this.str.charAt(this.pos);return this.pos+=1,e},t.QueryLexer.prototype.width=function(){return this.pos-this.start},t.QueryLexer.prototype.ignore=function(){this.start==this.pos&&(this.pos+=1),this.start=this.pos},t.QueryLexer.prototype.backup=function(){this.pos-=1},t.QueryLexer.prototype.acceptDigitRun=function(){var e,r;do e=this.next(),r=e.charCodeAt(0);while(r>47&&r<58);e!=t.QueryLexer.EOS&&this.backup()},t.QueryLexer.prototype.more=function(){return this.pos<this.length},t.QueryLexer.EOS="EOS",t.QueryLexer.FIELD="FIELD",t.QueryLexer.TERM="TERM",t.QueryLexer.EDIT_DISTANCE="EDIT_DISTANCE",t.QueryLexer.BOOST="BOOST",t.QueryLexer.PRESENCE="PRESENCE",t.QueryLexer.lexField=function(e){return e.backup(),e.emit(t.QueryLexer.FIELD),e.ignore(),t.QueryLexer.lexText},t.QueryLexer.lexTerm=function(e){if(e.width()>1&&(e.backup(),e.emit(t.QueryLexer.TERM)),e.ignore(),e.more())return t.QueryLexer.lexText},t.QueryLexer.lexEditDistance=function(e){return e.ignore(),e.acceptDigitRun(),e.emit(t.QueryLexer.EDIT_DISTANCE),t.QueryLexer.lexText},t.QueryLexer.lexBoost=function(e){return e.ignore(),e.acceptDigitRun(),e.emit(t.QueryLexer.BOOST),t.QueryLexer.lexText},t.QueryLexer.lexEOS=function(e){e.width()>0&&e.emit(t.QueryLexer.TERM)},t.QueryLexer.termSeparator=t.tokenizer.separator,t.QueryLexer.lexText=function(e){for(;;){var r=e.next();if(r==t.QueryLexer.EOS)return t.QueryLexer.lexEOS;if(r.charCodeAt(0)==92){e.escapeCharacter();continue}if(r==":")return t.QueryLexer.lexField;if(r=="~")return e.backup(),e.width()>0&&e.emit(t.QueryLexer.TERM),t.QueryLexer.lexEditDistance;if(r=="^")return e.backup(),e.width()>0&&e.emit(t.QueryLexer.TERM),t.QueryLexer.lexBoost;if(r=="+"&&e.width()===1||r=="-"&&e.width()===1)return e.emit(t.QueryLexer.PRESENCE),t.QueryLexer.lexText;if(r.match(t.QueryLexer.termSeparator))return t.QueryLexer.lexTerm}},t.QueryParser=function(e,r){this.lexer=new t.QueryLexer(e),this.query=r,this.currentClause={},this.lexemeIdx=0},t.QueryParser.prototype.parse=function(){this.lexer.run(),this.lexemes=this.lexer.lexemes;for(var e=t.QueryParser.parseClause;e;)e=e(this);return this.query},t.QueryParser.prototype.peekLexeme=function(){return this.lexemes[this.lexemeIdx]},t.QueryParser.prototype.consumeLexeme=function(){var e=this.peekLexeme();return this.lexemeIdx+=1,e},t.QueryParser.prototype.nextClause=function(){var e=this.currentClause;this.query.clause(e),this.currentClause={}},t.QueryParser.parseClause=function(e){var r=e.peekLexeme();if(r!=null)switch(r.type){case t.QueryLexer.PRESENCE:return t.QueryParser.parsePresence;case t.QueryLexer.FIELD:return t.QueryParser.parseField;case t.QueryLexer.TERM:return t.QueryParser.parseTerm;default:var n="expected either a field or a term, found "+r.type;throw r.str.length>=1&&(n+=" with value '"+r.str+"'"),new t.QueryParseError(n,r.start,r.end)}},t.QueryParser.parsePresence=function(e){var r=e.consumeLexeme();if(r!=null){switch(r.str){case"-":e.currentClause.presence=t.Query.presence.PROHIBITED;break;case"+":e.currentClause.presence=t.Query.presence.REQUIRED;break;default:var n="unrecognised presence operator'"+r.str+"'";throw new t.QueryParseError(n,r.start,r.end)}var i=e.peekLexeme();if(i==null){var n="expecting term or field, found nothing";throw new t.QueryParseError(n,r.start,r.end)}switch(i.type){case t.QueryLexer.FIELD:return t.QueryParser.parseField;case t.QueryLexer.TERM:return t.QueryParser.parseTerm;default:var n="expecting term or field, found '"+i.type+"'";throw new t.QueryParseError(n,i.start,i.end)}}},t.QueryParser.parseField=function(e){var r=e.consumeLexeme();if(r!=null){if(e.query.allFields.indexOf(r.str)==-1){var n=e.query.allFields.map(function(o){return"'"+o+"'"}).join(", "),i="unrecognised field '"+r.str+"', possible fields: "+n;throw new t.QueryParseError(i,r.start,r.end)}e.currentClause.fields=[r.str];var s=e.peekLexeme();if(s==null){var i="expecting term, found nothing";throw new t.QueryParseError(i,r.start,r.end)}switch(s.type){case t.QueryLexer.TERM:return t.QueryParser.parseTerm;default:var i="expecting term, found '"+s.type+"'";throw new t.QueryParseError(i,s.start,s.end)}}},t.QueryParser.parseTerm=function(e){var r=e.consumeLexeme();if(r!=null){e.currentClause.term=r.str.toLowerCase(),r.str.indexOf("*")!=-1&&(e.currentClause.usePipeline=!1);var n=e.peekLexeme();if(n==null){e.nextClause();return}switch(n.type){case t.QueryLexer.TERM:return e.nextClause(),t.QueryParser.parseTerm;case t.QueryLexer.FIELD:return e.nextClause(),t.QueryParser.parseField;case t.QueryLexer.EDIT_DISTANCE:return t.QueryParser.parseEditDistance;case t.QueryLexer.BOOST:return t.QueryParser.parseBoost;case t.QueryLexer.PRESENCE:return e.nextClause(),t.QueryParser.parsePresence;default:var i="Unexpected lexeme type '"+n.type+"'";throw new t.QueryParseError(i,n.start,n.end)}}},t.QueryParser.parseEditDistance=function(e){var r=e.consumeLexeme();if(r!=null){var n=parseInt(r.str,10);if(isNaN(n)){var i="edit distance must be numeric";throw new t.QueryParseError(i,r.start,r.end)}e.currentClause.editDistance=n;var s=e.peekLexeme();if(s==null){e.nextClause();return}switch(s.type){case t.QueryLexer.TERM:return e.nextClause(),t.QueryParser.parseTerm;case t.QueryLexer.FIELD:return e.nextClause(),t.QueryParser.parseField;case t.QueryLexer.EDIT_DISTANCE:return t.QueryParser.parseEditDistance;case t.QueryLexer.BOOST:return t.QueryParser.parseBoost;case t.QueryLexer.PRESENCE:return e.nextClause(),t.QueryParser.parsePresence;default:var i="Unexpected lexeme type '"+s.type+"'";throw new t.QueryParseError(i,s.start,s.end)}}},t.QueryParser.parseBoost=function(e){var r=e.consumeLexeme();if(r!=null){var n=parseInt(r.str,10);if(isNaN(n)){var i="boost must be numeric";throw new t.QueryParseError(i,r.start,r.end)}e.currentClause.boost=n;var s=e.peekLexeme();if(s==null){e.nextClause();return}switch(s.type){case t.QueryLexer.TERM:return e.nextClause(),t.QueryParser.parseTerm;case t.QueryLexer.FIELD:return e.nextClause(),t.QueryParser.parseField;case t.QueryLexer.EDIT_DISTANCE:return t.QueryParser.parseEditDistance;case t.QueryLexer.BOOST:return t.QueryParser.parseBoost;case t.QueryLexer.PRESENCE:return e.nextClause(),t.QueryParser.parsePresence;default:var i="Unexpected lexeme type '"+s.type+"'";throw new t.QueryParseError(i,s.start,s.end)}}},function(e,r){typeof define=="function"&&define.amd?define(r):typeof de=="object"?fe.exports=r():e.lunr=r()}(this,function(){return t})})()});var ce=[];function N(t,e){ce.push({selector:e,constructor:t})}var Y=class{constructor(){this.createComponents(document.body)}createComponents(e){ce.forEach(r=>{e.querySelectorAll(r.selector).forEach(n=>{n.dataset.hasInstance||(new r.constructor({el:n}),n.dataset.hasInstance=String(!0))})})}};var k=class{constructor(e){this.el=e.el}};var J=class{constructor(){this.listeners={}}addEventListener(e,r){e in this.listeners||(this.listeners[e]=[]),this.listeners[e].push(r)}removeEventListener(e,r){if(!(e in this.listeners))return;let n=this.listeners[e];for(let i=0,s=n.length;i<s;i++)if(n[i]===r){n.splice(i,1);return}}dispatchEvent(e){if(!(e.type in this.listeners))return!0;let r=this.listeners[e.type].slice();for(let n=0,i=r.length;n<i;n++)r[n].call(this,e);return!e.defaultPrevented}};var ne=(t,e=100)=>{let r=Date.now();return(...n)=>{r+e-Date.now()<0&&(t(...n),r=Date.now())}};var ie=class extends J{constructor(){super();this.scrollTop=0;this.lastY=0;this.width=0;this.height=0;this.showToolbar=!0;this.toolbar=document.querySelector(".tsd-page-toolbar"),this.secondaryNav=document.querySelector(".tsd-navigation.secondary"),window.addEventListener("scroll",ne(()=>this.onScroll(),10)),window.addEventListener("resize",ne(()=>this.onResize(),10)),this.onResize(),this.onScroll()}triggerResize(){let r=new CustomEvent("resize",{detail:{width:this.width,height:this.height}});this.dispatchEvent(r)}onResize(){this.width=window.innerWidth||0,this.height=window.innerHeight||0;let r=new CustomEvent("resize",{detail:{width:this.width,height:this.height}});this.dispatchEvent(r)}onScroll(){this.scrollTop=window.scrollY||0;let r=new CustomEvent("scroll",{detail:{scrollTop:this.scrollTop}});this.dispatchEvent(r),this.hideShowToolbar()}hideShowToolbar(){var n;let r=this.showToolbar;this.showToolbar=this.lastY>=this.scrollTop||this.scrollTop<=0,r!==this.showToolbar&&(this.toolbar.classList.toggle("tsd-page-toolbar--hide"),(n=this.secondaryNav)==null||n.classList.toggle("tsd-navigation--toolbar-hide")),this.lastY=this.scrollTop}},Q=ie;Q.instance=new ie;var X=class extends k{constructor(r){super(r);this.anchors=[];this.index=-1;Q.instance.addEventListener("resize",()=>this.onResize()),Q.instance.addEventListener("scroll",n=>this.onScroll(n)),this.createAnchors()}createAnchors(){let r=window.location.href;r.indexOf("#")!=-1&&(r=r.substr(0,r.indexOf("#"))),this.el.querySelectorAll("a").forEach(n=>{let i=n.href;if(i.indexOf("#")==-1||i.substr(0,r.length)!=r)return;let s=i.substr(i.indexOf("#")+1),o=document.querySelector("a.tsd-anchor[name="+s+"]"),a=n.parentNode;!o||!a||this.anchors.push({link:a,anchor:o,position:0})}),this.onResize()}onResize(){let r;for(let i=0,s=this.anchors.length;i<s;i++){r=this.anchors[i];let o=r.anchor.getBoundingClientRect();r.position=o.top+document.body.scrollTop}this.anchors.sort((i,s)=>i.position-s.position);let n=new CustomEvent("scroll",{detail:{scrollTop:Q.instance.scrollTop}});this.onScroll(n)}onScroll(r){let n=r.detail.scrollTop+5,i=this.anchors,s=i.length-1,o=this.index;for(;o>-1&&i[o].position>n;)o-=1;for(;o<s&&i[o+1].position<n;)o+=1;this.index!=o&&(this.index>-1&&this.anchors[this.index].link.classList.remove("focus"),this.index=o,this.index>-1&&this.anchors[this.index].link.classList.add("focus"))}};var he=(t,e=100)=>{let r;return(...n)=>{clearTimeout(r),r=setTimeout(()=>t(n),e)}};var ge=Fe(pe());function ye(){let t=document.getElementById("tsd-search");if(!t)return;let e=document.getElementById("search-script");t.classList.add("loading"),e&&(e.addEventListener("error",()=>{t.classList.remove("loading"),t.classList.add("failure")}),e.addEventListener("load",()=>{t.classList.remove("loading"),t.classList.add("ready")}),window.searchData&&t.classList.remove("loading"));let r=document.querySelector("#tsd-search input"),n=document.querySelector("#tsd-search .results");if(!r||!n)throw new Error("The input field or the result list wrapper was not found");let i=!1;n.addEventListener("mousedown",()=>i=!0),n.addEventListener("mouseup",()=>{i=!1,t.classList.remove("has-focus")}),r.addEventListener("focus",()=>t.classList.add("has-focus")),r.addEventListener("blur",()=>{i||(i=!1,t.classList.remove("has-focus"))});let s={base:t.dataset.base+"/"};Ae(t,n,r,s)}function Ae(t,e,r,n){r.addEventListener("input",he(()=>{He(t,e,r,n)},200));let i=!1;r.addEventListener("keydown",s=>{i=!0,s.key=="Enter"?ze(e,r):s.key=="Escape"?r.blur():s.key=="ArrowUp"?me(e,-1):s.key==="ArrowDown"?me(e,1):i=!1}),r.addEventListener("keypress",s=>{i&&s.preventDefault()}),document.body.addEventListener("keydown",s=>{s.altKey||s.ctrlKey||s.metaKey||!r.matches(":focus")&&s.key==="/"&&(r.focus(),s.preventDefault())})}function Ve(t,e){t.index||window.searchData&&(e.classList.remove("loading"),e.classList.add("ready"),t.data=window.searchData,t.index=ge.Index.load(window.searchData.index))}function He(t,e,r,n){var o,a;if(Ve(n,t),!n.index||!n.data)return;e.textContent="";let i=r.value.trim(),s=i?n.index.search(`*${i}*`):[];for(let l=0;l<s.length;l++){let u=s[l],h=n.data.rows[Number(u.ref)],f=1;h.name.toLowerCase().startsWith(i.toLowerCase())&&(f*=1+1/(Math.abs(h.name.length-i.length)*10)),f*=(o=h.boost)!=null?o:1,u.score*=f}s.sort((l,u)=>u.score-l.score);for(let l=0,u=Math.min(10,s.length);l<u;l++){let h=n.data.rows[Number(s[l].ref)],f=ve(h.name,i);h.parent&&(f=`<span class="parent">${ve(h.parent,i)}.</span>${f}`);let p=document.createElement("li");p.classList.value=(a=h.classes)!=null?a:"";let E=document.createElement("a");E.href=n.base+h.url,E.classList.add("tsd-kind-icon"),E.innerHTML=f,p.append(E),e.appendChild(p)}}function me(t,e){var n,i;let r=t.querySelector(".current");if(!r)r=t.querySelector(e==1?"li:first-child":"li:last-child"),r&&r.classList.add("current");else{let s=r;if(e===1)do s=(n=s.nextElementSibling)!=null?n:void 0;while(s instanceof HTMLElement&&s.offsetParent==null);else do s=(i=s.previousElementSibling)!=null?i:void 0;while(s instanceof HTMLElement&&s.offsetParent==null);s&&(r.classList.remove("current"),s.classList.add("current"))}}function ze(t,e){let r=t.querySelector(".current");if(r||(r=t.querySelector("li:first-child")),r){let n=r.querySelector("a");n&&(window.location.href=n.href),e.blur()}}function ve(t,e){if(e==="")return t;let r=t.toLocaleLowerCase(),n=e.toLocaleLowerCase(),i=[],s=0,o=r.indexOf(n);for(;o!=-1;)i.push(se(t.substring(s,o)),`<b>${se(t.substring(o,o+n.length))}</b>`),s=o+n.length,o=r.indexOf(n,s);return i.push(se(t.substring(s))),i.join("")}var Ne={"&":"&","<":"<",">":">","'":"'",'"':"""};function se(t){return t.replace(/[&<>"'"]/g,e=>Ne[e])}var oe=class{constructor(e,r){this.signature=e,this.description=r}addClass(e){return this.signature.classList.add(e),this.description.classList.add(e),this}removeClass(e){return this.signature.classList.remove(e),this.description.classList.remove(e),this}},Z=class extends k{constructor(r){super(r);this.groups=[];this.index=-1;this.createGroups(),this.container&&(this.el.classList.add("active"),Array.from(this.el.children).forEach(n=>{n.addEventListener("touchstart",i=>this.onClick(i)),n.addEventListener("click",i=>this.onClick(i))}),this.container.classList.add("active"),this.setIndex(0))}setIndex(r){if(r<0&&(r=0),r>this.groups.length-1&&(r=this.groups.length-1),this.index==r)return;let n=this.groups[r];if(this.index>-1){let i=this.groups[this.index];i.removeClass("current").addClass("fade-out"),n.addClass("current"),n.addClass("fade-in"),Q.instance.triggerResize(),setTimeout(()=>{i.removeClass("fade-out"),n.removeClass("fade-in")},300)}else n.addClass("current"),Q.instance.triggerResize();this.index=r}createGroups(){let r=this.el.children;if(r.length<2)return;this.container=this.el.nextElementSibling;let n=this.container.children;this.groups=[];for(let i=0;i<r.length;i++)this.groups.push(new oe(r[i],n[i]))}onClick(r){this.groups.forEach((n,i)=>{n.signature===r.currentTarget&&this.setIndex(i)})}};var C="mousedown",Le="mousemove",_="mouseup",K={x:0,y:0},xe=!1,ae=!1,je=!1,A=!1,Ee=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);document.documentElement.classList.add(Ee?"is-mobile":"not-mobile");Ee&&"ontouchstart"in document.documentElement&&(je=!0,C="touchstart",Le="touchmove",_="touchend");document.addEventListener(C,t=>{ae=!0,A=!1;let e=C=="touchstart"?t.targetTouches[0]:t;K.y=e.pageY||0,K.x=e.pageX||0});document.addEventListener(Le,t=>{if(!!ae&&!A){let e=C=="touchstart"?t.targetTouches[0]:t,r=K.x-(e.pageX||0),n=K.y-(e.pageY||0);A=Math.sqrt(r*r+n*n)>10}});document.addEventListener(_,()=>{ae=!1});document.addEventListener("click",t=>{xe&&(t.preventDefault(),t.stopImmediatePropagation(),xe=!1)});var ee=class extends k{constructor(r){super(r);this.className=this.el.dataset.toggle||"",this.el.addEventListener(_,n=>this.onPointerUp(n)),this.el.addEventListener("click",n=>n.preventDefault()),document.addEventListener(C,n=>this.onDocumentPointerDown(n)),document.addEventListener(_,n=>this.onDocumentPointerUp(n))}setActive(r){if(this.active==r)return;this.active=r,document.documentElement.classList.toggle("has-"+this.className,r),this.el.classList.toggle("active",r);let n=(this.active?"to-has-":"from-has-")+this.className;document.documentElement.classList.add(n),setTimeout(()=>document.documentElement.classList.remove(n),500)}onPointerUp(r){A||(this.setActive(!0),r.preventDefault())}onDocumentPointerDown(r){if(this.active){if(r.target.closest(".col-menu, .tsd-filter-group"))return;this.setActive(!1)}}onDocumentPointerUp(r){if(!A&&this.active&&r.target.closest(".col-menu")){let n=r.target.closest("a");if(n){let i=window.location.href;i.indexOf("#")!=-1&&(i=i.substr(0,i.indexOf("#"))),n.href.substr(0,i.length)==i&&setTimeout(()=>this.setActive(!1),250)}}}};var te=class{constructor(e,r){this.key=e,this.value=r,this.defaultValue=r,this.initialize(),window.localStorage[this.key]&&this.setValue(this.fromLocalStorage(window.localStorage[this.key]))}initialize(){}setValue(e){if(this.value==e)return;let r=this.value;this.value=e,window.localStorage[this.key]=this.toLocalStorage(e),this.handleValueChange(r,e)}},re=class extends te{initialize(){let r=document.querySelector("#tsd-filter-"+this.key);!r||(this.checkbox=r,this.checkbox.addEventListener("change",()=>{this.setValue(this.checkbox.checked)}))}handleValueChange(r,n){!this.checkbox||(this.checkbox.checked=this.value,document.documentElement.classList.toggle("toggle-"+this.key,this.value!=this.defaultValue))}fromLocalStorage(r){return r=="true"}toLocalStorage(r){return r?"true":"false"}},le=class extends te{initialize(){document.documentElement.classList.add("toggle-"+this.key+this.value);let r=document.querySelector("#tsd-filter-"+this.key);if(!r)return;this.select=r;let n=()=>{this.select.classList.add("active")},i=()=>{this.select.classList.remove("active")};this.select.addEventListener(C,n),this.select.addEventListener("mouseover",n),this.select.addEventListener("mouseleave",i),this.select.querySelectorAll("li").forEach(s=>{s.addEventListener(_,o=>{r.classList.remove("active"),this.setValue(o.target.dataset.value||"")})}),document.addEventListener(C,s=>{this.select.contains(s.target)||this.select.classList.remove("active")})}handleValueChange(r,n){this.select.querySelectorAll("li.selected").forEach(o=>{o.classList.remove("selected")});let i=this.select.querySelector('li[data-value="'+n+'"]'),s=this.select.querySelector(".tsd-select-label");i&&s&&(i.classList.add("selected"),s.textContent=i.textContent),document.documentElement.classList.remove("toggle-"+r),document.documentElement.classList.add("toggle-"+n)}fromLocalStorage(r){return r}toLocalStorage(r){return r}},j=class extends k{constructor(r){super(r);this.optionVisibility=new le("visibility","private"),this.optionInherited=new re("inherited",!0),this.optionExternals=new re("externals",!0)}static isSupported(){try{return typeof window.localStorage!="undefined"}catch{return!1}}};function we(t){let e=localStorage.getItem("tsd-theme")||"os";t.value=e,be(e),t.addEventListener("change",()=>{localStorage.setItem("tsd-theme",t.value),be(t.value)})}function be(t){switch(t){case"os":document.body.classList.remove("light","dark");break;case"light":document.body.classList.remove("dark"),document.body.classList.add("light");break;case"dark":document.body.classList.remove("light"),document.body.classList.add("dark");break}}ye();N(X,".menu-highlight");N(Z,".tsd-signatures");N(ee,"a[data-toggle]");j.isSupported()?N(j,"#tsd-filter"):document.documentElement.classList.add("no-filter");var Te=document.getElementById("theme");Te&&we(Te);var Be=new Y;Object.defineProperty(window,"app",{value:Be});})();
|
|
3
|
+
/*!
|
|
4
|
+
* lunr.Builder
|
|
5
|
+
* Copyright (C) 2020 Oliver Nightingale
|
|
6
|
+
*/
|
|
7
|
+
/*!
|
|
8
|
+
* lunr.Index
|
|
9
|
+
* Copyright (C) 2020 Oliver Nightingale
|
|
10
|
+
*/
|
|
11
|
+
/*!
|
|
12
|
+
* lunr.Pipeline
|
|
13
|
+
* Copyright (C) 2020 Oliver Nightingale
|
|
14
|
+
*/
|
|
15
|
+
/*!
|
|
16
|
+
* lunr.Set
|
|
17
|
+
* Copyright (C) 2020 Oliver Nightingale
|
|
18
|
+
*/
|
|
19
|
+
/*!
|
|
20
|
+
* lunr.TokenSet
|
|
21
|
+
* Copyright (C) 2020 Oliver Nightingale
|
|
22
|
+
*/
|
|
23
|
+
/*!
|
|
24
|
+
* lunr.Vector
|
|
25
|
+
* Copyright (C) 2020 Oliver Nightingale
|
|
26
|
+
*/
|
|
27
|
+
/*!
|
|
28
|
+
* lunr.stemmer
|
|
29
|
+
* Copyright (C) 2020 Oliver Nightingale
|
|
30
|
+
* Includes code from - http://tartarus.org/~martin/PorterStemmer/js.txt
|
|
31
|
+
*/
|
|
32
|
+
/*!
|
|
33
|
+
* lunr.stopWordFilter
|
|
34
|
+
* Copyright (C) 2020 Oliver Nightingale
|
|
35
|
+
*/
|
|
36
|
+
/*!
|
|
37
|
+
* lunr.tokenizer
|
|
38
|
+
* Copyright (C) 2020 Oliver Nightingale
|
|
39
|
+
*/
|
|
40
|
+
/*!
|
|
41
|
+
* lunr.trimmer
|
|
42
|
+
* Copyright (C) 2020 Oliver Nightingale
|
|
43
|
+
*/
|
|
44
|
+
/*!
|
|
45
|
+
* lunr.utils
|
|
46
|
+
* Copyright (C) 2020 Oliver Nightingale
|
|
47
|
+
*/
|
|
48
|
+
/**
|
|
49
|
+
* lunr - http://lunrjs.com - A bit like Solr, but much smaller and not as bright - 2.3.9
|
|
50
|
+
* Copyright (C) 2020 Oliver Nightingale
|
|
51
|
+
* @license MIT
|
|
52
|
+
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
window.searchData = JSON.parse("{\"kinds\":{\"32\":\"Variable\",\"64\":\"Function\",\"256\":\"Interface\",\"1024\":\"Property\",\"4194304\":\"Type alias\"},\"rows\":[{\"id\":0,\"kind\":256,\"name\":\"Block\",\"url\":\"interfaces/Block.html\",\"classes\":\"tsd-kind-interface\"},{\"id\":1,\"kind\":1024,\"name\":\"id\",\"url\":\"interfaces/Block.html#id\",\"classes\":\"tsd-kind-property tsd-parent-kind-interface\",\"parent\":\"Block\"},{\"id\":2,\"kind\":1024,\"name\":\"tangle\",\"url\":\"interfaces/Block.html#tangle\",\"classes\":\"tsd-kind-property tsd-parent-kind-interface\",\"parent\":\"Block\"},{\"id\":3,\"kind\":1024,\"name\":\"publish\",\"url\":\"interfaces/Block.html#publish\",\"classes\":\"tsd-kind-property tsd-parent-kind-interface\",\"parent\":\"Block\"},{\"id\":4,\"kind\":1024,\"name\":\"noweb\",\"url\":\"interfaces/Block.html#noweb\",\"classes\":\"tsd-kind-property tsd-parent-kind-interface\",\"parent\":\"Block\"},{\"id\":5,\"kind\":1024,\"name\":\"lang\",\"url\":\"interfaces/Block.html#lang\",\"classes\":\"tsd-kind-property tsd-parent-kind-interface\",\"parent\":\"Block\"},{\"id\":6,\"kind\":1024,\"name\":\"matchStart\",\"url\":\"interfaces/Block.html#matchStart\",\"classes\":\"tsd-kind-property tsd-parent-kind-interface\",\"parent\":\"Block\"},{\"id\":7,\"kind\":1024,\"name\":\"matchEnd\",\"url\":\"interfaces/Block.html#matchEnd\",\"classes\":\"tsd-kind-property tsd-parent-kind-interface\",\"parent\":\"Block\"},{\"id\":8,\"kind\":1024,\"name\":\"start\",\"url\":\"interfaces/Block.html#start\",\"classes\":\"tsd-kind-property tsd-parent-kind-interface\",\"parent\":\"Block\"},{\"id\":9,\"kind\":1024,\"name\":\"end\",\"url\":\"interfaces/Block.html#end\",\"classes\":\"tsd-kind-property tsd-parent-kind-interface\",\"parent\":\"Block\"},{\"id\":10,\"kind\":1024,\"name\":\"body\",\"url\":\"interfaces/Block.html#body\",\"classes\":\"tsd-kind-property tsd-parent-kind-interface\",\"parent\":\"Block\"},{\"id\":11,\"kind\":1024,\"name\":\"edited\",\"url\":\"interfaces/Block.html#edited\",\"classes\":\"tsd-kind-property tsd-parent-kind-interface\",\"parent\":\"Block\"},{\"id\":12,\"kind\":1024,\"name\":\"resolved\",\"url\":\"interfaces/Block.html#resolved\",\"classes\":\"tsd-kind-property tsd-parent-kind-interface\",\"parent\":\"Block\"},{\"id\":13,\"kind\":256,\"name\":\"TangleRef\",\"url\":\"interfaces/TangleRef.html\",\"classes\":\"tsd-kind-interface\"},{\"id\":14,\"kind\":1024,\"name\":\"path\",\"url\":\"interfaces/TangleRef.html#path\",\"classes\":\"tsd-kind-property tsd-parent-kind-interface\",\"parent\":\"TangleRef\"},{\"id\":15,\"kind\":1024,\"name\":\"src\",\"url\":\"interfaces/TangleRef.html#src\",\"classes\":\"tsd-kind-property tsd-parent-kind-interface\",\"parent\":\"TangleRef\"},{\"id\":16,\"kind\":1024,\"name\":\"blocks\",\"url\":\"interfaces/TangleRef.html#blocks\",\"classes\":\"tsd-kind-property tsd-parent-kind-interface\",\"parent\":\"TangleRef\"},{\"id\":17,\"kind\":4194304,\"name\":\"Blocks\",\"url\":\"modules.html#Blocks\",\"classes\":\"tsd-kind-type-alias\"},{\"id\":18,\"kind\":256,\"name\":\"TangleCtx\",\"url\":\"interfaces/TangleCtx.html\",\"classes\":\"tsd-kind-interface\"},{\"id\":19,\"kind\":1024,\"name\":\"format\",\"url\":\"interfaces/TangleCtx.html#format\",\"classes\":\"tsd-kind-property tsd-parent-kind-interface\",\"parent\":\"TangleCtx\"},{\"id\":20,\"kind\":1024,\"name\":\"files\",\"url\":\"interfaces/TangleCtx.html#files\",\"classes\":\"tsd-kind-property tsd-parent-kind-interface\",\"parent\":\"TangleCtx\"},{\"id\":21,\"kind\":1024,\"name\":\"outputs\",\"url\":\"interfaces/TangleCtx.html#outputs\",\"classes\":\"tsd-kind-property tsd-parent-kind-interface\",\"parent\":\"TangleCtx\"},{\"id\":22,\"kind\":1024,\"name\":\"logger\",\"url\":\"interfaces/TangleCtx.html#logger\",\"classes\":\"tsd-kind-property tsd-parent-kind-interface\",\"parent\":\"TangleCtx\"},{\"id\":23,\"kind\":1024,\"name\":\"fs\",\"url\":\"interfaces/TangleCtx.html#fs\",\"classes\":\"tsd-kind-property tsd-parent-kind-interface\",\"parent\":\"TangleCtx\"},{\"id\":24,\"kind\":1024,\"name\":\"opts\",\"url\":\"interfaces/TangleCtx.html#opts\",\"classes\":\"tsd-kind-property tsd-parent-kind-interface\",\"parent\":\"TangleCtx\"},{\"id\":25,\"kind\":256,\"name\":\"FileSystem\",\"url\":\"interfaces/FileSystem.html\",\"classes\":\"tsd-kind-interface\"},{\"id\":26,\"kind\":1024,\"name\":\"isAbsolute\",\"url\":\"interfaces/FileSystem.html#isAbsolute\",\"classes\":\"tsd-kind-property tsd-parent-kind-interface\",\"parent\":\"FileSystem\"},{\"id\":27,\"kind\":1024,\"name\":\"resolve\",\"url\":\"interfaces/FileSystem.html#resolve\",\"classes\":\"tsd-kind-property tsd-parent-kind-interface\",\"parent\":\"FileSystem\"},{\"id\":28,\"kind\":1024,\"name\":\"read\",\"url\":\"interfaces/FileSystem.html#read\",\"classes\":\"tsd-kind-property tsd-parent-kind-interface\",\"parent\":\"FileSystem\"},{\"id\":29,\"kind\":256,\"name\":\"TangleOpts\",\"url\":\"interfaces/TangleOpts.html\",\"classes\":\"tsd-kind-interface\"},{\"id\":30,\"kind\":1024,\"name\":\"comments\",\"url\":\"interfaces/TangleOpts.html#comments\",\"classes\":\"tsd-kind-property tsd-parent-kind-interface\",\"parent\":\"TangleOpts\"},{\"id\":31,\"kind\":256,\"name\":\"CodeBlockFormat\",\"url\":\"interfaces/CodeBlockFormat.html\",\"classes\":\"tsd-kind-interface\"},{\"id\":32,\"kind\":1024,\"name\":\"prefix\",\"url\":\"interfaces/CodeBlockFormat.html#prefix\",\"classes\":\"tsd-kind-property tsd-parent-kind-interface\",\"parent\":\"CodeBlockFormat\"},{\"id\":33,\"kind\":1024,\"name\":\"suffix\",\"url\":\"interfaces/CodeBlockFormat.html#suffix\",\"classes\":\"tsd-kind-property tsd-parent-kind-interface\",\"parent\":\"CodeBlockFormat\"},{\"id\":34,\"kind\":32,\"name\":\"BLOCK_FORMATS\",\"url\":\"modules.html#BLOCK_FORMATS\",\"classes\":\"tsd-kind-variable\"},{\"id\":35,\"kind\":32,\"name\":\"COMMENT_FORMATS\",\"url\":\"modules.html#COMMENT_FORMATS\",\"classes\":\"tsd-kind-variable\"},{\"id\":36,\"kind\":32,\"name\":\"LOGGER\",\"url\":\"modules.html#LOGGER\",\"classes\":\"tsd-kind-variable\"},{\"id\":37,\"kind\":64,\"name\":\"setLogger\",\"url\":\"modules.html#setLogger\",\"classes\":\"tsd-kind-function\"},{\"id\":38,\"kind\":64,\"name\":\"tangleFile\",\"url\":\"modules.html#tangleFile\",\"classes\":\"tsd-kind-function\"},{\"id\":39,\"kind\":64,\"name\":\"tangleString\",\"url\":\"modules.html#tangleString\",\"classes\":\"tsd-kind-function\"}],\"index\":{\"version\":\"2.3.9\",\"fields\":[\"name\",\"parent\"],\"fieldVectors\":[[\"name/0\",[0,11.109]],[\"parent/0\",[]],[\"name/1\",[1,33.081]],[\"parent/1\",[0,0.928]],[\"name/2\",[2,33.081]],[\"parent/2\",[0,0.928]],[\"name/3\",[3,33.081]],[\"parent/3\",[0,0.928]],[\"name/4\",[4,33.081]],[\"parent/4\",[0,0.928]],[\"name/5\",[5,33.081]],[\"parent/5\",[0,0.928]],[\"name/6\",[6,33.081]],[\"parent/6\",[0,0.928]],[\"name/7\",[7,33.081]],[\"parent/7\",[0,0.928]],[\"name/8\",[8,33.081]],[\"parent/8\",[0,0.928]],[\"name/9\",[9,33.081]],[\"parent/9\",[0,0.928]],[\"name/10\",[10,33.081]],[\"parent/10\",[0,0.928]],[\"name/11\",[11,33.081]],[\"parent/11\",[0,0.928]],[\"name/12\",[12,33.081]],[\"parent/12\",[0,0.928]],[\"name/13\",[13,22.095]],[\"parent/13\",[]],[\"name/14\",[14,33.081]],[\"parent/14\",[13,1.846]],[\"name/15\",[15,33.081]],[\"parent/15\",[13,1.846]],[\"name/16\",[16,27.973]],[\"parent/16\",[13,1.846]],[\"name/17\",[16,27.973]],[\"parent/17\",[]],[\"name/18\",[17,16.987]],[\"parent/18\",[]],[\"name/19\",[18,33.081]],[\"parent/19\",[17,1.419]],[\"name/20\",[19,33.081]],[\"parent/20\",[17,1.419]],[\"name/21\",[20,33.081]],[\"parent/21\",[17,1.419]],[\"name/22\",[21,27.973]],[\"parent/22\",[17,1.419]],[\"name/23\",[22,33.081]],[\"parent/23\",[17,1.419]],[\"name/24\",[23,33.081]],[\"parent/24\",[17,1.419]],[\"name/25\",[24,22.095]],[\"parent/25\",[]],[\"name/26\",[25,33.081]],[\"parent/26\",[24,1.846]],[\"name/27\",[26,33.081]],[\"parent/27\",[24,1.846]],[\"name/28\",[27,33.081]],[\"parent/28\",[24,1.846]],[\"name/29\",[28,27.973]],[\"parent/29\",[]],[\"name/30\",[29,33.081]],[\"parent/30\",[28,2.337]],[\"name/31\",[30,24.608]],[\"parent/31\",[]],[\"name/32\",[31,33.081]],[\"parent/32\",[30,2.056]],[\"name/33\",[32,33.081]],[\"parent/33\",[30,2.056]],[\"name/34\",[33,33.081]],[\"parent/34\",[]],[\"name/35\",[34,33.081]],[\"parent/35\",[]],[\"name/36\",[21,27.973]],[\"parent/36\",[]],[\"name/37\",[35,33.081]],[\"parent/37\",[]],[\"name/38\",[36,33.081]],[\"parent/38\",[]],[\"name/39\",[37,33.081]],[\"parent/39\",[]]],\"invertedIndex\":[[\"block\",{\"_index\":0,\"name\":{\"0\":{}},\"parent\":{\"1\":{},\"2\":{},\"3\":{},\"4\":{},\"5\":{},\"6\":{},\"7\":{},\"8\":{},\"9\":{},\"10\":{},\"11\":{},\"12\":{}}}],[\"block_formats\",{\"_index\":33,\"name\":{\"34\":{}},\"parent\":{}}],[\"blocks\",{\"_index\":16,\"name\":{\"16\":{},\"17\":{}},\"parent\":{}}],[\"body\",{\"_index\":10,\"name\":{\"10\":{}},\"parent\":{}}],[\"codeblockformat\",{\"_index\":30,\"name\":{\"31\":{}},\"parent\":{\"32\":{},\"33\":{}}}],[\"comment_formats\",{\"_index\":34,\"name\":{\"35\":{}},\"parent\":{}}],[\"comments\",{\"_index\":29,\"name\":{\"30\":{}},\"parent\":{}}],[\"edited\",{\"_index\":11,\"name\":{\"11\":{}},\"parent\":{}}],[\"end\",{\"_index\":9,\"name\":{\"9\":{}},\"parent\":{}}],[\"files\",{\"_index\":19,\"name\":{\"20\":{}},\"parent\":{}}],[\"filesystem\",{\"_index\":24,\"name\":{\"25\":{}},\"parent\":{\"26\":{},\"27\":{},\"28\":{}}}],[\"format\",{\"_index\":18,\"name\":{\"19\":{}},\"parent\":{}}],[\"fs\",{\"_index\":22,\"name\":{\"23\":{}},\"parent\":{}}],[\"id\",{\"_index\":1,\"name\":{\"1\":{}},\"parent\":{}}],[\"isabsolute\",{\"_index\":25,\"name\":{\"26\":{}},\"parent\":{}}],[\"lang\",{\"_index\":5,\"name\":{\"5\":{}},\"parent\":{}}],[\"logger\",{\"_index\":21,\"name\":{\"22\":{},\"36\":{}},\"parent\":{}}],[\"matchend\",{\"_index\":7,\"name\":{\"7\":{}},\"parent\":{}}],[\"matchstart\",{\"_index\":6,\"name\":{\"6\":{}},\"parent\":{}}],[\"noweb\",{\"_index\":4,\"name\":{\"4\":{}},\"parent\":{}}],[\"opts\",{\"_index\":23,\"name\":{\"24\":{}},\"parent\":{}}],[\"outputs\",{\"_index\":20,\"name\":{\"21\":{}},\"parent\":{}}],[\"path\",{\"_index\":14,\"name\":{\"14\":{}},\"parent\":{}}],[\"prefix\",{\"_index\":31,\"name\":{\"32\":{}},\"parent\":{}}],[\"publish\",{\"_index\":3,\"name\":{\"3\":{}},\"parent\":{}}],[\"read\",{\"_index\":27,\"name\":{\"28\":{}},\"parent\":{}}],[\"resolve\",{\"_index\":26,\"name\":{\"27\":{}},\"parent\":{}}],[\"resolved\",{\"_index\":12,\"name\":{\"12\":{}},\"parent\":{}}],[\"setlogger\",{\"_index\":35,\"name\":{\"37\":{}},\"parent\":{}}],[\"src\",{\"_index\":15,\"name\":{\"15\":{}},\"parent\":{}}],[\"start\",{\"_index\":8,\"name\":{\"8\":{}},\"parent\":{}}],[\"suffix\",{\"_index\":32,\"name\":{\"33\":{}},\"parent\":{}}],[\"tangle\",{\"_index\":2,\"name\":{\"2\":{}},\"parent\":{}}],[\"tanglectx\",{\"_index\":17,\"name\":{\"18\":{}},\"parent\":{\"19\":{},\"20\":{},\"21\":{},\"22\":{},\"23\":{},\"24\":{}}}],[\"tanglefile\",{\"_index\":36,\"name\":{\"38\":{}},\"parent\":{}}],[\"tangleopts\",{\"_index\":28,\"name\":{\"29\":{}},\"parent\":{\"30\":{}}}],[\"tangleref\",{\"_index\":13,\"name\":{\"13\":{}},\"parent\":{\"14\":{},\"15\":{},\"16\":{}}}],[\"tanglestring\",{\"_index\":37,\"name\":{\"39\":{}},\"parent\":{}}]],\"pipeline\":[]}}");
|
package/index.d.ts
ADDED
package/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@thi.ng/tangle",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Literate programming code block tangling / codegen utility, inspired by org-mode & noweb",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"module": "./index.js",
|
|
7
|
+
"typings": "./index.d.ts",
|
|
8
|
+
"bin": "bin/tangle",
|
|
9
|
+
"sideEffects": false,
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/thi-ng/umbrella.git"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://github.com/thi-ng/umbrella/tree/master/packages/tangle#readme",
|
|
15
|
+
"funding": [
|
|
16
|
+
{
|
|
17
|
+
"type": "github",
|
|
18
|
+
"url": "https://github.com/sponsors/postspectacular"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"type": "patreon",
|
|
22
|
+
"url": "https://patreon.com/thing_umbrella"
|
|
23
|
+
}
|
|
24
|
+
],
|
|
25
|
+
"author": "Karsten Schmidt <k+npm@thi.ng>",
|
|
26
|
+
"license": "Apache-2.0",
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "yarn clean && tsc --declaration",
|
|
29
|
+
"clean": "rimraf '*.js' '*.d.ts' '*.map' doc",
|
|
30
|
+
"doc": "typedoc --excludePrivate --excludeInternal --out doc src/index.ts",
|
|
31
|
+
"doc:ae": "mkdir -p .ae/doc .ae/temp && api-extractor run --local --verbose",
|
|
32
|
+
"doc:readme": "yarn doc:stats && tools:readme",
|
|
33
|
+
"doc:stats": "tools:module-stats",
|
|
34
|
+
"pub": "yarn npm publish --access public",
|
|
35
|
+
"test": "testament test"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@thi.ng/api": "^8.4.2",
|
|
39
|
+
"@thi.ng/args": "^2.2.2",
|
|
40
|
+
"@thi.ng/checks": "^3.2.5",
|
|
41
|
+
"@thi.ng/compare": "^2.1.12",
|
|
42
|
+
"@thi.ng/date": "^2.3.8",
|
|
43
|
+
"@thi.ng/errors": "^2.2.0",
|
|
44
|
+
"@thi.ng/file-io": "^0.3.11",
|
|
45
|
+
"@thi.ng/logger": "^1.3.0",
|
|
46
|
+
"@thi.ng/strings": "^3.3.12",
|
|
47
|
+
"@thi.ng/transducers": "^8.3.14"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@microsoft/api-extractor": "^7.31.1",
|
|
51
|
+
"@thi.ng/testament": "^0.3.0",
|
|
52
|
+
"rimraf": "^3.0.2",
|
|
53
|
+
"tools": "^0.0.1",
|
|
54
|
+
"typedoc": "^0.22.17",
|
|
55
|
+
"typescript": "^4.8.3"
|
|
56
|
+
},
|
|
57
|
+
"keywords": [
|
|
58
|
+
"codegen",
|
|
59
|
+
"literate-programming",
|
|
60
|
+
"markdown",
|
|
61
|
+
"org-mode",
|
|
62
|
+
"tangle",
|
|
63
|
+
"typescript"
|
|
64
|
+
],
|
|
65
|
+
"publishConfig": {
|
|
66
|
+
"access": "public"
|
|
67
|
+
},
|
|
68
|
+
"browser": {
|
|
69
|
+
"process": false,
|
|
70
|
+
"setTimeout": false
|
|
71
|
+
},
|
|
72
|
+
"engines": {
|
|
73
|
+
"node": ">=14"
|
|
74
|
+
},
|
|
75
|
+
"files": [
|
|
76
|
+
"*.js",
|
|
77
|
+
"*.d.ts"
|
|
78
|
+
],
|
|
79
|
+
"exports": {
|
|
80
|
+
".": {
|
|
81
|
+
"default": "./index.js"
|
|
82
|
+
},
|
|
83
|
+
"./api": {
|
|
84
|
+
"default": "./api.js"
|
|
85
|
+
},
|
|
86
|
+
"./tangle": {
|
|
87
|
+
"default": "./tangle.js"
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
"thi.ng": {
|
|
91
|
+
"status": "alpha",
|
|
92
|
+
"year": 2022
|
|
93
|
+
},
|
|
94
|
+
"gitHead": "973139c5aa3b50081020f4cc726a7cc330f77fc7\n"
|
|
95
|
+
}
|
package/tangle.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { IObjectOf } from "@thi.ng/api";
|
|
2
|
+
import { TangleCtx } from "./api.js";
|
|
3
|
+
export declare const tangleFile: (path: string, ctx?: Partial<TangleCtx>) => TangleCtx;
|
|
4
|
+
/**
|
|
5
|
+
* In-memory version of {@link tangleFile}. Take a file name and an object of
|
|
6
|
+
* file names and their respective contents, then calls {@link tangleFile} with
|
|
7
|
+
* a customized {@link TangleCtx} which resolves code block refs using given
|
|
8
|
+
* virtual "file system" (of sorts).
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* All file references are considered absolute paths, i.e. `foo.md` is okay, but
|
|
12
|
+
* `../foo/bar.md` is NOT supported.
|
|
13
|
+
*
|
|
14
|
+
* @param fileID
|
|
15
|
+
* @param files
|
|
16
|
+
* @param ctx
|
|
17
|
+
*/
|
|
18
|
+
export declare const tangleString: (fileID: string, files: IObjectOf<string>, ctx?: Partial<TangleCtx>) => TangleCtx;
|
|
19
|
+
//# sourceMappingURL=tangle.d.ts.map
|
package/tangle.js
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { isPlainObject, isString } from "@thi.ng/checks";
|
|
2
|
+
import { compareByKey } from "@thi.ng/compare";
|
|
3
|
+
import { FMT_ISO_SHORT } from "@thi.ng/date";
|
|
4
|
+
import { defError } from "@thi.ng/errors/deferror";
|
|
5
|
+
import { illegalArgs } from "@thi.ng/errors/illegal-arguments";
|
|
6
|
+
import { readText } from "@thi.ng/file-io";
|
|
7
|
+
import { split } from "@thi.ng/strings";
|
|
8
|
+
import { assocObj, map, transduce } from "@thi.ng/transducers";
|
|
9
|
+
import { extname, isAbsolute, resolve, sep } from "path";
|
|
10
|
+
import { BLOCK_FORMATS, COMMENT_FORMATS, LOGGER, } from "./api.js";
|
|
11
|
+
const UnknownBlockError = defError((err) => `can't include unknown block ID: ${err[0]} (via ${err[1]})`, () => "");
|
|
12
|
+
const extractBlocks = (src, { format, logger }) => {
|
|
13
|
+
let nextID = 0;
|
|
14
|
+
const blocks = {};
|
|
15
|
+
const re = new RegExp(`^${format.prefix.replace("+", "\\+")}(\\w+)\\s+(.+)$`, "gm");
|
|
16
|
+
let match;
|
|
17
|
+
while ((match = re.exec(src))) {
|
|
18
|
+
let { id, tangle, noweb, publish } = parseBlockHeader(match[2]);
|
|
19
|
+
!id && (id = `__block-${nextID++}`);
|
|
20
|
+
const matchStart = match.index;
|
|
21
|
+
const start = src.indexOf("\n", matchStart) + 1;
|
|
22
|
+
const end = src.indexOf(`\n${format.suffix}`, matchStart + 1);
|
|
23
|
+
logger.debug("codeblock", id, start, end, matchStart, src.substring(start, 8));
|
|
24
|
+
const body = src.substring(start, end);
|
|
25
|
+
blocks[id] = {
|
|
26
|
+
id,
|
|
27
|
+
lang: match[1],
|
|
28
|
+
tangle,
|
|
29
|
+
publish,
|
|
30
|
+
noweb,
|
|
31
|
+
start,
|
|
32
|
+
end,
|
|
33
|
+
matchStart,
|
|
34
|
+
matchEnd: end + format.suffix.length + 2,
|
|
35
|
+
body,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
return blocks;
|
|
39
|
+
};
|
|
40
|
+
const resolveBlock = (block, ref, ctx) => {
|
|
41
|
+
if (block.resolved)
|
|
42
|
+
return;
|
|
43
|
+
if (block.noweb === "no") {
|
|
44
|
+
block.resolved = true;
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
ctx.logger.debug("resolve", block.id);
|
|
48
|
+
const re = /<<(.+)>>/g;
|
|
49
|
+
let match;
|
|
50
|
+
let body = block.body;
|
|
51
|
+
while ((match = re.exec(body))) {
|
|
52
|
+
const paramIdx = match[1].indexOf(" ");
|
|
53
|
+
let [childID, params] = paramIdx > 0
|
|
54
|
+
? [
|
|
55
|
+
match[1].substring(0, paramIdx),
|
|
56
|
+
JSON.parse(match[1].substring(paramIdx).trim()),
|
|
57
|
+
]
|
|
58
|
+
: [match[1]];
|
|
59
|
+
let childBlock;
|
|
60
|
+
if (childID.indexOf("#") > 0) {
|
|
61
|
+
const [file, blockID] = childID.split("#");
|
|
62
|
+
childBlock = loadAndResolveBlocks(ctx.fs.resolve(ctx.fs.resolve(ref.path, ".."), file), ctx).blocks[blockID];
|
|
63
|
+
childID = blockID;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
childID = childID.replace("#", "");
|
|
67
|
+
childBlock = ref.blocks[childID];
|
|
68
|
+
}
|
|
69
|
+
if (!childBlock)
|
|
70
|
+
throw new UnknownBlockError([childID, block.id]);
|
|
71
|
+
resolveBlock(childBlock, ref, ctx);
|
|
72
|
+
const newBody = isPlainObject(params)
|
|
73
|
+
? parametricBody(childBlock.body, params)
|
|
74
|
+
: childBlock.body;
|
|
75
|
+
block.body = block.body.replace(`<<${match[1]}>>`, newBody);
|
|
76
|
+
block.edited = true;
|
|
77
|
+
}
|
|
78
|
+
block.resolved = true;
|
|
79
|
+
block.body = block.body.replace(/\\</g, "<");
|
|
80
|
+
};
|
|
81
|
+
const resolveBlocks = (ref, ctx) => {
|
|
82
|
+
for (let id in ref.blocks) {
|
|
83
|
+
resolveBlock(ref.blocks[id], ref, ctx);
|
|
84
|
+
}
|
|
85
|
+
return ref;
|
|
86
|
+
};
|
|
87
|
+
const parseFileMeta = (src) => {
|
|
88
|
+
if (!src.startsWith("---\n"))
|
|
89
|
+
return {};
|
|
90
|
+
const res = {};
|
|
91
|
+
for (let line of split(src.substring(4))) {
|
|
92
|
+
if (line === "---")
|
|
93
|
+
break;
|
|
94
|
+
const [key, val] = line.split(/:\s+/g);
|
|
95
|
+
res[key.trim()] = val.trim();
|
|
96
|
+
}
|
|
97
|
+
return res;
|
|
98
|
+
};
|
|
99
|
+
const parseBlockHeader = (header) => transduce(map((x) => x.split(":")), assocObj(), header.split(/\s+/));
|
|
100
|
+
const parametricBody = (body, params) => body.replace(/\{\{(\w+)\}\}/g, (_, id) => params[id] != null ? params[id] : id);
|
|
101
|
+
const commentForLang = (lang, body) => {
|
|
102
|
+
const syntax = COMMENT_FORMATS[lang];
|
|
103
|
+
return isString(syntax)
|
|
104
|
+
? `${syntax} ${body}`
|
|
105
|
+
: `${syntax[0]} ${body} ${syntax[1]}`;
|
|
106
|
+
};
|
|
107
|
+
const loadAndResolveBlocks = (path, ctx) => {
|
|
108
|
+
path = ctx.fs.resolve(path);
|
|
109
|
+
if (!ctx.files[path]) {
|
|
110
|
+
const src = ctx.fs.read(path, ctx.logger);
|
|
111
|
+
const blocks = extractBlocks(src, ctx);
|
|
112
|
+
const ref = (ctx.files[path] = { path, src, blocks });
|
|
113
|
+
resolveBlocks(ref, ctx);
|
|
114
|
+
}
|
|
115
|
+
return ctx.files[path];
|
|
116
|
+
};
|
|
117
|
+
export const tangleFile = (path, ctx = {}) => {
|
|
118
|
+
const fmt = ctx.format || BLOCK_FORMATS[extname(path)];
|
|
119
|
+
!fmt && illegalArgs(`unsupported file type: ${extname(path)}`);
|
|
120
|
+
const $ctx = {
|
|
121
|
+
files: {},
|
|
122
|
+
outputs: {},
|
|
123
|
+
format: fmt,
|
|
124
|
+
logger: LOGGER,
|
|
125
|
+
fs: {
|
|
126
|
+
isAbsolute,
|
|
127
|
+
resolve,
|
|
128
|
+
read: readText,
|
|
129
|
+
},
|
|
130
|
+
...ctx,
|
|
131
|
+
opts: {
|
|
132
|
+
comments: true,
|
|
133
|
+
...ctx.opts,
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
const { path: $path, src, blocks } = loadAndResolveBlocks(path, $ctx);
|
|
137
|
+
const parentDir = $ctx.fs.resolve($path, "..");
|
|
138
|
+
const meta = parseFileMeta(src);
|
|
139
|
+
const sorted = Object.values(blocks).sort(compareByKey("start"));
|
|
140
|
+
let prev = 0;
|
|
141
|
+
let res = [];
|
|
142
|
+
for (let block of sorted) {
|
|
143
|
+
if (meta.publish) {
|
|
144
|
+
res.push(src.substring(prev, Math.max(prev, block.matchStart)));
|
|
145
|
+
if (block.publish !== "no") {
|
|
146
|
+
res.push(`${fmt.prefix}${block.lang}\n${block.body}\n${fmt.suffix}\n`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (block.tangle) {
|
|
150
|
+
const dest = $ctx.fs.isAbsolute(block.tangle)
|
|
151
|
+
? block.tangle
|
|
152
|
+
: $ctx.fs.resolve(parentDir, `${meta.tangle || "."}${sep}${block.tangle}`);
|
|
153
|
+
let body = block.body;
|
|
154
|
+
if (!$ctx.outputs[dest]) {
|
|
155
|
+
if ($ctx.opts.comments && COMMENT_FORMATS[block.lang]) {
|
|
156
|
+
body = [
|
|
157
|
+
commentForLang(block.lang, `Tangled @ ${FMT_ISO_SHORT()} - DO NOT EDIT!`),
|
|
158
|
+
commentForLang(block.lang, `Source: ${$path}`),
|
|
159
|
+
"",
|
|
160
|
+
body,
|
|
161
|
+
].join("\n");
|
|
162
|
+
}
|
|
163
|
+
$ctx.outputs[dest] = body;
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
$ctx.outputs[dest] += "\n\n" + body;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
prev = block.matchEnd;
|
|
170
|
+
}
|
|
171
|
+
res.push(src.substring(prev));
|
|
172
|
+
if (meta.publish) {
|
|
173
|
+
const dest = $ctx.fs.resolve(parentDir, meta.publish);
|
|
174
|
+
$ctx.outputs[dest] = res.join("").trim();
|
|
175
|
+
}
|
|
176
|
+
return $ctx;
|
|
177
|
+
};
|
|
178
|
+
/**
|
|
179
|
+
* In-memory version of {@link tangleFile}. Take a file name and an object of
|
|
180
|
+
* file names and their respective contents, then calls {@link tangleFile} with
|
|
181
|
+
* a customized {@link TangleCtx} which resolves code block refs using given
|
|
182
|
+
* virtual "file system" (of sorts).
|
|
183
|
+
*
|
|
184
|
+
* @remarks
|
|
185
|
+
* All file references are considered absolute paths, i.e. `foo.md` is okay, but
|
|
186
|
+
* `../foo/bar.md` is NOT supported.
|
|
187
|
+
*
|
|
188
|
+
* @param fileID
|
|
189
|
+
* @param files
|
|
190
|
+
* @param ctx
|
|
191
|
+
*/
|
|
192
|
+
export const tangleString = (fileID, files, ctx = {}) => tangleFile(fileID, {
|
|
193
|
+
fs: {
|
|
194
|
+
isAbsolute: () => true,
|
|
195
|
+
resolve: (...path) => path[path.length - 1],
|
|
196
|
+
read: (path, logger) => {
|
|
197
|
+
logger.debug("reading file ref", path);
|
|
198
|
+
const body = files[path];
|
|
199
|
+
return body !== undefined
|
|
200
|
+
? body
|
|
201
|
+
: illegalArgs(`missing file for ref: ${path}`);
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
...ctx,
|
|
205
|
+
});
|