@podlite/publisher 0.0.52 → 0.0.54

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 (52) hide show
  1. package/CHANGELOG.podlite +26 -0
  2. package/esm/catalogue.d.ts +17 -0
  3. package/esm/catalogue.js +156 -0
  4. package/esm/catalogue.js.map +1 -0
  5. package/esm/images-plugin.js +3 -1
  6. package/esm/images-plugin.js.map +1 -1
  7. package/esm/include-resolve-plugin.d.ts +16 -1
  8. package/esm/include-resolve-plugin.js +235 -104
  9. package/esm/include-resolve-plugin.js.map +1 -1
  10. package/esm/links-plugin.d.ts +9 -1
  11. package/esm/links-plugin.js +144 -58
  12. package/esm/links-plugin.js.map +1 -1
  13. package/esm/node-utils.d.ts +3 -2
  14. package/esm/node-utils.js +60 -19
  15. package/esm/node-utils.js.map +1 -1
  16. package/esm/react-plugin.js +9 -1
  17. package/esm/react-plugin.js.map +1 -1
  18. package/esm/reading.d.ts +5 -0
  19. package/esm/reading.js +34 -0
  20. package/esm/reading.js.map +1 -0
  21. package/esm/record.d.ts +2 -2
  22. package/esm/record.js +1 -1
  23. package/esm/record.js.map +1 -1
  24. package/esm/site-data-plugin.d.ts +1 -0
  25. package/esm/site-data-plugin.js +12 -1
  26. package/esm/site-data-plugin.js.map +1 -1
  27. package/esm/source.d.ts +6 -0
  28. package/esm/source.js +27 -0
  29. package/esm/source.js.map +1 -1
  30. package/esm/version.d.ts +1 -1
  31. package/esm/version.js +1 -1
  32. package/lib/catalogue.d.ts +17 -0
  33. package/lib/catalogue.js +197 -0
  34. package/lib/images-plugin.js +3 -1
  35. package/lib/include-resolve-plugin.d.ts +16 -1
  36. package/lib/include-resolve-plugin.js +270 -103
  37. package/lib/links-plugin.d.ts +9 -1
  38. package/lib/links-plugin.js +177 -56
  39. package/lib/node-utils.d.ts +3 -2
  40. package/lib/node-utils.js +73 -31
  41. package/lib/react-plugin.js +9 -1
  42. package/lib/reading.d.ts +5 -0
  43. package/lib/reading.js +38 -0
  44. package/lib/record.d.ts +2 -2
  45. package/lib/record.js +2 -1
  46. package/lib/site-data-plugin.d.ts +1 -0
  47. package/lib/site-data-plugin.js +13 -1
  48. package/lib/source.d.ts +6 -0
  49. package/lib/source.js +29 -1
  50. package/lib/version.d.ts +1 -1
  51. package/lib/version.js +1 -1
  52. package/package.json +4 -4
