@podlite/schema 0.0.70 → 0.0.71

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 (97) hide show
  1. package/CHANGELOG.podlite +82 -0
  2. package/esm/ast-helpers.d.ts +11 -0
  3. package/esm/ast-helpers.js +277 -25
  4. package/esm/ast-helpers.js.map +1 -1
  5. package/esm/block-names.d.ts +2 -2
  6. package/esm/block-names.js +7 -0
  7. package/esm/block-names.js.map +1 -1
  8. package/esm/blocks-helpers.d.ts +1 -1
  9. package/esm/blocks-helpers.js +3 -1
  10. package/esm/blocks-helpers.js.map +1 -1
  11. package/esm/exportHtml.js +85 -28
  12. package/esm/exportHtml.js.map +1 -1
  13. package/esm/exportMarkdown.js +112 -27
  14. package/esm/exportMarkdown.js.map +1 -1
  15. package/esm/grammar.js +588 -454
  16. package/esm/grammar.js.map +1 -1
  17. package/esm/guard.js +11 -1
  18. package/esm/guard.js.map +1 -1
  19. package/esm/helpers/blockName.d.ts +8 -0
  20. package/esm/helpers/blockName.js +60 -0
  21. package/esm/helpers/blockName.js.map +1 -0
  22. package/esm/helpers/configPropagation.d.ts +12 -2
  23. package/esm/helpers/configPropagation.js +51 -13
  24. package/esm/helpers/configPropagation.js.map +1 -1
  25. package/esm/helpers/corePlugins.d.ts +1 -1
  26. package/esm/helpers/corePlugins.js +4 -2
  27. package/esm/helpers/corePlugins.js.map +1 -1
  28. package/esm/helpers/makeInterator.js +3 -2
  29. package/esm/helpers/makeInterator.js.map +1 -1
  30. package/esm/index.d.ts +13 -3
  31. package/esm/index.js +15 -5
  32. package/esm/index.js.map +1 -1
  33. package/esm/pluggableParser.d.ts +6 -2
  34. package/esm/pluggableParser.js +5 -5
  35. package/esm/pluggableParser.js.map +1 -1
  36. package/esm/plugin-data-table.js +4 -5
  37. package/esm/plugin-data-table.js.map +1 -1
  38. package/esm/plugin-formatting-codes.js +65 -24
  39. package/esm/plugin-formatting-codes.js.map +1 -1
  40. package/esm/plugin-set.js +15 -18
  41. package/esm/plugin-set.js.map +1 -1
  42. package/esm/plugin-tables.js +6 -1
  43. package/esm/plugin-tables.js.map +1 -1
  44. package/esm/selectors.d.ts +25 -8
  45. package/esm/selectors.js +398 -141
  46. package/esm/selectors.js.map +1 -1
  47. package/esm/set-assign.d.ts +17 -0
  48. package/esm/set-assign.js +143 -0
  49. package/esm/set-assign.js.map +1 -0
  50. package/esm/test-display.d.ts +3 -0
  51. package/esm/test-display.js +58 -0
  52. package/esm/test-display.js.map +1 -0
  53. package/esm/toc-caption.d.ts +7 -0
  54. package/esm/toc-caption.js +23 -0
  55. package/esm/toc-caption.js.map +1 -0
  56. package/esm/types.d.ts +16 -1
  57. package/esm/version.d.ts +1 -1
  58. package/esm/version.js +1 -1
  59. package/lib/ast-helpers.d.ts +11 -0
  60. package/lib/ast-helpers.js +279 -26
  61. package/lib/block-names.d.ts +2 -2
  62. package/lib/block-names.js +7 -0
  63. package/lib/blocks-helpers.d.ts +1 -1
  64. package/lib/blocks-helpers.js +3 -1
  65. package/lib/exportHtml.js +84 -27
  66. package/lib/exportMarkdown.js +111 -26
  67. package/lib/grammar.js +588 -454
  68. package/lib/guard.js +11 -1
  69. package/lib/helpers/blockName.d.ts +8 -0
  70. package/lib/helpers/blockName.js +66 -0
  71. package/lib/helpers/configPropagation.d.ts +12 -2
  72. package/lib/helpers/configPropagation.js +54 -14
  73. package/lib/helpers/corePlugins.d.ts +1 -1
  74. package/lib/helpers/corePlugins.js +4 -2
  75. package/lib/helpers/makeInterator.js +3 -2
  76. package/lib/index.d.ts +13 -3
  77. package/lib/index.js +30 -5
  78. package/lib/pluggableParser.d.ts +6 -2
  79. package/lib/pluggableParser.js +5 -5
  80. package/lib/plugin-data-table.js +4 -5
  81. package/lib/plugin-formatting-codes.js +65 -24
  82. package/lib/plugin-set.js +15 -18
  83. package/lib/plugin-tables.js +6 -1
  84. package/lib/selectors.d.ts +25 -8
  85. package/lib/selectors.js +401 -141
  86. package/lib/set-assign.d.ts +17 -0
  87. package/lib/set-assign.js +150 -0
  88. package/lib/test-display.d.ts +3 -0
  89. package/lib/test-display.js +67 -0
  90. package/lib/toc-caption.d.ts +7 -0
  91. package/lib/toc-caption.js +27 -0
  92. package/lib/types.d.ts +16 -1
  93. package/lib/version.d.ts +1 -1
  94. package/lib/version.js +1 -1
  95. package/package.json +1 -1
  96. package/schema/AstTree.json +160 -0
  97. package/schema/PodliteDocument.json +160 -0
