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