podlite 0.0.82 → 0.0.84
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.podlite +95 -0
- package/esm/assemble/async.d.ts +31 -0
- package/esm/assemble/async.js +113 -0
- package/esm/assemble/async.js.map +1 -0
- package/esm/assemble/files.d.ts +2 -0
- package/esm/assemble/files.js +77 -0
- package/esm/assemble/files.js.map +1 -0
- package/esm/assemble/index.d.ts +59 -0
- package/esm/assemble/index.js +1003 -0
- package/esm/assemble/index.js.map +1 -0
- package/esm/cli.js +160 -30
- package/esm/cli.js.map +1 -1
- package/esm/file-format.d.ts +3 -0
- package/esm/file-format.js +53 -0
- package/esm/file-format.js.map +1 -0
- package/esm/index.d.ts +4 -0
- package/esm/index.js +5 -2
- package/esm/index.js.map +1 -1
- package/esm/lint/config.js +6 -2
- package/esm/lint/config.js.map +1 -1
- package/esm/lint/engine.js +1 -1
- package/esm/lint/grammar/scan.d.ts +1 -1
- package/esm/lint/grammar/scan.js +7 -6
- package/esm/lint/grammar/scan.js.map +1 -1
- package/esm/lint/index.d.ts +1 -1
- package/esm/lint/index.js +14 -14
- package/esm/lint/index.js.map +1 -1
- package/esm/lint/loader.js +5 -4
- package/esm/lint/loader.js.map +1 -1
- package/esm/lint/mute.js +2 -1
- package/esm/lint/mute.js.map +1 -1
- package/esm/lint/parallel.js +1 -1
- package/esm/lint/rules/include-resolves.d.ts +6 -0
- package/esm/lint/rules/include-resolves.js +89 -0
- package/esm/lint/rules/include-resolves.js.map +1 -0
- package/esm/lint/rules/index.js +12 -10
- package/esm/lint/rules/index.js.map +1 -1
- package/esm/lint/rules/link-file-resolves.js +2 -2
- package/esm/lint/rules/link-not-empty.js +1 -1
- package/esm/lint/rules/link-target-resolves.js +1 -1
- package/esm/lint/rules/table-shape.js +7 -1
- package/esm/lint/rules/table-shape.js.map +1 -1
- package/esm/lint/types.d.ts +6 -1
- package/esm/lint/types.js.map +1 -1
- package/esm/lint/worker.js +1 -1
- package/esm/query-blocks.d.ts +6 -0
- package/esm/query-blocks.js +127 -0
- package/esm/query-blocks.js.map +1 -0
- package/esm/query.d.ts +2 -0
- package/esm/query.js +233 -26
- package/esm/query.js.map +1 -1
- package/esm/reader.d.ts +15 -0
- package/esm/reader.js +119 -0
- package/esm/reader.js.map +1 -0
- package/esm/refresh-tocs.d.ts +2 -0
- package/esm/refresh-tocs.js +52 -0
- package/esm/refresh-tocs.js.map +1 -0
- package/esm/resolve-includes.d.ts +27 -1
- package/esm/resolve-includes.js +80 -40
- package/esm/resolve-includes.js.map +1 -1
- package/esm/test/collect.d.ts +16 -0
- package/esm/test/collect.js +368 -0
- package/esm/test/collect.js.map +1 -0
- package/esm/test/documents.d.ts +47 -0
- package/esm/test/documents.js +211 -0
- package/esm/test/documents.js.map +1 -0
- package/esm/test/evaluate.d.ts +41 -0
- package/esm/test/evaluate.js +104 -0
- package/esm/test/evaluate.js.map +1 -0
- package/esm/test/formatters/json.d.ts +2 -0
- package/esm/test/formatters/json.js +11 -0
- package/esm/test/formatters/json.js.map +1 -0
- package/esm/test/formatters/text.d.ts +2 -0
- package/esm/test/formatters/text.js +104 -0
- package/esm/test/formatters/text.js.map +1 -0
- package/esm/test/index.d.ts +11 -0
- package/esm/test/index.js +19 -0
- package/esm/test/index.js.map +1 -0
- package/esm/test/resources.d.ts +5 -0
- package/esm/test/resources.js +45 -0
- package/esm/test/resources.js.map +1 -0
- package/esm/test/run.d.ts +52 -0
- package/esm/test/run.js +91 -0
- package/esm/test/run.js.map +1 -0
- package/esm/test/sources.d.ts +48 -0
- package/esm/test/sources.js +162 -0
- package/esm/test/sources.js.map +1 -0
- package/esm/test/types.d.ts +104 -0
- package/esm/test/types.js +3 -0
- package/esm/test/types.js.map +1 -0
- package/esm/version.d.ts +1 -1
- package/esm/version.js +1 -1
- package/lib/assemble/async.d.ts +31 -0
- package/lib/assemble/async.js +118 -0
- package/lib/assemble/async.js.map +1 -0
- package/lib/assemble/files.d.ts +2 -0
- package/lib/assemble/files.js +81 -0
- package/lib/assemble/files.js.map +1 -0
- package/lib/assemble/index.d.ts +59 -0
- package/lib/assemble/index.js +1013 -0
- package/lib/assemble/index.js.map +1 -0
- package/lib/cli.js +154 -24
- package/lib/cli.js.map +1 -1
- package/lib/file-format.d.ts +3 -0
- package/lib/file-format.js +58 -0
- package/lib/file-format.js.map +1 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +22 -1
- package/lib/index.js.map +1 -1
- package/lib/lint/config.js +6 -2
- package/lib/lint/config.js.map +1 -1
- package/lib/lint/grammar/scan.d.ts +1 -1
- package/lib/lint/grammar/scan.js +7 -3
- package/lib/lint/grammar/scan.js.map +1 -1
- package/lib/lint/index.d.ts +1 -1
- package/lib/lint/index.js +3 -3
- package/lib/lint/index.js.map +1 -1
- package/lib/lint/loader.js +5 -4
- package/lib/lint/loader.js.map +1 -1
- package/lib/lint/mute.js +2 -1
- package/lib/lint/mute.js.map +1 -1
- package/lib/lint/rules/include-resolves.d.ts +6 -0
- package/lib/lint/rules/include-resolves.js +92 -0
- package/lib/lint/rules/include-resolves.js.map +1 -0
- package/lib/lint/rules/index.js +2 -0
- package/lib/lint/rules/index.js.map +1 -1
- package/lib/lint/rules/table-shape.js +7 -1
- package/lib/lint/rules/table-shape.js.map +1 -1
- package/lib/lint/types.d.ts +6 -1
- package/lib/lint/types.js.map +1 -1
- package/lib/query-blocks.d.ts +6 -0
- package/lib/query-blocks.js +136 -0
- package/lib/query-blocks.js.map +1 -0
- package/lib/query.d.ts +2 -0
- package/lib/query.js +232 -25
- package/lib/query.js.map +1 -1
- package/lib/reader.d.ts +15 -0
- package/lib/reader.js +124 -0
- package/lib/reader.js.map +1 -0
- package/lib/refresh-tocs.d.ts +2 -0
- package/lib/refresh-tocs.js +56 -0
- package/lib/refresh-tocs.js.map +1 -0
- package/lib/resolve-includes.d.ts +27 -1
- package/lib/resolve-includes.js +84 -40
- package/lib/resolve-includes.js.map +1 -1
- package/lib/test/collect.d.ts +16 -0
- package/lib/test/collect.js +374 -0
- package/lib/test/collect.js.map +1 -0
- package/lib/test/documents.d.ts +47 -0
- package/lib/test/documents.js +250 -0
- package/lib/test/documents.js.map +1 -0
- package/lib/test/evaluate.d.ts +41 -0
- package/lib/test/evaluate.js +142 -0
- package/lib/test/evaluate.js.map +1 -0
- package/lib/test/formatters/json.d.ts +2 -0
- package/lib/test/formatters/json.js +15 -0
- package/lib/test/formatters/json.js.map +1 -0
- package/lib/test/formatters/text.d.ts +2 -0
- package/lib/test/formatters/text.js +141 -0
- package/lib/test/formatters/text.js.map +1 -0
- package/lib/test/index.d.ts +11 -0
- package/lib/test/index.js +31 -0
- package/lib/test/index.js.map +1 -0
- package/lib/test/resources.d.ts +5 -0
- package/lib/test/resources.js +83 -0
- package/lib/test/resources.js.map +1 -0
- package/lib/test/run.d.ts +52 -0
- package/lib/test/run.js +95 -0
- package/lib/test/run.js.map +1 -0
- package/lib/test/sources.d.ts +48 -0
- package/lib/test/sources.js +200 -0
- package/lib/test/sources.js.map +1 -0
- package/lib/test/types.d.ts +104 -0
- package/lib/test/types.js +8 -0
- package/lib/test/types.js.map +1 -0
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +28 -7
package/esm/query.js
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
import * as fs from 'fs';
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import { getDocIDs, podlitePluggable, parseSelector, runSelector, toHtml, toMarkdown, SelectorError, } from '@podlite/schema';
|
|
4
|
+
import { describeProblem, diskProvider, expandMask, hasMask, resolveIncludes, } from './resolve-includes.js';
|
|
5
|
+
import { externalMessage } from './assemble/index.js';
|
|
6
|
+
import { refreshTocs } from './refresh-tocs.js';
|
|
7
|
+
import { readerFor, writtenTree } from './reader.js';
|
|
8
|
+
import { formatOfFile } from './file-format.js';
|
|
9
|
+
import { contentOf, hasPlace, isWrapper, jsonBlock, markSections, podliteText } from './query-blocks.js';
|
|
10
|
+
const queryReader = () => {
|
|
11
|
+
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
12
|
+
const { PluginRegister: markdown } = require('@podlite/markdown');
|
|
13
|
+
const { PluginRegister: image } = require('@podlite/image');
|
|
14
|
+
const { PluginRegister: toc } = require('@podlite/toc');
|
|
15
|
+
/* eslint-enable @typescript-eslint/no-var-requires */
|
|
16
|
+
const p = podlitePluggable({ plugins: { ...markdown, ...image, ...toc } });
|
|
17
|
+
return {
|
|
18
|
+
toTree: readerFor(p),
|
|
19
|
+
written: (text, format) => writtenTree(p, text, format),
|
|
20
|
+
};
|
|
13
21
|
};
|
|
14
22
|
// Each block is rendered through its own pod-block invocation. Wrapping
|
|
15
23
|
// multiple matches into one synthetic container triggers serializer
|
|
@@ -19,16 +27,16 @@ const renderViaRoot = (block, serializer) => {
|
|
|
19
27
|
const out = serializer === 'md' ? toMarkdown({}).run(root) : toHtml({}).run(root);
|
|
20
28
|
return out.toString();
|
|
21
29
|
};
|
|
22
|
-
const formatBlocks = (format, matches) => {
|
|
30
|
+
const formatBlocks = (format, matches, sections) => {
|
|
23
31
|
if (format === 'json') {
|
|
24
32
|
// without the source, a query over several files answers "here are the
|
|
25
33
|
// blocks" and drops "from where", which leaves the caller no way back to
|
|
26
34
|
// the document
|
|
27
|
-
return JSON.stringify(matches.map(m => ({ file: m.
|
|
35
|
+
return JSON.stringify(matches.map(m => ({ file: m.file, ...jsonBlock(m.block, sections) })), null, 2);
|
|
28
36
|
}
|
|
29
37
|
if (format === 'podlite') {
|
|
30
38
|
return matches
|
|
31
|
-
.map(m =>
|
|
39
|
+
.map(m => podliteText(m.block, m.text, sections).trimEnd())
|
|
32
40
|
.filter(Boolean)
|
|
33
41
|
.join('\n\n');
|
|
34
42
|
}
|
|
@@ -46,28 +54,227 @@ export const runQuery = (opts) => {
|
|
|
46
54
|
throw new Error(`Invalid selector: ${opts.selector}`);
|
|
47
55
|
}
|
|
48
56
|
const sources = [];
|
|
49
|
-
|
|
50
|
-
|
|
57
|
+
const problems = [];
|
|
58
|
+
const { scheme, document, anchor } = parsed;
|
|
59
|
+
const shown = `${scheme}:${document}${anchor ? `#${anchor}` : ''}`;
|
|
60
|
+
// a selector that names a file reads it, relative to where it is written: the
|
|
61
|
+
// command line; the files and the input given are not read
|
|
62
|
+
const namesFile = scheme === 'file' && Boolean(document);
|
|
63
|
+
let emptyMask = false;
|
|
64
|
+
if (namesFile && document) {
|
|
65
|
+
const masked = hasMask(document);
|
|
66
|
+
const written = masked ? expandMask(document, process.cwd(), diskProvider) : [document];
|
|
67
|
+
for (const name of written) {
|
|
68
|
+
const text = diskProvider.read(path.resolve(name));
|
|
69
|
+
if (text !== null)
|
|
70
|
+
sources.push({ file: name, text });
|
|
71
|
+
}
|
|
72
|
+
const given = [...(opts.stdinContent !== undefined ? ['<stdin>'] : []), ...opts.files];
|
|
73
|
+
if (given.length > 0)
|
|
74
|
+
problems.push(`the selector names its own source; not read: ${given.join(', ')}`);
|
|
75
|
+
if (sources.length === 0 && !(masked && !anchor)) {
|
|
76
|
+
problems.push(masked ? `no block has the address ${anchor}: ${shown}` : `the source does not resolve: ${shown}`);
|
|
77
|
+
return { output: '', matchCount: 0, exitCode: 1, problems };
|
|
78
|
+
}
|
|
79
|
+
emptyMask = sources.length === 0;
|
|
51
80
|
}
|
|
52
|
-
|
|
53
|
-
|
|
81
|
+
else {
|
|
82
|
+
if (opts.stdinContent !== undefined) {
|
|
83
|
+
sources.push({ file: '<stdin>', text: opts.stdinContent, fromStdin: true });
|
|
84
|
+
}
|
|
85
|
+
for (const f of opts.files) {
|
|
86
|
+
sources.push({ file: f, text: fs.readFileSync(f, 'utf-8') });
|
|
87
|
+
}
|
|
54
88
|
}
|
|
55
|
-
if (sources.length === 0) {
|
|
89
|
+
if (sources.length === 0 && !emptyMask) {
|
|
56
90
|
throw new Error('No input files (and no stdin)');
|
|
57
91
|
}
|
|
58
92
|
// Per-source invocation preserves file context for source-slicing in podlite output
|
|
59
93
|
const matches = [];
|
|
94
|
+
let failed = false;
|
|
95
|
+
// the source and its address are those of the query: they are missing only if
|
|
96
|
+
// no document answers
|
|
97
|
+
let answered = false;
|
|
98
|
+
let addressed = false;
|
|
99
|
+
// While an input is read, its problems wait for the selection: an external
|
|
100
|
+
// source is reported only when the selection shows blocks of it.
|
|
101
|
+
let waiting;
|
|
102
|
+
const onError = (problem) => {
|
|
103
|
+
failed = true;
|
|
104
|
+
if (waiting)
|
|
105
|
+
waiting.push(problem);
|
|
106
|
+
else
|
|
107
|
+
problems.push(describeProblem(problem));
|
|
108
|
+
};
|
|
109
|
+
const onWarning = (problem) => {
|
|
110
|
+
if (waiting)
|
|
111
|
+
waiting.push(problem);
|
|
112
|
+
else
|
|
113
|
+
problems.push(describeProblem(problem));
|
|
114
|
+
};
|
|
115
|
+
const report = (found, origin) => {
|
|
116
|
+
const shown = [];
|
|
117
|
+
// the podlite output gives a block with a place as its own text: what an
|
|
118
|
+
// include brought inside it is not printed
|
|
119
|
+
const ownText = (node) => opts.format === 'podlite' && hasPlace(node) && !sections.has(node);
|
|
120
|
+
const visit = (node) => {
|
|
121
|
+
if (!node || typeof node !== 'object')
|
|
122
|
+
return;
|
|
123
|
+
if (Array.isArray(node))
|
|
124
|
+
return node.forEach(visit);
|
|
125
|
+
const where = origin.get(node);
|
|
126
|
+
if (where)
|
|
127
|
+
shown.push(where);
|
|
128
|
+
visit(node.content);
|
|
129
|
+
};
|
|
130
|
+
for (const item of found) {
|
|
131
|
+
const where = item && typeof item === 'object' ? origin.get(item) : undefined;
|
|
132
|
+
if (!ownText(item))
|
|
133
|
+
visit(item);
|
|
134
|
+
else if (where)
|
|
135
|
+
shown.push(where);
|
|
136
|
+
}
|
|
137
|
+
// the external sources whose blocks are shown and came through this very directive
|
|
138
|
+
const brought = (problem) => {
|
|
139
|
+
const at = problem.chain[problem.chain.length - 1];
|
|
140
|
+
const offset = at?.location?.start?.offset;
|
|
141
|
+
const through = shown.filter(where => where.steps?.some(step => step.file === at?.file && step.location?.start?.offset === offset));
|
|
142
|
+
return (problem.sources ?? []).filter(source => through.some(where => where.file === source.id));
|
|
143
|
+
};
|
|
144
|
+
for (const problem of waiting ?? []) {
|
|
145
|
+
if (problem.kind !== 'external') {
|
|
146
|
+
problems.push(describeProblem(problem));
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
const sources = brought(problem);
|
|
150
|
+
if (sources.length === 0)
|
|
151
|
+
continue;
|
|
152
|
+
const written = parseSelector(problem.target)?.document ?? problem.target;
|
|
153
|
+
const line = describeProblem({ ...problem, message: externalMessage(sources, written) });
|
|
154
|
+
// counted again, two lines of one directive may come to the same text
|
|
155
|
+
if (!problems.includes(line))
|
|
156
|
+
problems.push(line);
|
|
157
|
+
}
|
|
158
|
+
waiting = undefined;
|
|
159
|
+
};
|
|
160
|
+
const reader = queryReader();
|
|
161
|
+
const sections = new WeakMap();
|
|
162
|
+
// each file is read on its own before its includes, as convert reads it
|
|
163
|
+
const toTree = (text, file, config, how) => {
|
|
164
|
+
const tree = reader.toTree(text, file, config, { format: how?.format });
|
|
165
|
+
markSections(tree, sections);
|
|
166
|
+
return tree;
|
|
167
|
+
};
|
|
168
|
+
// a file an operand names is relative to where the selector is written: the
|
|
169
|
+
// command line
|
|
170
|
+
const carrySection = (from, to) => {
|
|
171
|
+
const section = sections.get(from);
|
|
172
|
+
if (section)
|
|
173
|
+
sections.set(to, section);
|
|
174
|
+
};
|
|
175
|
+
const readFile = (document) => {
|
|
176
|
+
const file = path.resolve(document);
|
|
177
|
+
if (!fs.existsSync(file) || !fs.statSync(file).isFile())
|
|
178
|
+
return undefined;
|
|
179
|
+
const text = fs.readFileSync(file, 'utf-8');
|
|
180
|
+
const node = resolveIncludes(toTree(text, file, undefined, { format: formatOfFile(file) }), {
|
|
181
|
+
baseDir: path.dirname(file),
|
|
182
|
+
parse: toTree,
|
|
183
|
+
file: document,
|
|
184
|
+
self: file,
|
|
185
|
+
text,
|
|
186
|
+
onCopy: carrySection,
|
|
187
|
+
onError,
|
|
188
|
+
onWarning,
|
|
189
|
+
});
|
|
190
|
+
return [{ file: document, node: contentOf(node) }];
|
|
191
|
+
};
|
|
192
|
+
// a mask no file answers selects nothing, and its operands are still read
|
|
193
|
+
if (emptyMask) {
|
|
194
|
+
const blank = { file: '', node: toTree('', '') };
|
|
195
|
+
try {
|
|
196
|
+
runSelector(opts.selector, [], { readFile, home: [blank] });
|
|
197
|
+
}
|
|
198
|
+
catch (e) {
|
|
199
|
+
if (!(e instanceof SelectorError))
|
|
200
|
+
throw e;
|
|
201
|
+
problems.push(e.message);
|
|
202
|
+
return { output: '', matchCount: 0, exitCode: 1, problems };
|
|
203
|
+
}
|
|
204
|
+
return { output: '', matchCount: 0, exitCode: failed || opts.failOnEmpty ? 1 : 0, problems };
|
|
205
|
+
}
|
|
60
206
|
for (const src of sources) {
|
|
61
|
-
const
|
|
62
|
-
const
|
|
207
|
+
const origin = new WeakMap();
|
|
208
|
+
const fromStdin = src.fromStdin === true;
|
|
209
|
+
const baseDir = fromStdin ? process.cwd() : path.dirname(path.resolve(src.file));
|
|
210
|
+
waiting = [];
|
|
211
|
+
// a document is read in the format its name gives; text from the standard input is Podlite
|
|
212
|
+
const format = fromStdin ? 'podlite' : formatOfFile(src.file);
|
|
213
|
+
const resolved = resolveIncludes(toTree(src.text, src.file, undefined, { format }), {
|
|
214
|
+
baseDir,
|
|
215
|
+
root: opts.root ?? baseDir,
|
|
216
|
+
parse: toTree,
|
|
217
|
+
file: src.file,
|
|
218
|
+
self: fromStdin ? undefined : src.file,
|
|
219
|
+
text: src.text,
|
|
220
|
+
origin,
|
|
221
|
+
onCopy: carrySection,
|
|
222
|
+
onError,
|
|
223
|
+
onWarning,
|
|
224
|
+
});
|
|
225
|
+
// the tables of contents are made again over what the includes brought; a
|
|
226
|
+
// copy keeps the section its block was read out of
|
|
227
|
+
const node = refreshTocs(resolved, reader.written(src.text, format), src.file, origin, (from, to) => {
|
|
228
|
+
const section = sections.get(from);
|
|
229
|
+
if (section)
|
|
230
|
+
sections.set(to, section);
|
|
231
|
+
});
|
|
232
|
+
const docs = [{ file: src.file, node: contentOf(node) }];
|
|
233
|
+
if (scheme === 'doc' && document && !getDocIDs(docs[0]).includes(document)) {
|
|
234
|
+
report([], origin);
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
answered = true;
|
|
238
|
+
let result;
|
|
239
|
+
try {
|
|
240
|
+
result = runSelector(opts.selector, docs, { readFile });
|
|
241
|
+
}
|
|
242
|
+
catch (e) {
|
|
243
|
+
report([], origin);
|
|
244
|
+
if (!(e instanceof SelectorError))
|
|
245
|
+
throw e;
|
|
246
|
+
// with an address the selection is not applied, so no operand is read
|
|
247
|
+
if (anchor && e.kind === 'address')
|
|
248
|
+
continue;
|
|
249
|
+
failed = true;
|
|
250
|
+
problems.push(`${src.file}: ${e.message}`);
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
report(result, origin);
|
|
254
|
+
if (anchor)
|
|
255
|
+
addressed = true;
|
|
63
256
|
for (const item of result) {
|
|
64
|
-
|
|
65
|
-
|
|
257
|
+
// what the tree adds around the written blocks is not counted as found
|
|
258
|
+
if (item && typeof item === 'object' && !('file' in item) && !isWrapper(item)) {
|
|
259
|
+
const where = origin.get(item);
|
|
260
|
+
matches.push({
|
|
261
|
+
file: where ? where.file : src.file,
|
|
262
|
+
text: where ? where.text : src.text,
|
|
263
|
+
block: item,
|
|
264
|
+
});
|
|
66
265
|
}
|
|
67
266
|
}
|
|
68
267
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
268
|
+
if (scheme === 'doc' && !answered) {
|
|
269
|
+
failed = true;
|
|
270
|
+
problems.push(`the source does not resolve: ${shown}`);
|
|
271
|
+
}
|
|
272
|
+
else if (anchor && answered && !addressed) {
|
|
273
|
+
failed = true;
|
|
274
|
+
problems.push(`no block has the address ${anchor}: ${shown}`);
|
|
275
|
+
}
|
|
276
|
+
const output = formatBlocks(opts.format, matches, sections);
|
|
277
|
+
const exitCode = failed || (opts.failOnEmpty && matches.length === 0) ? 1 : 0;
|
|
278
|
+
return { output, matchCount: matches.length, exitCode, problems };
|
|
72
279
|
};
|
|
73
280
|
//# sourceMappingURL=query.js.map
|
package/esm/query.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query.js","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AACxB,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,EAAwB,MAAM,iBAAiB,CAAA;AAe7G,MAAM,UAAU,GAAG,CAAC,IAAY,EAAU,EAAE;IAC1C,MAAM,IAAI,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;IAC3C,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,EAAE,CAAA;AAC1C,CAAC,CAAA;AAED,MAAM,UAAU,GAAG,CAAC,IAAY,EAAE,KAAU,EAAU,EAAE;IACtD,MAAM,GAAG,GAAG,KAAK,EAAE,QAAQ,CAAA;IAC3B,IAAI,CAAC,GAAG,IAAI,OAAO,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,QAAQ,IAAI,OAAO,GAAG,CAAC,GAAG,EAAE,MAAM,KAAK,QAAQ,EAAE,CAAC;QACzF,OAAO,EAAE,CAAA;IACX,CAAC;IACD,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;AACrD,CAAC,CAAA;AAED,wEAAwE;AACxE,oEAAoE;AACpE,4DAA4D;AA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4BAA4B,MAAM,KAAK,KAAK,EAAE,CAAC,CAAA;IAC/D,CAAC;IAED,MAAM,MAAM,GAAG,YAAY,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAA;IAC3D,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,WAAW,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IAC7E,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAA;AACnE,CAAC,CAAA"}
|
package/esm/reader.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AstTree, ConfigScope, Podlite, PodliteDocument, ScopedBlock, parseOpt } from '@podlite/schema';
|
|
2
|
+
import type { ReadFormat } from './file-format';
|
|
3
|
+
export type { ReadFormat } from './file-format';
|
|
4
|
+
export type ReaderOptions = {
|
|
5
|
+
format?: (file: string) => ReadFormat;
|
|
6
|
+
body?: (block: ScopedBlock) => boolean;
|
|
7
|
+
};
|
|
8
|
+
type Parser = Pick<Podlite, 'parse' | 'toAst'>;
|
|
9
|
+
type ReadExtras = Pick<parseOpt, 'recognition' | 'diagnostics'> & {
|
|
10
|
+
format?: ReadFormat;
|
|
11
|
+
};
|
|
12
|
+
type Reader<T> = (text: string, file: string, config?: ConfigScope, extras?: ReadExtras) => T;
|
|
13
|
+
export declare const writtenTree: (parser: Pick<Podlite, "parse">, text: string, format?: ReadFormat) => any;
|
|
14
|
+
export declare function readerFor(parser: Parser): Reader<PodliteDocument>;
|
|
15
|
+
export declare function readerFor(parser: Parser, options: ReaderOptions): Reader<PodliteDocument | AstTree>;
|
package/esm/reader.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { propagateConfigDefaults, walkConfigScopes } from '@podlite/schema';
|
|
2
|
+
import { parseMd } from '@podlite/markdown';
|
|
3
|
+
// The raw body of a block as the parser holds it, when that is all the block holds
|
|
4
|
+
const rawBody = (block) => {
|
|
5
|
+
const content = block.content;
|
|
6
|
+
if (!Array.isArray(content) || !content.length)
|
|
7
|
+
return undefined;
|
|
8
|
+
if (!content.every(part => part && part.type === 'verbatim' && typeof part.value === 'string'))
|
|
9
|
+
return undefined;
|
|
10
|
+
return content.map(part => part.value).join('');
|
|
11
|
+
};
|
|
12
|
+
// white space within a line, as the parser takes it for an indent
|
|
13
|
+
const blank = '[^\\S\\r\\n]';
|
|
14
|
+
const indent = new RegExp(blank);
|
|
15
|
+
// Where the characters of a body stand in the text of its document. The parser
|
|
16
|
+
// cuts the indent at the start of a line and nothing else, so the body read
|
|
17
|
+
// backwards from where it ends is the text read backwards with runs of white
|
|
18
|
+
// space left out. A body that is not, has no place, and there is no answer.
|
|
19
|
+
const placeOf = (body, block, text) => {
|
|
20
|
+
const from = block.location?.start?.offset;
|
|
21
|
+
const to = block.location?.end?.offset;
|
|
22
|
+
if (typeof from !== 'number' || typeof to !== 'number')
|
|
23
|
+
return undefined;
|
|
24
|
+
// a delimited block ends with its closing marker, the other forms with their body;
|
|
25
|
+
// the marker starts its line: the same words at the end of a line of text are text
|
|
26
|
+
const closing = new RegExp(`(?<=^|[\\r\\n])${blank}*=end${blank}+${block.name}${blank}*(\\r\\n|\\n|\\r)?$`);
|
|
27
|
+
const within = text.slice(0, to);
|
|
28
|
+
const end = within.length - (closing.exec(within)?.[0].length ?? 0);
|
|
29
|
+
const at = new Array(body.length + 1);
|
|
30
|
+
at[body.length] = end;
|
|
31
|
+
let offset = end;
|
|
32
|
+
for (let i = body.length - 1; i >= 0; i--) {
|
|
33
|
+
offset--;
|
|
34
|
+
while (offset >= from && text[offset] !== body[i] && indent.test(text[offset]))
|
|
35
|
+
offset--;
|
|
36
|
+
if (offset < from || text[offset] !== body[i])
|
|
37
|
+
return undefined;
|
|
38
|
+
at[i] = offset;
|
|
39
|
+
}
|
|
40
|
+
return point => {
|
|
41
|
+
const offset = at[Math.min(Math.max(point.offset, 0), body.length)];
|
|
42
|
+
// lines are counted the way the parser counts them
|
|
43
|
+
const lineStart = text.lastIndexOf('\n', offset - 1) + 1;
|
|
44
|
+
let line = 1;
|
|
45
|
+
for (let i = text.indexOf('\n'); i !== -1 && i < offset; i = text.indexOf('\n', i + 1))
|
|
46
|
+
line++;
|
|
47
|
+
return { line, column: offset - lineStart + 1, offset };
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
const placed = (location, place) => ({
|
|
51
|
+
...location,
|
|
52
|
+
start: place(location.start),
|
|
53
|
+
end: place(location.end),
|
|
54
|
+
});
|
|
55
|
+
const placeTree = (node, place) => {
|
|
56
|
+
if (Array.isArray(node))
|
|
57
|
+
return node.forEach(child => placeTree(child, place));
|
|
58
|
+
if (!node || typeof node !== 'object')
|
|
59
|
+
return;
|
|
60
|
+
if (node.location?.start && node.location?.end)
|
|
61
|
+
node.location = placed(node.location, place);
|
|
62
|
+
placeTree(node.content, place);
|
|
63
|
+
};
|
|
64
|
+
/*
|
|
65
|
+
=begin pod :kind<export>
|
|
66
|
+
|
|
67
|
+
=head2 writtenTree
|
|
68
|
+
|
|
69
|
+
A text as its file holds it, read in its format by the parser alone, without the
|
|
70
|
+
plugins: what a table of contents is built again from once the includes are in.
|
|
71
|
+
|
|
72
|
+
=end pod
|
|
73
|
+
*/
|
|
74
|
+
export const writtenTree = (parser, text, format = 'podlite') => format === 'md' ? parseMd(text) : parser.parse(text, { podMode: format === 'default' ? 0 : 1 });
|
|
75
|
+
export function readerFor(parser, options = {}) {
|
|
76
|
+
const { format, body } = options;
|
|
77
|
+
const readBodies = (tree, text, config, extras, root) => walkConfigScopes(tree, config, (node, scope) => {
|
|
78
|
+
const block = node;
|
|
79
|
+
if (block.name === 'root' || !body(node))
|
|
80
|
+
return;
|
|
81
|
+
const raw = rawBody(block);
|
|
82
|
+
if (raw === undefined)
|
|
83
|
+
return;
|
|
84
|
+
const place = placeOf(raw, block, text);
|
|
85
|
+
if (!place)
|
|
86
|
+
return;
|
|
87
|
+
const here = { ...scope };
|
|
88
|
+
const recognition = [];
|
|
89
|
+
const diagnostics = [];
|
|
90
|
+
const read = parser.toAst(parser.parse(raw, { podMode: 1, config: here, recognition, diagnostics }), {
|
|
91
|
+
config: here,
|
|
92
|
+
});
|
|
93
|
+
placeTree(read.content, place);
|
|
94
|
+
const told = Array.isArray(read.diagnostics) ? read.diagnostics : diagnostics;
|
|
95
|
+
const warnings = told.map(item => ({ ...item, location: placed(item.location, place) }));
|
|
96
|
+
if (warnings.length) {
|
|
97
|
+
// the list the caller gave is the one the root holds once it is not empty
|
|
98
|
+
const list = extras.diagnostics ?? root.diagnostics ?? [];
|
|
99
|
+
list.push(...warnings);
|
|
100
|
+
root.diagnostics = list;
|
|
101
|
+
}
|
|
102
|
+
extras.recognition?.push(...recognition.map(event => ({ ...event, location: placed(event.location, place) })));
|
|
103
|
+
// a body inside is found from its place in the text, as this one was
|
|
104
|
+
readBodies(read.content, text, here, extras, root);
|
|
105
|
+
block.content = read.content;
|
|
106
|
+
});
|
|
107
|
+
return (text, file, config, extras = {}) => {
|
|
108
|
+
const { format: asked, ...lists } = extras;
|
|
109
|
+
const chosen = asked ?? format?.(file) ?? 'podlite';
|
|
110
|
+
if (chosen === 'md')
|
|
111
|
+
return config ? propagateConfigDefaults(parseMd(text), config) : parseMd(text);
|
|
112
|
+
const podMode = chosen === 'default' ? 0 : 1;
|
|
113
|
+
const tree = parser.toAst(parser.parse(text, { ...lists, podMode, config }), { config });
|
|
114
|
+
if (body)
|
|
115
|
+
readBodies(tree, text, config ?? {}, lists, tree);
|
|
116
|
+
return tree;
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=reader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reader.js","sourceRoot":"","sources":["../src/reader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE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,CAAA;QAC1C,MAAM,MAAM,GAAG,KAAK,IAAI,MAAM,EAAE,CAAC,IAAI,CAAC,IAAI,SAAS,CAAA;QACnD,IAAI,MAAM,KAAK,IAAI;YAAE,OAAO,MAAM,CAAC,CAAC,CAAC,uBAAuB,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;QACnG,MAAM,OAAO,GAAG,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;QAC5C,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,GAAG,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,CAAA;QACxF,IAAI,IAAI;YAAE,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,IAAI,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,CAAA;QAC3D,OAAO,IAAI,CAAA;IACb,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { markGuarded } from '@podlite/schema';
|
|
2
|
+
import { plugin as tocPlugin } from '@podlite/toc';
|
|
3
|
+
const isTocBlock = (node) => node && typeof node === 'object' && node.type === 'block' && (node.name === 'toc' || node.name === 'Toc');
|
|
4
|
+
const collectTocBlocks = (tree, found) => {
|
|
5
|
+
if (!tree || typeof tree !== 'object')
|
|
6
|
+
return;
|
|
7
|
+
if (Array.isArray(tree))
|
|
8
|
+
return tree.forEach(node => collectTocBlocks(node, found));
|
|
9
|
+
if (isTocBlock(tree) && tree.location)
|
|
10
|
+
found.set(tree.location.start.offset, tree);
|
|
11
|
+
if (Array.isArray(tree.content))
|
|
12
|
+
tree.content.forEach((node) => collectTocBlocks(node, found));
|
|
13
|
+
};
|
|
14
|
+
// A table of contents is built while its file is parsed, before the includes of
|
|
15
|
+
// that file are in. Built again over the assembled document, it reaches the
|
|
16
|
+
// blocks they brought. Only the document's own tables are rebuilt: a table in an
|
|
17
|
+
// included file stays as its file built it.
|
|
18
|
+
export const refreshTocs = (tree, written, file, origin,
|
|
19
|
+
// told of each copy, so a caller keeping its own table on the nodes can carry it
|
|
20
|
+
onCopy) => {
|
|
21
|
+
const blocks = new Map();
|
|
22
|
+
// a table hidden by its own :masked or by a hidden container keeps that mark here
|
|
23
|
+
collectTocBlocks(markGuarded(written), blocks);
|
|
24
|
+
if (blocks.size === 0)
|
|
25
|
+
return tree;
|
|
26
|
+
const rebuild = tocPlugin.toAstAfter(null, null, tree);
|
|
27
|
+
const walk = (node) => {
|
|
28
|
+
if (!node || typeof node !== 'object')
|
|
29
|
+
return node;
|
|
30
|
+
if (Array.isArray(node))
|
|
31
|
+
return node.map(walk);
|
|
32
|
+
const own = origin.get(node)?.file === file;
|
|
33
|
+
// the table is made again inside the block that holds it, so there stays one of each
|
|
34
|
+
if (isTocBlock(node) && own && node.location && blocks.has(node.location.start.offset)) {
|
|
35
|
+
const made = rebuild(blocks.get(node.location.start.offset), { tocSelf: node }, (content) => content);
|
|
36
|
+
const copy = { ...node, content: made.content };
|
|
37
|
+
origin.set(copy, origin.get(node));
|
|
38
|
+
onCopy?.(node, copy);
|
|
39
|
+
return copy;
|
|
40
|
+
}
|
|
41
|
+
if (!Array.isArray(node.content))
|
|
42
|
+
return node;
|
|
43
|
+
const copy = { ...node, content: node.content.map(walk) };
|
|
44
|
+
const known = origin.get(node);
|
|
45
|
+
if (known)
|
|
46
|
+
origin.set(copy, known);
|
|
47
|
+
onCopy?.(node, copy);
|
|
48
|
+
return copy;
|
|
49
|
+
};
|
|
50
|
+
return walk(tree);
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=refresh-tocs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refresh-tocs.js","sourceRoot":"","sources":["../src/refresh-tocs.ts"],"names":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CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC;YAAE,OAAO,IAAI,CAAA;QAC7C,MAAM,IAAI,GAAG,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAA;QACzD,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;QAC9B,IAAI,KAAK;YAAE,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;QAClC,MAAM,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;QACpB,OAAO,IAAI,CAAA;IACb,CAAC,CAAA;IACD,OAAO,IAAI,CAAC,IAAI,CAAC,CAAA;AACnB,CAAC,CAAA"}
|
|
@@ -1,5 +1,31 @@
|
|
|
1
|
+
import { ConfigScope } from '@podlite/schema';
|
|
2
|
+
import { IncludeOrigin, IncludeProblem } from './assemble';
|
|
3
|
+
import type { ReadFormat } from './file-format';
|
|
4
|
+
export { isWarning } from './assemble';
|
|
5
|
+
export type { IncludeStep, IncludeProblem, IncludeOrigin } from './assemble';
|
|
6
|
+
export type SourceProvider = {
|
|
7
|
+
read: (file: string) => string | null;
|
|
8
|
+
list: (dir: string, deep: boolean) => string[];
|
|
9
|
+
real?: (file: string) => string | null;
|
|
10
|
+
};
|
|
1
11
|
export type ResolveIncludesOptions = {
|
|
2
12
|
baseDir: string;
|
|
3
|
-
parse: (source: string
|
|
13
|
+
parse: (source: string, file: string, config?: ConfigScope, how?: {
|
|
14
|
+
format?: ReadFormat;
|
|
15
|
+
}) => any;
|
|
16
|
+
file?: string;
|
|
17
|
+
text?: string;
|
|
18
|
+
self?: string;
|
|
19
|
+
onError?: (problem: IncludeProblem) => void;
|
|
20
|
+
onWarning?: (problem: IncludeProblem) => void;
|
|
21
|
+
origin?: WeakMap<object, IncludeOrigin>;
|
|
22
|
+
onCopy?: (from: object, to: object) => void;
|
|
23
|
+
tolerant?: boolean;
|
|
24
|
+
provider?: SourceProvider;
|
|
25
|
+
root?: string;
|
|
4
26
|
};
|
|
27
|
+
export declare const hasMask: (target: string) => boolean;
|
|
28
|
+
export declare const expandMask: (target: string, baseDir: string, provider: SourceProvider) => string[];
|
|
29
|
+
export declare const diskProvider: SourceProvider;
|
|
5
30
|
export declare const resolveIncludes: (tree: any, opts: ResolveIncludesOptions) => any;
|
|
31
|
+
export declare const describeProblem: (problem: IncludeProblem) => string;
|