@@ -3,9 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.makeAttrs = exports.getExplicitNodeId = exports.getSafeNodeId = exports.bindTarget = exports.buildBindingIndex = exports.writtenValue = exports.linkTarget = exports.sameDocTarget = exports.resolveFragment = exports.findAnchor = exports.restyleAnchors = exports.indexAnchors = exports.markdownStyle = exports.htmlStyle = exports.toMarkdownFragment = exports.toFragment = exports.getNodeId = void 0;
6
+ exports.makeAttrs = exports.getExplicitNodeId = exports.getSafeNodeId = exports.bindTarget = exports.buildBindingIndex = exports.writtenValue = exports.linkTarget = exports.sameDocTarget = exports.resolveFragment = exports.findAnchor = exports.readerAnchors = exports.restyleAnchors = exports.indexAnchors = exports.markdownStyle = exports.htmlStyle = exports.toMarkdownFragment = exports.toFragment = exports.getNodeId = void 0;
7
+ const entities_1 = require("entities");
7
8
  const _1 = require(".");
8
9
  const config_1 = __importDefault(require("./helpers/config"));
10
+ const handlers_1 = require("./helpers/handlers");
9
11
  const getNodeId = (node, ctx) => {
10
12
  const conf = (0, config_1.default)(node, ctx);
11
13
  if (conf.exists('id')) {
@@ -51,6 +53,99 @@ const takeUnique = (fragment, taken, firstRepeat) => {
51
53
  taken.set(result, taken.get(result) || 0);
52
54
  return result;
53
55
  };
56
+ const decodeEntities = (content) => Array.isArray(content)
57
+ ? content
58
+ .map((element) => {
59
+ if (element?.type === 'number' && typeof element.value === 'number')
60
+ return String.fromCharCode(element.value);
61
+ if (element?.type === 'html_named' && typeof element.value === 'string')
62
+ return (0, entities_1.decodeHTMLStrict)(`&${element.value};`);
63
+ return '';
64
+ })
65
+ .join('')
66
+ : '';
67
+ // The text the markdown output puts into a heading, as a reader sees it. Hidden parts
68
+ // come out masked when the output masks them, and G<> masks everything written inside
69
+ // it at once. The markdown export writes nothing for E<> and Z<>, a footnote as its
70
+ // number, and S<> with unbreakable spaces, which a reader drops from the address.
71
+ const markdownText = (node, masked, footnotes, covered = false) => {
72
+ if (typeof node === 'string')
73
+ return covered && masked ? (0, handlers_1.maskText)(node) : node;
74
+ if (Array.isArray(node))
75
+ return node.map(child => markdownText(child, masked, footnotes, covered)).join('');
76
+ if (!node || typeof node !== 'object')
77
+ return '';
78
+ const n = node;
79
+ const hidden = covered || n.guarded === true;
80
+ if (n.type === 'fcode') {
81
+ if (n.name === 'G' && masked)
82
+ return (0, handlers_1.maskText)((0, handlers_1.collectText)(n.content));
83
+ if (n.name === 'E' || n.name === 'Z')
84
+ return '';
85
+ if (n.name === 'N')
86
+ return String(footnotes.get(node) ?? '');
87
+ if (n.name === 'S')
88
+ return markdownText(n.content, masked, footnotes, hidden).replace(/ /g, '\u00a0');
89
+ }
90
+ if ((n.type === 'text' || n.type === 'verbatim') && typeof n.value === 'string')
91
+ return hidden && masked ? (0, handlers_1.maskText)(n.value) : n.value;
92
+ return markdownText(n.content, masked, footnotes, hidden);
93
+ };
94
+ // Footnotes are numbered in the order the markdown export meets them in the text. It
95
+ // writes nothing for a comment or a data block, reaches a footnote inside another one
96
+ // only when the notes are written at the end, and in production a G<> writes its text
97
+ // masked and never reaches a footnote inside it. Only footnotes of the text are
98
+ // numbered here: a heading holds no note written at the end.
99
+ const numberFootnotes = (tree) => {
100
+ const footnotes = { production: new Map(), draft: new Map() };
101
+ const visit = (node, insideGuard) => {
102
+ if (Array.isArray(node))
103
+ return node.forEach(child => visit(child, insideGuard));
104
+ if (!node || typeof node !== 'object')
105
+ return;
106
+ const n = node;
107
+ if (n.type === 'block' && (n.name === 'comment' || n.name === 'data'))
108
+ return;
109
+ if (n.type === 'fcode' && n.name === 'N') {
110
+ if (Array.isArray(n.content) && n.content.length > 0) {
111
+ footnotes.draft.set(node, footnotes.draft.size + 1);
112
+ if (!insideGuard)
113
+ footnotes.production.set(node, footnotes.production.size + 1);
114
+ }
115
+ return;
116
+ }
117
+ visit(n.content, insideGuard || (n.type === 'fcode' && n.name === 'G'));
118
+ };
119
+ visit(tree, false);
120
+ return footnotes;
121
+ };
122
+ // A block named in capitals comes out of the markdown export under a heading of its name.
123
+ const isSemanticBlock = (node) => node.type === 'block' &&
124
+ typeof node.name === 'string' &&
125
+ node.name === node.name.toUpperCase() &&
126
+ /\p{Lu}/u.test(node.name);
127
+ const hiddenPart = (node, covered = false) => {
128
+ if (typeof node === 'string')
129
+ return covered ? node : '';
130
+ if (Array.isArray(node))
131
+ return node.map(child => hiddenPart(child, covered)).join('');
132
+ if (!node || typeof node !== 'object')
133
+ return '';
134
+ const n = node;
135
+ const hidden = covered || n.guarded === true;
136
+ if (n.type === 'fcode' && n.name === 'E')
137
+ return hidden ? decodeEntities(n.content) : '';
138
+ if ((n.type === 'text' || n.type === 'verbatim') && typeof n.value === 'string')
139
+ return hidden ? n.value : '';
140
+ return hiddenPart(n.content, hidden);
141
+ };
142
+ // A heading hides something when a covered part of it shows a character. G<> with
143
+ // nothing inside, or with a space, hides nothing and leaves the address alone.
144
+ const hidesText = (node) => /\S/.test(hiddenPart(node));
145
+ const hasExplicitId = (node) => !!node && typeof node === 'object' && (0, config_1.default)(node, {}).exists('id');
146
+ // A heading whose address is not made of its text: the author named it, or its text
147
+ // is hidden. The markdown reader cannot give it that address, so the export writes one.
148
+ const hasOwnAddress = (node) => hasExplicitId(node) || hidesText(node);
54
149
  const walkNodes = (node, visit) => {
55
150
  if (Array.isArray(node)) {
56
151
  for (const child of node)
@@ -63,37 +158,177 @@ const walkNodes = (node, visit) => {
63
158
  if ('content' in node)
64
159
  walkNodes(node.content, visit);
65
160
  };
66
- const assignAnchors = (heads, style) => {
161
+ // A heading with hidden text gets a name made of nothing it hides, and it takes no
162
+ // place in the numbering of repeats: otherwise the number of an open neighbour would
163
+ // say that a hidden heading above carries the same name.
164
+ const assignAnchors = (heads, style, reserved = new Set()) => {
67
165
  const byNode = new Map();
68
166
  const byName = new Map();
69
167
  const taken = new Map();
168
+ const hidden = [];
70
169
  for (const node of heads) {
170
+ if (!hasExplicitId(node) && hidesText(node)) {
171
+ // held in document order; the name comes once the open headings have theirs
172
+ byNode.set(node, '');
173
+ hidden.push(node);
174
+ continue;
175
+ }
71
176
  const id = (0, exports.getNodeId)(node, {});
72
177
  if (id == null)
73
178
  continue;
74
179
  const name = id.toString();
75
180
  const anchor = takeUnique(style.shape(name), taken, style.firstRepeat);
76
181
  byNode.set(node, anchor);
77
- if (!byName.has(name))
182
+ if (!hidesText(node) && !byName.has(name))
78
183
  byName.set(name, anchor);
79
184
  }
80
- return { byNode, byName, shape: style.shape };
185
+ // A markdown reader folds case, so a generated name is kept clear of every name in
186
+ // any case: the same name then serves both outputs.
187
+ const inUse = new Set([...taken.keys(), ...reserved].map(name => name.toLowerCase()));
188
+ let count = 0;
189
+ for (const node of hidden) {
190
+ let anchor = '';
191
+ do
192
+ anchor = style.shape(`masked-${++count}`);
193
+ while (inUse.has(anchor.toLowerCase()));
194
+ inUse.add(anchor.toLowerCase());
195
+ taken.set(anchor, 0);
196
+ byNode.set(node, anchor);
197
+ }
198
+ return { byNode, byName, shape: style.shape, reserved };
199
+ };
200
+ // The addresses a markdown reader builds out of the headings as the page shows them,
201
+ // their numbers included, counting repeats over every heading the way github-slugger
202
+ // does: an empty name takes a place as well.
203
+ const readerSlugs = (headings, masked, footnotes) => {
204
+ const numbers = (masked ? footnotes?.production : footnotes?.draft) || new Map();
205
+ const occurrences = new Map();
206
+ const slugs = [];
207
+ for (const node of headings) {
208
+ const n = node;
209
+ const prefix = n.numberPrefix;
210
+ const text = n.name === 'head'
211
+ ? `${prefix ? `${prefix} ` : ''}${markdownText(n.content, masked, numbers)}`.trim()
212
+ : n.guarded === true && masked
213
+ ? (0, handlers_1.maskText)(String(n.name))
214
+ : String(n.name);
215
+ const base = (0, exports.toMarkdownFragment)(text);
216
+ let slug = base;
217
+ while (occurrences.has(slug)) {
218
+ const count = (occurrences.get(base) || 0) + 1;
219
+ occurrences.set(base, count);
220
+ slug = `${base}-${count}`;
221
+ }
222
+ occurrences.set(slug, 0);
223
+ slugs.push(slug);
224
+ }
225
+ return slugs;
81
226
  };
82
227
  // Anchors are handed out in one walk before rendering. A renderer asks for the
83
228
  // same heading more than once — the numbering would run away — and a link may
84
229
  // stand before the heading it points to, so both need the whole tree first.
85
230
  const indexAnchors = (tree, style = exports.htmlStyle) => {
86
231
  const heads = [];
232
+ const pageHeadings = [];
233
+ const reserved = new Set();
87
234
  walkNodes(tree, node => {
88
- if (node.name === 'head')
235
+ if (node.name === 'head') {
89
236
  heads.push(node);
237
+ pageHeadings.push(node);
238
+ return;
239
+ }
240
+ if (isSemanticBlock(node))
241
+ pageHeadings.push(node);
242
+ if (hasExplicitId(node)) {
243
+ const written = (0, config_1.default)(node, {}).getFirstValue('id');
244
+ if (written != null)
245
+ reserved.add(style.shape(String(written)));
246
+ }
90
247
  });
91
- return assignAnchors(heads, style);
248
+ // what a markdown reader will build, so a generated name never lands on a heading
249
+ // the reader addresses the same way. Only the masked page is read: the draft one is
250
+ // made of the hidden text, and the name must not depend on it.
251
+ const footnotes = numberFootnotes(tree);
252
+ for (const slug of readerSlugs(pageHeadings, true, footnotes))
253
+ reserved.add(slug);
254
+ return { ...assignAnchors(heads, style, reserved), pageHeadings, footnotes };
92
255
  };
93
256
  exports.indexAnchors = indexAnchors;
94
257
  // The same headings in the same order, shaped for another output.
95
- const restyleAnchors = (index, style) => index && assignAnchors(index.byNode.keys(), style);
258
+ const restyleAnchors = (index, style) => index && {
259
+ ...assignAnchors(index.byNode.keys(), style, index.reserved),
260
+ pageHeadings: index.pageHeadings,
261
+ footnotes: index.footnotes,
262
+ };
96
263
  exports.restyleAnchors = restyleAnchors;
264
+ /*
265
+ =begin pod :kind<export>
266
+
267
+ =head2 readerAnchors
268
+
269
+ The addresses of headings in markdown output. A markdown reader builds each address
270
+ itself, out of the heading as the page shows it, so these are the addresses it will
271
+ build: the text of the heading with its number, hidden parts masked unless the mode
272
+ is C<draft>, repeats counted the way github-slugger counts them, blocks named in
273
+ capitals included, since the export writes a heading for each.
274
+
275
+ A heading the reader cannot address that way keeps the address the html output gave
276
+ it, and C<named> lists it: a hidden heading, one with an explicit C<:id>, and one
277
+ whose built address would fall on such an address. The export writes a named anchor
278
+ before each of them.
279
+
280
+ =end pod
281
+ */
282
+ const readerAnchors = (index, renderMode) => {
283
+ if (!index)
284
+ return index;
285
+ const headings = index.pageHeadings || [...index.byNode.keys()];
286
+ const slugs = readerSlugs(headings, renderMode !== 'draft', index.footnotes);
287
+ const slugOf = new Map();
288
+ headings.forEach((node, at) => slugOf.set(node, slugs[at]));
289
+ const named = new Set([...index.byNode.keys()].filter(hasOwnAddress));
290
+ const namedAddresses = () => new Set([...named].map(node => (index.byNode.get(node) || '').toLowerCase()));
291
+ for (let changed = true; changed;) {
292
+ changed = false;
293
+ const taken = namedAddresses();
294
+ for (const node of index.byNode.keys()) {
295
+ if (named.has(node) || !taken.has((slugOf.get(node) || '').toLowerCase()))
296
+ continue;
297
+ named.add(node);
298
+ changed = true;
299
+ }
300
+ }
301
+ const byNode = new Map();
302
+ const byName = new Map();
303
+ const namesGiven = new Set();
304
+ for (const [node, ownAddress] of index.byNode) {
305
+ // lowercased: a reader such as GitHub finds a named anchor by the lowercased
306
+ // address, and one written in capitals is not reached. Two addresses apart only
307
+ // by case would then meet, so a repeat gets a number, as the reader numbers slugs.
308
+ let anchor = slugOf.get(node) || '';
309
+ if (named.has(node)) {
310
+ const base = ownAddress.toLowerCase();
311
+ anchor = base;
312
+ for (let count = 1; namesGiven.has(anchor);)
313
+ anchor = `${base}-${++count}`;
314
+ namesGiven.add(anchor);
315
+ }
316
+ byNode.set(node, anchor);
317
+ const id = (0, exports.getNodeId)(node, {});
318
+ if (id != null && !hidesText(node) && !byName.has(id.toString()))
319
+ byName.set(id.toString(), anchor);
320
+ }
321
+ return {
322
+ byNode,
323
+ byName,
324
+ shape: exports.toMarkdownFragment,
325
+ reserved: index.reserved,
326
+ pageHeadings: headings,
327
+ named,
328
+ footnotes: index.footnotes,
329
+ };
330
+ };
331
+ exports.readerAnchors = readerAnchors;
97
332
  // Exact name first, then without regard to case: a link copied from markdown
98
333
  // carries a lowercased target, and one written by hand carries the name itself.
99
334
  const findAnchor = (target, index) => {
@@ -125,6 +360,10 @@ const sameDocTarget = (target, ctx, index = ctx?.__anchors) => {
125
360
  const bound = (0, exports.bindTarget)(target.slice(1), bindings);
126
361
  if (!bound.found)
127
362
  return undefined;
363
+ // level one has named the node; its address is the one this output gave it
364
+ const anchor = index?.byNode.get(bound.node);
365
+ if (anchor !== undefined)
366
+ return `#${anchor}`;
128
367
  return `#${bound.via === 'heading' ? (0, exports.resolveFragment)(bound.key, index) : shape(bound.key)}`;
129
368
  }
130
369
  return `#${(0, exports.resolveFragment)(target.slice(1), index)}`;
@@ -175,35 +414,45 @@ const buildBindingIndex = (tree, style = exports.htmlStyle) => {
175
414
  if (via === 'explicit-id' && known.via !== 'explicit-id')
176
415
  byKey.set(key, { node, via });
177
416
  };
417
+ const written = [];
418
+ const handedOut = [];
419
+ const shapedForms = [];
178
420
  walkNodes(tree, node => {
179
421
  // The raw value the author wrote, and the form the anchor takes: getExplicitNodeId
180
422
  // already turns whitespace into a hyphen, so a link written the way the id was
181
423
  // written would otherwise miss it.
182
- const written = (0, config_1.default)(node, {}).exists('id') ? (0, config_1.default)(node, {}).getFirstValue('id') : null;
183
- const explicit = (0, exports.getExplicitNodeId)(node, {});
184
- for (const key of [written == null ? null : String(written), explicit]) {
185
- if (key)
186
- put(key.normalize('NFC').trim(), node, 'explicit-id');
424
+ const raw = (0, config_1.default)(node, {}).exists('id') ? (0, config_1.default)(node, {}).getFirstValue('id') : null;
425
+ // :id with no value reads as the flag true, which is not a name the author wrote
426
+ if (typeof raw !== 'boolean') {
427
+ const explicit = (0, exports.getExplicitNodeId)(node, {});
428
+ for (const key of [raw == null ? null : String(raw), explicit]) {
429
+ if (key)
430
+ written.push([key.normalize('NFC').trim(), node, 'explicit-id']);
431
+ }
187
432
  }
188
433
  if (node.name !== 'head')
189
434
  return;
190
435
  const name = (0, _1.getTextContentFromNode)(node).normalize('NFC').trim();
191
- put(name, node, 'heading');
192
- // A heading answers to its own name and to the form an output would give it: a
193
- // link copied out of a rendered page carries the shaped name, and the author who
194
- // pastes it means the same section. Both keys name one node, so this is a second
195
- // name for the target rather than resolution decided by shaping.
436
+ written.push([name, node, 'heading']);
437
+ // The anchor actually handed out, which carries the number when a name repeats: a
438
+ // link written against the second «Parameters» asks for Parameters-2, and only the
439
+ // assignment knows that.
440
+ const assigned = anchors.byNode.get(node);
441
+ if (assigned)
442
+ handedOut.push([assigned, node, 'heading']);
443
+ // A heading also answers to the form an output would give it: a link copied out of
444
+ // a rendered page carries the shaped name, and the author who pastes it means the
445
+ // same section. Both keys name one node, so this is a second name for the target
446
+ // rather than resolution decided by shaping.
196
447
  for (const shaped of [(0, exports.toFragment)(name), (0, exports.toMarkdownFragment)(name)]) {
197
448
  if (shaped && shaped !== name)
198
- put(shaped, node, 'heading');
449
+ shapedForms.push([shaped, node, 'heading']);
199
450
  }
200
- // And the anchor actually handed out, which carries the number when a name
201
- // repeats: a link written against the second «Parameters» asks for Parameters-2,
202
- // and only the assignment knows that.
203
- const assigned = anchors.byNode.get(node);
204
- if (assigned)
205
- put(assigned, node, 'heading');
206
451
  });
452
+ for (const layer of [written, handedOut, shapedForms]) {
453
+ for (const [key, node, via] of layer)
454
+ put(key, node, via);
455
+ }
207
456
  return { byKey, ambiguous };
208
457
  };
209
458
  exports.buildBindingIndex = buildBindingIndex;
@@ -220,13 +469,18 @@ const bindTarget = (target, index) => {
220
469
  // Two targets of one name is a fact about the document, not a reason to refuse it
221
470
  // an address: the first still answers, as it always has, and the ambiguity travels
222
471
  // with the answer for whoever reports it.
223
- return { found: true, document: 'self', key, via: hit.via, ambiguous: index.ambiguous.has(key) };
472
+ return { found: true, document: 'self', key, via: hit.via, ambiguous: index.ambiguous.has(key), node: hit.node };
224
473
  };
225
474
  exports.bindTarget = bindTarget;
226
475
  const getSafeNodeId = (node, ctx) => {
227
476
  const assigned = ctx?.__anchors?.byNode?.get(node);
228
477
  if (assigned !== undefined)
229
478
  return assigned;
479
+ const isHeading = typeof node === 'object' && node.name === 'head';
480
+ // a heading brought in after the index was built, as an =include drawn on the page
481
+ // is, must not fall back to a name made of the text it hides
482
+ if (isHeading && !hasExplicitId(node) && hidesText(node))
483
+ return null;
230
484
  const id = (0, exports.getNodeId)(node, ctx);
231
485
  if (id == null)
232
486
  return null;
@@ -234,7 +488,6 @@ const getSafeNodeId = (node, ctx) => {
234
488
  // only a heading derives its identifier from its own text, so only there can two
235
489
  // blocks claim the same anchor. An author-written :id is the author's business,
236
490
  // and a generated one is unique already.
237
- const isHeading = typeof node === 'object' && node.name === 'head';
238
491
  if (!isHeading)
239
492
  return fragment;
240
493
  const taken = ctx && typeof ctx === 'object' ? (ctx.__fragments ||= new Map()) : new Map();
@@ -1,5 +1,5 @@
1
- export declare const BLOCK_NAMES: readonly ["boundary", "cell", "code", "comment", "data", "data-table", "defn", "formula", "head", "include", "input", "item", "markdown", "nested", "output", "para", "picture", "pod", "row", "set", "table", "toc"];
2
- export declare const VERBATIM_BLOCKS: readonly ["code", "comment", "data", "data-table", "formula", "input", "markdown", "output", "picture", "table"];
1
+ export declare const BLOCK_NAMES: readonly ["assert", "boundary", "cell", "code", "comment", "data", "data-table", "defn", "fixture", "formula", "head", "include", "input", "item", "markdown", "nested", "output", "para", "picture", "pod", "resource", "row", "set", "table", "test", "toc"];
2
+ export declare const VERBATIM_BLOCKS: readonly ["assert", "code", "comment", "data", "data-table", "fixture", "formula", "input", "markdown", "output", "picture", "resource", "table"];
3
3
  export declare const isNamedBlockName: (name: string) => boolean;
4
4
  export declare const isVerbatimBlock: (name: string) => boolean;
5
5
  export declare const isKnownBlockName: (name: string) => boolean;
@@ -4,6 +4,7 @@ exports.isKnownBlockName = exports.isVerbatimBlock = exports.isNamedBlockName =
4
4
  // Names the parser treats as blocks. Kept here so the parser, the linter and the
5
5
  // editor read one list instead of each carrying a copy.
6
6
  exports.BLOCK_NAMES = [
7
+ 'assert',
7
8
  'boundary',
8
9
  'cell',
9
10
  'code',
@@ -11,6 +12,7 @@ exports.BLOCK_NAMES = [
11
12
  'data',
12
13
  'data-table',
13
14
  'defn',
15
+ 'fixture',
14
16
  'formula',
15
17
  'head',
16
18
  'include',
@@ -22,24 +24,29 @@ exports.BLOCK_NAMES = [
22
24
  'para',
23
25
  'picture',
24
26
  'pod',
27
+ 'resource',
25
28
  'row',
26
29
  'set',
27
30
  'table',
31
+ 'test',
28
32
  'toc',
29
33
  ];
30
34
  // Blocks whose content is taken as written, so nothing inside them is markup.
31
35
  // The formatting-codes plugin keeps a narrower list of its own — the two answer
32
36
  // different questions and are reconciled separately.
33
37
  exports.VERBATIM_BLOCKS = [
38
+ 'assert',
34
39
  'code',
35
40
  'comment',
36
41
  'data',
37
42
  'data-table',
43
+ 'fixture',
38
44
  'formula',
39
45
  'input',
40
46
  'markdown',
41
47
  'output',
42
48
  'picture',
49
+ 'resource',
43
50
  'table',
44
51
  ];
45
52
  // A name carrying both cases is a named block: the specification hands its body
@@ -22,7 +22,7 @@ export declare const mkVerbatim: (text: any) => {
22
22
  type: string;
23
23
  value: any;
24
24
  };
25
- export declare const mkToc: (content: TocList, title?: string, location?: Location, foldedLevels?: Record<number, boolean>, folded?: boolean) => Toc;
25
+ export declare const mkToc: (content: TocList, title?: string, location?: Location, foldedLevels?: Record<number, boolean>, folded?: boolean, caption?: BlockCaption, selector?: string) => Toc;
26
26
  export declare const mkTocList: (content: Array<TocItem | TocList>, level: number) => TocList;
27
27
  export declare const mkTocItem: (content: PodNode) => TocItem;
28
28
  export declare const mkCaption: (content: Array<Node>) => BlockCaption;
@@ -50,7 +50,7 @@ const mkVerbatim = text => {
50
50
  };
51
51
  exports.mkVerbatim = mkVerbatim;
52
52
  // Table of contents helpers
53
- const mkToc = (content, title, location, foldedLevels, folded) => {
53
+ const mkToc = (content, title, location, foldedLevels, folded, caption, selector) => {
54
54
  return (0, exports.mkNode)({
55
55
  type: 'toc',
56
56
  title,
@@ -58,6 +58,8 @@ const mkToc = (content, title, location, foldedLevels, folded) => {
58
58
  location,
59
59
  ...(foldedLevels ? { foldedLevels } : {}),
60
60
  ...(folded !== undefined ? { folded } : {}),
61
+ ...(caption ? { caption } : {}),
62
+ ...(selector !== undefined ? { selector } : {}),
61
63
  });
62
64
  };
63
65
  exports.mkToc = mkToc;