@@ -1,118 +1,249 @@
1
- import { getTextContentFromNode, makeInterator } from '@podlite/schema';
2
- import { applySetToFirst, outermost, SelectorError } from '@podlite/schema';
3
- import { parseSelector, runSelector } from './shared.js';
4
- // A selector whose source, address or operand does not resolve brings nothing
5
- // in, and says so once, naming the =set assignments lost with it.
6
- const select = (selector, recs, lost = '') => {
7
- // a selector that is not read, or a scheme not resolved here, finds nothing
8
- // without saying why
9
- const parsed = parseSelector(selector);
10
- if (!parsed) {
11
- console.warn(`[plugin: resolve ] selector ${selector} cannot be read${lost}`);
12
- return null;
13
- }
14
- if (parsed.scheme && parsed.scheme !== 'doc' && parsed.scheme !== 'file') {
15
- console.warn(`[plugin: resolve ] selector ${selector}: scheme ${parsed.scheme}: is not supported${lost}`);
16
- return null;
17
- }
18
- try {
19
- return runSelector(selector, recs);
20
- }
21
- catch (e) {
22
- if (!(e instanceof SelectorError))
23
- throw e;
24
- console.warn(`[plugin: resolve ] selector ${selector} cannot be read: ${e.message}${lost}`);
25
- return null;
1
+ import * as path from 'path';
2
+ import { getFromTree } from '@podlite/schema';
3
+ import { assembleIncludes, podlite, writtenTree } from 'podlite';
4
+ import { refreshTocs } from 'podlite/lib/refresh-tocs';
5
+ import { catalogueOf, idOfFile } from './catalogue.js';
6
+ import { getParserTypeforFile, PARSER_TYPES } from './node-utils.js';
7
+ import { readRecordText } from './reading.js';
8
+ import { SITE_DATA_DOCUMENT } from './site-data-plugin.js';
9
+ import { nodeOriginKey, recordOrigin } from './source.js';
10
+ /*
11
+ =begin pod :kind<export>
12
+
13
+ =head2 IncludeError
14
+
15
+ The build stops when an include cannot place what it names:
16
+
17
+ =item the source or the address is not found;
18
+ =item the selector cannot be read;
19
+ =item the scheme is not one the site reads;
20
+ =item a name answers to two documents;
21
+ =item a file includes itself, directly or through other files.
22
+
23
+ C<problems> holds one line for each, with the file and the line of the directive.
24
+
25
+ =end pod
26
+ */
27
+ export class IncludeError extends Error {
28
+ problems;
29
+ constructor(problems) {
30
+ super(`an include is not placed:\n${problems.map(line => ` ${line}`).join('\n')}`);
31
+ this.name = 'IncludeError';
32
+ this.problems = problems;
26
33
  }
34
+ }
35
+ // lose what the include names, though the assembler reports them as warnings
36
+ const stopping = new Set(['unsupported-scheme', 'unparsed-selector', 'cycle', 'ambiguous']);
37
+ const shown = (file) => (path.isAbsolute(file) ? path.relative(process.cwd(), file) : file);
38
+ const isNode = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
39
+ const nodesOf = (tree, ...queries) => getFromTree(tree, ...queries).flatMap(node => (isNode(node) ? [node] : []));
40
+ const isToc = (node) => node.type === 'block' && (node.name === 'toc' || node.name === 'Toc');
41
+ const hasToc = (tree) => nodesOf(tree, 'toc', 'Toc').some(isToc);
42
+ // the format a table of contents of the record is built again from; none for Markdown
43
+ const writtenFormat = (source) => {
44
+ const type = getParserTypeforFile(source.file, source.mime);
45
+ return type === PARSER_TYPES.MARKDOWN ? undefined : type === PARSER_TYPES.PODLITE ? 'podlite' : 'default';
27
46
  };
28
- const names = (set) => set.map(c => c.name).join(', ');
29
- // The =set assignments written before an include go to the first block it
30
- // brings; once placed or lost, the directive no longer carries them. When the
31
- // include brings no block they stay without a target: carrying them on to the
32
- // next block is not done here, nor through an include inside what was brought.
33
- const assignments = (node) => {
34
- const set = node.set || [];
35
- const { set: _, ...rest } = node;
36
- const lost = set.length ? `; =set assignments not applied: ${names(set)}` : '';
37
- const place = (blocks) => {
38
- if (!set.length)
39
- return blocks;
40
- const applied = applySetToFirst(blocks, set, { mode: 'include' });
41
- if (applied.outcome !== 'block') {
42
- console.warn(`[plugin: resolve ] =set before =include has no target block: ${names(set)}`);
43
- }
44
- return applied.outcome === 'block' ? applied.nodes : blocks;
47
+ const passes = (options) => {
48
+ const late = new Set([SITE_DATA_DOCUMENT, ...(options.late ?? [])]);
49
+ let waiting = false;
50
+ const catalogue = catalogueOf(options.catalogue ?? [], {
51
+ bounds: options.bounds,
52
+ parse: (text, file) => readRecordText(text, file),
53
+ waits: name => waiting && late.has(name),
54
+ });
55
+ const parser = podlite({ importPlugins: true });
56
+ // the file a directive was written in, by the place a problem shares with it
57
+ const fileAt = new WeakMap();
58
+ const describe = (problem) => {
59
+ const steps = problem.chain.map(step => {
60
+ const file = (step.location && fileAt.get(step.location)) || step.file;
61
+ return `${shown(file)}${step.location ? `:${step.location.start.line}` : ''}`;
62
+ });
63
+ const at = steps.pop() ?? '<document>';
64
+ return `${at}: ${problem.message}${steps.length ? ` (included through ${steps.reverse().join(', ')})` : ''}`;
45
65
  };
46
- return { node: rest, lost, place };
47
- };
48
- const plugin = () => {
49
- const outCtx = {};
50
- const docsMap = new Map();
51
- const onExit = ctx => ({ ...ctx, ...outCtx });
52
- const processNode = (node, recs) => {
53
- const rules = {
54
- // TODO: remove 'Include' due to duplicate to 'include'
55
- Include: written => {
56
- const { node, lost, place } = assignments(written);
57
- const { content } = node;
58
- const selector = getTextContentFromNode(content).trim();
59
- console.warn(`[include] start resolve selector: ${selector}`);
60
- if (selector) {
61
- // try to resolve selector
62
- const result = select(selector, recs, lost);
63
- if (!result)
64
- return node;
65
- const [block] = result;
66
- if (typeof block === 'object' && !('file' in block)) {
67
- const updated = { content: place([block])[0] };
68
- return { ...node, ...updated };
69
- }
70
- if (!block) {
71
- console.warn(`[plugin: resolve ] selector ${selector} not found`);
72
- place([]);
66
+ const stampOf = (where) => where.via ? { file: where.file, via: where.via } : { file: where.file };
67
+ // The file each node was written in goes onto the node itself, where a copy
68
+ // keeps it; the assembler's own table is lost on the first copy a plugin makes.
69
+ const stamp = (tree, origin) => {
70
+ const visit = (node) => {
71
+ if (Array.isArray(node))
72
+ return node.forEach(visit);
73
+ if (!isNode(node))
74
+ return;
75
+ const where = origin.get(node);
76
+ if (where && !node[nodeOriginKey])
77
+ node[nodeOriginKey] = stampOf(where);
78
+ const file = node[nodeOriginKey]?.file;
79
+ if (file && isNode(node.location))
80
+ fileAt.set(node.location, file);
81
+ visit(node.content);
82
+ };
83
+ visit(tree);
84
+ };
85
+ // what the nodes say of themselves is told to the assembler, so that a block an
86
+ // earlier pass brought is not taken for one of the record
87
+ const seed = (tree, origin) => {
88
+ const visit = (node) => {
89
+ if (Array.isArray(node))
90
+ return node.forEach(visit);
91
+ if (!isNode(node))
92
+ return;
93
+ const mark = node[nodeOriginKey];
94
+ if (mark)
95
+ origin.set(node, { file: mark.file, text: '', ...(mark.via ? { via: mark.via } : {}) });
96
+ visit(node.content);
97
+ };
98
+ visit(tree);
99
+ };
100
+ const run = (pass) => {
101
+ const outCtx = {};
102
+ const onExit = ctx => ({ ...ctx, ...outCtx });
103
+ const onProcess = (recs) => {
104
+ if (!options.catalogue && pass !== 'last') {
105
+ console.warn('[plugin: resolve ] no catalogue of the site is given; an include is looked for among the records at hand');
106
+ }
107
+ // a document a plugin made earlier in the chain is a source too
108
+ catalogue.add(recs);
109
+ waiting = pass === 'first';
110
+ const problems = [];
111
+ // directives already said why they are left in place
112
+ const told = new WeakSet();
113
+ const fail = (problem) => {
114
+ const at = problem.chain[problem.chain.length - 1]?.location;
115
+ if (at)
116
+ told.add(at);
117
+ problems.push(describe(problem));
118
+ };
119
+ const warn = (problem) => {
120
+ if (stopping.has(problem.kind))
121
+ fail(problem);
122
+ else
123
+ console.warn(`[plugin: resolve ] ${describe(problem)}`);
124
+ };
125
+ // a document placed last is placed as it is: an include in it would need a third pass
126
+ const lateFiles = new Set();
127
+ if (pass !== 'first') {
128
+ for (const name of late) {
129
+ for (const id of catalogue.named(name)) {
130
+ lateFiles.add(id);
131
+ const text = catalogue.textOf(id);
132
+ if (text !== undefined && nodesOf(readRecordText(text, id), 'include').length) {
133
+ problems.push(`${shown(id)}: ${name} is placed after the other plugins, so it may not hold an include`);
134
+ }
73
135
  }
74
136
  }
137
+ if (problems.length)
138
+ throw new IncludeError(problems);
139
+ }
140
+ // one field of a record, read from one file
141
+ const assemble = (tree, record) => {
142
+ if (typeof tree !== 'object' || tree === null)
143
+ return tree;
144
+ // the tables of contents are built again in the passes that place the record's
145
+ // own text; the last one only adds documents plugins made
146
+ if (!nodesOf(tree, 'include').length && (pass === 'last' || !hasToc(tree)))
147
+ return tree;
148
+ const self = catalogue.idOf(record);
149
+ const source = recordOrigin(record);
150
+ const file = self ?? idOfFile(record.file);
151
+ const origin = new WeakMap();
152
+ seed(tree, origin);
153
+ let node = assembleIncludes(tree, {
154
+ sources: catalogue.sources,
155
+ context: path.dirname(file),
156
+ parse: readRecordText,
157
+ file,
158
+ ...(source ? { text: source.text } : {}),
159
+ self,
160
+ origin,
161
+ reportCycles: true,
162
+ onError: fail,
163
+ onWarning: warn,
164
+ });
165
+ // the record's own tables of contents reach what the includes brought
166
+ const format = source && writtenFormat(source);
167
+ if (source && format && hasToc(node)) {
168
+ node = refreshTocs(node, writtenTree(parser, source.text, format), file, origin);
169
+ }
170
+ stamp(node, origin);
75
171
  return node;
76
- },
77
- include: written => {
78
- const { node, lost, place } = assignments(written);
79
- const { content } = node;
80
- const selector = getTextContentFromNode(content).trim();
81
- console.warn(`[include] start resolve selector: ${selector}`);
82
- if (selector) {
83
- const result = select(selector, recs, lost);
84
- if (!result)
85
- return node;
86
- const blocks = [];
87
- for (const item of result) {
88
- if (typeof item === 'object' && item !== null && !('file' in item)) {
89
- blocks.push(item);
172
+ };
173
+ // two records of one reading share their tree
174
+ const trees = new WeakMap();
175
+ const assembleTree = (record) => {
176
+ const known = trees.get(record.node);
177
+ if (known)
178
+ return known;
179
+ const made = assemble(record.node, record);
180
+ trees.set(record.node, made);
181
+ return made;
182
+ };
183
+ // a template is a record of the chain and is assembled as one; a template a record
184
+ // carries is left as it is, as the plugins of images and links leave it
185
+ const out = recs.map(record => {
186
+ const node = assembleTree(record);
187
+ const description = assemble(record.description, record);
188
+ const header = assemble(record.header, record);
189
+ const footer = assemble(record.footer, record);
190
+ const same = node === record.node &&
191
+ description === record.description &&
192
+ header === record.header &&
193
+ footer === record.footer;
194
+ return same ? record : { ...record, node, description, header, footer };
195
+ });
196
+ if (pass !== 'first') {
197
+ for (const record of out) {
198
+ for (const tree of [record.node, record.description, record.header, record.footer]) {
199
+ for (const left of nodesOf(tree, 'include')) {
200
+ if (left.location && told.has(left.location))
201
+ continue;
202
+ const file = left[nodeOriginKey]?.file ?? record.file;
203
+ const line = left.location ? `:${left.location.start.line}` : '';
204
+ problems.push(`${shown(file)}${line}: the include is left in place`);
205
+ }
206
+ // a picture or a link placed now comes after the plugins that make them work
207
+ for (const node of nodesOf(tree, () => true)) {
208
+ const from = node[nodeOriginKey]?.file;
209
+ if (!from || !lateFiles.has(from))
210
+ continue;
211
+ const what = node.type === 'image' ? 'a picture' : node.type === 'fcode' && node.name === 'L' ? 'a link' : '';
212
+ if (what)
213
+ problems.push(`${shown(from)}: ${what} is placed after the plugins that handle it`);
90
214
  }
91
215
  }
92
- if (blocks.length > 0) {
93
- return { ...node, content: place(outermost(blocks)) };
94
- }
95
- console.warn(`[plugin: resolve ] selector ${selector} not found`);
96
- place([]);
97
- }
98
- else if (lost) {
99
- console.warn(`[plugin: resolve ] include selector cannot be read: (empty)${lost}`);
100
216
  }
101
- return node;
102
- },
217
+ }
218
+ if (problems.length)
219
+ throw new IncludeError([...new Set(problems)]);
220
+ return out;
103
221
  };
104
- return makeInterator(rules)(node, {});
105
- };
106
- const onProcess = (recs) => {
107
- // convert all doc: links to file:: links
108
- const docsWithIncludesResolves = recs.map(item => {
109
- const node = processNode(item.node, recs);
110
- // const node = item.node
111
- return { ...item, node };
112
- });
113
- return docsWithIncludesResolves;
222
+ return [onProcess, onExit];
114
223
  };
115
- return [onProcess, onExit];
224
+ return { run, documents: (name) => catalogue.named(name) };
225
+ };
226
+ /*
227
+ =begin pod :kind<export>
228
+
229
+ =head2 includePasses
230
+
231
+ Gives the include plugin as two passes over one catalogue. C<first> goes before the
232
+ plugins of images, links and React and places all it can; an include of a
233
+ document a plugin makes later in the chain (the site data, and the names in
234
+ C<late>) waits there. C<last> goes after those plugins and places only such
235
+ documents. An include left after it stops the build. C<documents> gives the files
236
+ of the documents that answer to a name, for the links plugin to find a C<doc:>
237
+ link by the same names.
238
+
239
+ =end pod
240
+ */
241
+ export const includePasses = (options = {}) => {
242
+ const { run, documents } = passes(options);
243
+ return { first: run('first'), last: run('last'), documents };
116
244
  };
245
+ // One pass over the records: nothing waits, and an include that does not place
246
+ // what it names stops the build.
247
+ const plugin = (options = {}) => passes(options).run('only');
117
248
  export default plugin;
118
249
  //# sourceMappingURL=include-resolve-plugin.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"include-resolve-plugin.js","sourceRoot":"","sources":["../src/include-resolve-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,sBAAsB,EAAa,aAAa,EAAW,MAAM,iBAAiB,CAAA;AAGnH,OAAO,EAAE,eAAe,EAAc,SAAS,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AACvF,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAErD,8EAA8E;AAC9E,kEAAkE;AAClE,MAAM,MAAM,GAAG,CAAC,QAAgB,EAAE,IAAqB,EAAE,IAAI,GAAG,EAAE,EAAE,EAAE;IACpE,4EAA4E;IAC5E,qBAAqB;IACrB,MAAM,MAAM,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAA;IACtC,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,CAAC,IAAI,CAAC,+BAA+B,QAAQ,kBAAkB,IAAI,EAAE,CAAC,CAAA;QAC7E,OAAO,IAAI,CAAA;IACb,CAAC;IACD,IAAI,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,KAAK,KAAK,IAAI,MAAM,CAAC,MAAM,KAAK,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AI,KAAK,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAA;4BAClG,IAAI,IAAI;gCAAE,QAAQ,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,IAAI,6CAA6C,CAAC,CAAA;wBAC/F,CAAC;oBACH,CAAC;gBACH,CAAC;YACH,CAAC;YACD,IAAI,QAAQ,CAAC,MAAM;gBAAE,MAAM,IAAI,YAAY,CAAC,CAAC,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAA;YACnE,OAAO,GAAG,CAAA;QACZ,CAAC,CAAA;QACD,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,CAAA;IAC5B,CAAC,CAAA;IACD,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAA;AACpE,CAAC,CAAA;AAED;;;;;;;;;;;;;;EAcE;AACF,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,UAAiC,EAAE,EACyD,EAAE;IAC9F,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC,OAAO,CAAC,CAAA;IAC1C,OAAO,EAAE,KAAK,EAAE,GAAG,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,CAAA;AAC9D,CAAC,CAAA;AAED,+EAA+E;AAC/E,iCAAiC;AACjC,MAAM,MAAM,GAAG,CAAC,UAAiC,EAAE,EAAoB,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;AACrG,eAAe,MAAM,CAAA"}
@@ -1,3 +1,11 @@
1
1
  import { PodliteWebPlugin } from './plugins';
2
- declare const plugin: () => PodliteWebPlugin;
2
+ export type LinksOptions = {
3
+ documents?: (name: string) => string[];
4
+ home?: string;
5
+ };
6
+ export declare class LinkError extends Error {
7
+ readonly problems: string[];
8
+ constructor(problems: string[]);
9
+ }
10
+ declare const plugin: (options?: LinksOptions) => PodliteWebPlugin;
3
11
  export default plugin;
@@ -1,84 +1,170 @@
1
- import { getTextContentFromNode, makeAttrs, makeInterator } from '@podlite/schema';
2
- import { convertFileLinksToUrl, getPathToOpen } from './node-utils.js';
3
- const plugin = () => {
1
+ import * as path from 'path';
2
+ import { bindTarget, buildBindingIndex, getTextContentFromNode, indexAnchors, makeAttrs, makeInterator, sameDocTarget, } from '@podlite/schema';
3
+ import { convertFileLinksToUrl, getPathToOpen, isIndexed } from './node-utils.js';
4
+ import { nodeOrigin, recordOrigin } from './source.js';
5
+ /*
6
+ =begin pod :kind<export>
7
+
8
+ =head2 LinkError
9
+
10
+ A C<doc:> link whose name no published document answers to, or that two
11
+ documents answer to, stops the build. C<problems> holds one line for each.
12
+
13
+ =end pod
14
+ */
15
+ export class LinkError extends Error {
16
+ problems;
17
+ constructor(problems) {
18
+ super(`a link does not resolve:\n${problems.map(line => ` ${line}`).join('\n')}`);
19
+ this.name = 'LinkError';
20
+ this.problems = problems;
21
+ }
22
+ }
23
+ const isNode = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
24
+ const shown = (file) => (path.isAbsolute(file) ? path.relative(process.cwd(), file) : file);
25
+ // the file a record was read from, or cut out of
26
+ const fileOf = (record) => path.resolve(recordOrigin(record)?.file ?? record.file);
27
+ const plugin = (options = {}) => {
4
28
  const outCtx = {};
5
- const docsMap = new Map();
6
29
  const onExit = ctx => ({ ...ctx, ...outCtx });
7
- const processNode = (node, srcfile) => {
8
- const rules = {
9
- 'L<>': node => {
10
- const { content, meta } = node;
11
- const link = meta ? meta : getTextContentFromNode(content);
12
- const r = link.match(/doc:\s*(?<path>(.+))\s*$/);
13
- if (r?.groups?.path) {
14
- const docLink = r.groups.path;
15
- const { isRemote } = getPathToOpen(docLink, srcfile);
16
- if (isRemote) {
17
- return node;
18
- }
19
- let title;
20
- let url;
21
- if (!docsMap.has(docLink)) {
22
- console.error(`doc: ${docLink} not found`);
23
- title = `doc: ${docLink} not found`;
24
- url = `doc: ${docLink} not found`;
25
- }
26
- else {
27
- const { title: title1, url: url1 } = docsMap.get(docLink);
28
- title = title1;
29
- url = url1;
30
- }
31
- const newContent = {
32
- type: 'text',
33
- value: `${title}`,
34
- };
35
- const updated = meta ? { meta: url } : { content: newContent, meta: url };
36
- return { ...node, ...updated };
37
- }
38
- return node;
39
- },
40
- };
41
- return makeInterator(rules)(node, {});
42
- };
43
30
  const onProcess = (recs) => {
44
- // const collectlinksMap = makeLinksMap(recs)
45
- // collects docsMap map doc: to file
46
- for (const item of recs) {
47
- // get =TITLE
31
+ // the records that answer to each name, with the text of the block that names them
32
+ const named = new Map();
33
+ for (const record of recs) {
48
34
  const handler = node => {
35
+ // a name an include brought belongs to the document it was written in
36
+ const from = nodeOrigin(node)?.file;
37
+ if (from !== undefined && path.resolve(from) !== fileOf(record))
38
+ return;
49
39
  const conf = makeAttrs(node, {});
50
40
  const title = getTextContentFromNode(node).trim();
51
- if (conf.exists('id')) {
52
- const id = conf.getFirstValue('id');
53
- if (id) {
54
- docsMap.set(id, { file: item.file, title, url: item.publishUrl });
55
- }
41
+ const id = conf.exists('id') ? conf.getFirstValue('id') : undefined;
42
+ for (const name of new Set([id, title].filter(Boolean))) {
43
+ named.set(name, [...(named.get(name) ?? []), { record, title }]);
56
44
  }
57
- docsMap.set(title, { file: item.file, title, url: item.publishUrl });
58
45
  };
59
- makeInterator({
60
- NAME: handler,
61
- TITLE: handler,
62
- })(item.node, {});
46
+ makeInterator({ NAME: handler, TITLE: handler })(record.node, {});
63
47
  }
48
+ const problems = [];
49
+ // the address a page gives a section, by the rule the page is drawn with: empty
50
+ // for the block that names the document, which is the page itself
51
+ const addressIn = (record, section) => {
52
+ const bindings = buildBindingIndex(record.node);
53
+ const bound = bindTarget(section, bindings);
54
+ if (bound.found && isNode(bound.node) && (bound.node.name === 'NAME' || bound.node.name === 'TITLE'))
55
+ return '';
56
+ return sameDocTarget(`#${section}`, { __bindings: bindings, __anchors: indexAnchors(record.node) });
57
+ };
58
+ const home = options.home === undefined ? undefined : path.resolve(options.home);
59
+ const addressOf = (record) => record.publishUrl || (home !== undefined && path.resolve(record.file) === home ? '/' : '');
60
+ // the title and the address a name links to: of one document, at the place a
61
+ // search engine is told to index when it is published at more than one
62
+ const resolve = (name, section, at) => {
63
+ // a link has no place of its own; `at` is where the paragraph holding it starts
64
+ const written = section === undefined ? name : `${name}#${section}`;
65
+ const answering = (named.get(name) ?? []).filter(({ record }) => Boolean(addressOf(record)));
66
+ const files = options.documents
67
+ ? options.documents(name).map(file => path.resolve(file))
68
+ : [...new Set(answering.map(({ record }) => fileOf(record)))];
69
+ if (files.length > 1) {
70
+ problems.push(`${at}: a link in the text from this line, doc:${written}: more than one document is named ${name}: ${files
71
+ .map(shown)
72
+ .join(', ')}`);
73
+ return undefined;
74
+ }
75
+ const placed = answering.filter(({ record }) => fileOf(record) === files[0]);
76
+ if (!placed.length) {
77
+ problems.push(`${at}: a link in the text from this line, doc:${written}: no published document is named ${name}`);
78
+ return undefined;
79
+ }
80
+ const indexed = placed.filter(({ record }) => isIndexed(record));
81
+ const { record, title } = (indexed.length ? indexed : placed)[(indexed.length ? indexed : placed).length - 1];
82
+ const url = addressOf(record);
83
+ if (section === undefined)
84
+ return { title, url };
85
+ // a section is the block the page gives that address to, by the rule the page is drawn with
86
+ const anchor = addressIn(record, section);
87
+ if (anchor === undefined) {
88
+ problems.push(`${at}: a link in the text from this line, doc:${written}: ${name} has no section ${section}`);
89
+ return undefined;
90
+ }
91
+ return { title, url: `${url}${anchor}` };
92
+ };
93
+ const processNode = (node, srcfile, page) => {
94
+ // the line the paragraph or block holding each link starts at
95
+ const lines = new WeakMap();
96
+ const mark = (tree, line) => {
97
+ if (Array.isArray(tree))
98
+ return tree.forEach(child => mark(child, line));
99
+ if (!isNode(tree))
100
+ return;
101
+ const here = (tree.type === 'block' || tree.type === 'para') && tree.location ? tree.location.start.line : line;
102
+ if (tree.type === 'fcode' && tree.name === 'L' && here !== undefined)
103
+ lines.set(tree, here);
104
+ mark(tree.content, here);
105
+ };
106
+ mark(node);
107
+ const rules = {
108
+ 'L<>': node => {
109
+ const { content, meta } = node;
110
+ const link = meta ? meta : getTextContentFromNode(content);
111
+ const r = link.match(/doc:\s*(?<path>(.+))\s*$/);
112
+ if (r?.groups?.path) {
113
+ const docLink = r.groups.path;
114
+ const from = nodeOrigin(node)?.file ?? srcfile;
115
+ const { isRemote } = getPathToOpen(docLink, from);
116
+ if (isRemote) {
117
+ return node;
118
+ }
119
+ const line = lines.get(node);
120
+ const at = `${shown(from)}${line !== undefined ? `:${line}` : ''}`;
121
+ // a section of the document is addressed after its name, of this page without one
122
+ const [name, ...section] = docLink.split('#');
123
+ const local = (written) => {
124
+ const anchor = addressIn(page, written);
125
+ if (anchor !== undefined)
126
+ return { title: written, url: anchor || '#' };
127
+ problems.push(`${at}: a link in the text from this line, doc:#${written}: the page has no section ${written}`);
128
+ return undefined;
129
+ };
130
+ const found = name === '' && section.length
131
+ ? local(section.join('#'))
132
+ : resolve(name, section.length ? section.join('#') : undefined, at);
133
+ if (!found)
134
+ return node;
135
+ const { url } = found;
136
+ const newContent = {
137
+ type: 'text',
138
+ value: `${found.title}`,
139
+ };
140
+ const updated = meta ? { meta: url } : { content: newContent, meta: url };
141
+ return { ...node, ...updated };
142
+ }
143
+ return node;
144
+ },
145
+ };
146
+ return makeInterator(rules)(node, {});
147
+ };
64
148
  // convert all doc: links to file:: links
65
149
  const docToFileLinksConverted = recs.map(item => {
66
- const node = processNode(item.node, item.file);
150
+ const node = processNode(item.node, item.file, item);
67
151
  // process images inside description
68
152
  let extra = {};
69
153
  if (item.description) {
70
- extra.description = processNode(item.description, item.file);
154
+ extra.description = processNode(item.description, item.file, item);
71
155
  }
72
156
  // process file header and footer
73
157
  const { footer, header } = item;
74
158
  if (footer) {
75
- extra.footer = processNode(footer, item.file);
159
+ extra.footer = processNode(footer, item.file, item);
76
160
  }
77
161
  if (header) {
78
- extra.header = processNode(header, item.file);
162
+ extra.header = processNode(header, item.file, item);
79
163
  }
80
164
  return { ...item, node, ...extra };
81
165
  });
166
+ if (problems.length)
167
+ throw new LinkError([...new Set(problems)]);
82
168
  return convertFileLinksToUrl(docToFileLinksConverted);
83
169
  };
84
170
  return [onProcess, onExit];