@podlite/schema 0.0.70 → 0.0.72

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
package/lib/exportHtml.js CHANGED
@@ -40,12 +40,15 @@ const exportAny_1 = __importDefault(require("./exportAny"));
40
40
  const handlers_1 = require("./helpers/handlers");
41
41
  const makeTransformer_1 = require("./helpers/makeTransformer");
42
42
  const config_1 = __importStar(require("./helpers/config"));
43
+ const configPropagation_1 = require("./helpers/configPropagation");
43
44
  const image_base_1 = require("./image-base");
44
45
  const guard_1 = require("./guard");
45
46
  const writerHtml_1 = __importDefault(require("./writerHtml"));
46
47
  const plugin_clean_location_1 = __importDefault(require("./plugin-clean-location"));
47
48
  const ast_helpers_1 = require("./ast-helpers");
48
49
  const link_config_1 = require("./helpers/link-config");
50
+ const test_display_1 = require("./test-display");
51
+ const toc_caption_1 = require("./toc-caption");
49
52
  const entities_1 = require("entities");
50
53
  const html_attr_1 = require("./helpers/html-attr");
51
54
  // HTML gives an anchor without href to a link whose target the author never
@@ -62,19 +65,20 @@ const hrefAttr = (node, ctx) => {
62
65
  // looks like a working link.
63
66
  return address === undefined ? '' : ` href="${(0, html_attr_1.quoteAttribute)(String(address))}"`;
64
67
  };
65
- const linkConfigAttrs = config => {
68
+ // A title or a file name written on a link inside hidden content is hidden with it.
69
+ const linkConfigAttrs = (config, conceal = text => text) => {
66
70
  const { newContext, title, lang, download } = (0, link_config_1.readLinkConfig)(config);
67
71
  const attrs = [];
68
72
  if (newContext)
69
73
  attrs.push(' target="_blank"');
70
74
  if (title !== undefined)
71
- attrs.push(` title="${(0, html_attr_1.quoteAttribute)(title)}"`);
75
+ attrs.push(` title="${(0, html_attr_1.quoteAttribute)(conceal(title))}"`);
72
76
  if (lang !== undefined)
73
77
  attrs.push(` hreflang="${(0, html_attr_1.quoteAttribute)(lang)}"`);
74
78
  if (download === true)
75
79
  attrs.push(' download');
76
80
  else if (typeof download === 'string')
77
- attrs.push(` download="${(0, html_attr_1.quoteAttribute)(download)}"`);
81
+ attrs.push(` download="${(0, html_attr_1.quoteAttribute)(conceal(download))}"`);
78
82
  return attrs.join('');
79
83
  };
80
84
  // Shaped by the same rule the address is: an anchor keeping a dot the address drops
@@ -84,6 +88,8 @@ const anchorOf = (node, ctx) => {
84
88
  const written = (0, ast_helpers_1.getExplicitNodeId)(node, ctx);
85
89
  return written === null ? null : (ctx?.__anchors?.shape || ast_helpers_1.toFragment)(written);
86
90
  };
91
+ // the words a test is shown by are hidden with the content they stand beside
92
+ const covered = (node, ctx, text) => ((0, guard_1.isCovered)(node, ctx) ? (0, handlers_1.maskText)(text) : text);
87
93
  const openTag = (tag, node, ctx, attrs = '') => {
88
94
  const id = anchorOf(node, ctx);
89
95
  return `<${tag}${id ? ` id="${id}"` : ''}${attrs}>`;
@@ -103,7 +109,7 @@ const rules = {
103
109
  //get replacement text
104
110
  const term = (0, handlers_1.collectText)(node.content).trim();
105
111
  if (!(ctx.alias && ctx.alias.hasOwnProperty(term))) {
106
- writer.write(`A<${term}>`);
112
+ writer.write(`A<${covered(node, ctx, term)}>`);
107
113
  }
108
114
  else {
109
115
  const src = ctx.alias[term].join('\n');
@@ -131,7 +137,7 @@ const rules = {
131
137
  return '';
132
138
  })
133
139
  .join('');
134
- writer.write(decoded);
140
+ writer.write(covered(node, ctx, decoded));
135
141
  }
136
142
  },
137
143
  'D<>': (writer, processor) => (node, ctx, interator) => {
@@ -168,11 +174,11 @@ const rules = {
168
174
  'H<>': (0, handlers_1.wrapContent)('<sup>', '</sup>'),
169
175
  'J<>': (0, handlers_1.wrapContent)('<sub>', '</sub>'),
170
176
  'L<>': (0, handlers_1.setFn)((node, ctx) => {
171
- const attrs = linkConfigAttrs((0, config_1.codeConfigWithDefaults)(node, ctx));
177
+ const attrs = linkConfigAttrs((0, config_1.codeConfigWithDefaults)(node, ctx), text => covered(node, ctx, text));
172
178
  return (0, handlers_1.wrapContent)(`<a${hrefAttr(node, ctx)}${attrs}>`, `</a>`);
173
179
  }),
174
180
  'W<>': (0, handlers_1.setFn)((node, ctx) => {
175
- const attrs = linkConfigAttrs((0, config_1.codeConfigWithDefaults)(node, ctx));
181
+ const attrs = linkConfigAttrs((0, config_1.codeConfigWithDefaults)(node, ctx), text => covered(node, ctx, text));
176
182
  return (0, handlers_1.wrapContent)(`<a${hrefAttr(node, ctx)}${attrs} class="backlink">`, `</a>`);
177
183
  }),
178
184
  /**
@@ -231,7 +237,7 @@ const rules = {
231
237
  };
232
238
  },
233
239
  'S<>': (writer, processor) => (node, ctx, interator) => {
234
- const spaces = (0, handlers_1.collectText)(node.content).replace(/ /g, '&nbsp;');
240
+ const spaces = covered(node, ctx, (0, handlers_1.collectText)(node.content)).replace(/ /g, '&nbsp;');
235
241
  const newFeed = spaces.replace(/\n/g, '</br>');
236
242
  writer.writeRaw(newFeed);
237
243
  },
@@ -257,10 +263,14 @@ const rules = {
257
263
  },
258
264
  'Z<>': handlers_1.emptyContent,
259
265
  pod: handlers_1.content,
260
- ':code': (0, handlers_1.wrapContent)('<pre><code>', '</code></pre>'),
266
+ ':code': (0, handlers_1.handleNested)((0, handlers_1.wrapContent)('<pre><code>', '</code></pre>')),
261
267
  code: (0, handlers_1.handleNested)((0, handlers_1.setFn)((node, ctx) => (0, handlers_1.wrapContent)(`${openTag('pre', node, ctx)}<code>`, '</code></pre>'))),
262
268
  // a folded section is a heading plus the nodes under it; the disclosure is
263
269
  // native so the reader needs no script to open it
270
+ // a document, and a file an include brings whole: its blocks are written, the holder is not
271
+ root: () => (node, ctx, interator) => {
272
+ interator(node.content, ctx);
273
+ },
264
274
  _folded_section: (writer, processor) => (node, ctx, interator) => {
265
275
  const [heading, ...rest] = (node.content || []);
266
276
  const open = node.foldedState === false || node.foldedState === 0 || node.foldedState === '0';
@@ -291,7 +301,7 @@ const rules = {
291
301
  if (!ctx.hasOwnProperty('config'))
292
302
  ctx.config = {};
293
303
  //collect configs in context
294
- ctx.config[node.name] = node.config;
304
+ ctx.config[node.name] = (0, configPropagation_1.mergeConfigSettings)(node.config, ctx.config[node.name]);
295
305
  return handlers_1.emptyContent;
296
306
  }),
297
307
  ':alias': (0, handlers_1.setFn)((node, ctx) => {
@@ -305,10 +315,9 @@ const rules = {
305
315
  // block =para
306
316
  // With an :id the block owns the <p> so the anchor lands on it; without one
307
317
  // the inner paragraph renders as before.
308
- para: (0, handlers_1.handleNested)((0, handlers_1.setFn)((node, ctx) => anchorOf(node, ctx)
309
- ? (0, handlers_1.subUse)({ ':para': handlers_1.content }, (0, handlers_1.wrapContent)(openTag('p', node, ctx), '</p>'))
310
- : handlers_1.content)),
311
- ':para': (0, handlers_1.setFn)((node, ctx) => (0, handlers_1.wrapContent)(openTag('p', node, ctx), '</p>')),
318
+ para: (0, handlers_1.handleNested)((0, handlers_1.setFn)((node, ctx) => anchorOf(node, ctx) ? (0, handlers_1.subUse)({ ':para': handlers_1.content }, (0, handlers_1.wrapContent)(openTag('p', node, ctx), '</p>')) : handlers_1.content)),
319
+ // a paragraph written without a marker is nested by the settings it was given
320
+ ':para': (0, handlers_1.handleNested)((0, handlers_1.setFn)((node, ctx) => (0, handlers_1.wrapContent)(openTag('p', node, ctx), '</p>'))),
312
321
  'head:block': (0, handlers_1.subUse)({
313
322
  // inside head don't wrap into <p>
314
323
  ':para': handlers_1.content,
@@ -342,13 +351,53 @@ const rules = {
342
351
  writer.writeRaw('</li>');
343
352
  },
344
353
  'comment:block': handlers_1.emptyContent,
354
+ // a test is written open: a reader without scripts gets the rule and its test together
355
+ 'test:block': (writer, processor) => (node, ctx, interator) => {
356
+ const open = (0, test_display_1.testFoldedByAuthor)(node, ctx) === true ? '' : ' open';
357
+ writer.writeRaw(openTag('details', node, ctx, ` class="test"${open}`));
358
+ writer.writeRaw('<summary class="test-summary"><span class="test-label">test</span> <span class="test-caption">');
359
+ writer.write(covered(node, ctx, (0, test_display_1.testCaption)(node, ctx)));
360
+ writer.writeRaw('</span></summary><div class="test-body">');
361
+ interator(node.content, ctx);
362
+ writer.writeRaw('</div></details>');
363
+ },
364
+ 'fixture:block': (writer, processor) => (node, ctx, interator) => {
365
+ writer.writeRaw('<div class="test-fixture"><pre><code>');
366
+ interator(node.content, ctx);
367
+ writer.writeRaw('</code></pre></div>');
368
+ },
369
+ 'assert:block': (writer, processor) => (node, ctx, interator) => {
370
+ const conf = (0, config_1.default)(node, ctx);
371
+ const absent = conf.exists('absent') && Boolean(conf.getFirstValue('absent'));
372
+ writer.writeRaw(`<div class="test-assert${absent ? ' test-absent' : ''}"><code class="test-selector">`);
373
+ interator(node.content, ctx);
374
+ writer.writeRaw(`</code> <span class="test-expect">${absent ? 'must find no block' : 'must find a block'}</span>`);
375
+ if (conf.exists('caption')) {
376
+ writer.writeRaw(': <span class="test-assert-caption">');
377
+ writer.write(covered(node, ctx, String(conf.getFirstValue('caption'))));
378
+ writer.writeRaw('</span>');
379
+ }
380
+ writer.writeRaw('</div>');
381
+ },
382
+ 'resource:block': (writer, processor) => (node, ctx, interator) => {
383
+ const conf = (0, config_1.default)(node, ctx);
384
+ writer.writeRaw('<div class="test-resource">');
385
+ if (conf.exists('name')) {
386
+ writer.writeRaw('<span class="test-resource-name">');
387
+ writer.write(covered(node, ctx, String(conf.getFirstValue('name'))));
388
+ writer.writeRaw('</span>');
389
+ }
390
+ writer.writeRaw('<pre><code>');
391
+ interator(node.content, ctx);
392
+ writer.writeRaw('</code></pre></div>');
393
+ },
345
394
  'boundary:block': (writer, processor) => (node, ctx) => {
346
395
  const conf = (0, config_1.default)(node, ctx);
347
396
  const id = anchorOf(node, ctx);
348
397
  const idAttr = id ? ` id="${id}"` : '';
349
398
  if (conf.exists('caption')) {
350
399
  writer.writeRaw(`<hr${idAttr} title="`);
351
- writer.write(conf.getFirstValue('caption'));
400
+ writer.write(covered(node, ctx, String(conf.getFirstValue('caption'))));
352
401
  writer.writeRaw('">');
353
402
  }
354
403
  else {
@@ -372,7 +421,7 @@ const rules = {
372
421
  writer.writeRaw(openTag('table', node, ctx));
373
422
  if (conf.exists('caption')) {
374
423
  writer.writeRaw('<caption>');
375
- writer.write(conf.getFirstValue('caption'));
424
+ writer.write(covered(node, ctx, String(conf.getFirstValue('caption'))));
376
425
  writer.writeRaw('</caption>');
377
426
  }
378
427
  const innerCtx = { ...ctx, ...(node.align && { 'table.align': node.align }) };
@@ -432,17 +481,24 @@ const rules = {
432
481
  interator(node.content, ctx);
433
482
  writer.writeRaw(`</${tag}>`);
434
483
  },
435
- // Toc
484
+ // Toc: the directive holds the table it made, and gives it its :id
485
+ 'toc:block': (writer, processor) => (node, ctx, interator) => interator(node.content, { ...ctx, tocAnchor: anchorOf(node, ctx) }),
486
+ 'Toc:block': (writer, processor) => (node, ctx, interator) => interator(node.content, { ...ctx, tocAnchor: anchorOf(node, ctx) }),
436
487
  ':toc': (writer, processor) => (node, ctx, interator) => {
437
- writer.writeRaw('<div className="toc">');
438
- // get toc title
439
- const conf = (0, config_1.default)(node, ctx);
440
- if (conf.exists('title')) {
441
- const title = conf.getFirstValue('title');
442
- writer.writeRaw('<div className="toctitle">');
443
- writer.write(title);
488
+ writer.writeRaw(ctx?.tocAnchor ? `<div class="toc" id="${ctx.tocAnchor}">` : '<div class="toc">');
489
+ if (node.caption) {
490
+ writer.writeRaw('<div class="toctitle">');
491
+ interator(node.caption.content, ctx);
444
492
  writer.writeRaw('</div>');
445
493
  }
494
+ else {
495
+ const title = (0, toc_caption_1.tocTitleText)(node, ctx);
496
+ if (title !== undefined) {
497
+ writer.writeRaw('<div class="toctitle">');
498
+ writer.write(title);
499
+ writer.writeRaw('</div>');
500
+ }
501
+ }
446
502
  interator(node.content, ctx);
447
503
  writer.writeRaw('</div>');
448
504
  },
@@ -453,7 +509,7 @@ const rules = {
453
509
  // html reads a missing alt as "this image is part of the content" and an empty
454
510
  // one as "decorative", so an alternative text the author never wrote is left out
455
511
  const altText = (0, ast_helpers_1.writtenValue)(node.alt);
456
- const alt = altText === undefined ? '' : ` alt="${(0, html_attr_1.quoteAttribute)(altText)}"`;
512
+ const alt = altText === undefined ? '' : ` alt="${(0, html_attr_1.quoteAttribute)(covered(node, ctx, altText))}"`;
457
513
  writer.writeRaw(`<img src="${src}"${alt}/>`);
458
514
  },
459
515
  };
@@ -480,7 +536,7 @@ const toHtml = opt => (0, exportAny_1.default)({
480
536
  writer.writeRaw('<h1 class="');
481
537
  writer.write(name);
482
538
  writer.writeRaw('">');
483
- writer.write(name);
539
+ writer.write(covered(node, ctx, String(name)));
484
540
  writer.writeRaw('</h1>');
485
541
  }
486
542
  else {
@@ -501,7 +557,8 @@ const toHtml = opt => (0, exportAny_1.default)({
501
557
  return defaultFn();
502
558
  if (node.guarded)
503
559
  return defaultFn(node, { ...(ctx || {}), maskMode: true }, interator);
504
- if (node.type !== 'block')
560
+ // a paragraph or code written without a marker carries what =config or =set gave it
561
+ if (node.type !== 'block' && node.type !== 'para' && node.type !== 'code')
505
562
  return defaultFn();
506
563
  const conf = (0, config_1.default)(node, ctx || {});
507
564
  if (!conf.exists('masked') || !conf.getFirstValue('masked'))
@@ -40,17 +40,35 @@ const exportAny_1 = __importDefault(require("./exportAny"));
40
40
  const guard_1 = require("./guard");
41
41
  const handlers_1 = require("./helpers/handlers");
42
42
  const config_1 = __importStar(require("./helpers/config"));
43
+ const configPropagation_1 = require("./helpers/configPropagation");
43
44
  const image_base_1 = require("./image-base");
44
45
  const writerMarkdown_1 = __importDefault(require("./writerMarkdown"));
45
46
  const plugin_clean_location_1 = __importDefault(require("./plugin-clean-location"));
46
47
  const ast_helpers_1 = require("./ast-helpers");
48
+ const html_attr_1 = require("./helpers/html-attr");
47
49
  const link_config_1 = require("./helpers/link-config");
50
+ const test_display_1 = require("./test-display");
48
51
  // A markdown reader builds the anchor out of the heading itself, by its own rules,
49
52
  // so a link written here has to match what that reader will produce.
50
- const markdownAnchors = ctx => ctx && (ctx.__markdownAnchors ||= (0, ast_helpers_1.restyleAnchors)(ctx.__anchors, ast_helpers_1.markdownStyle));
51
- const linkTitle = config => {
53
+ // Built once per document and mode: a hidden block renders with a copy of the context,
54
+ // and a cache kept on the context itself would be rebuilt for every one of them.
55
+ const readerAnchorsCache = new WeakMap();
56
+ const markdownAnchors = ctx => {
57
+ const index = ctx?.__anchors;
58
+ if (!index)
59
+ return undefined;
60
+ const mode = ctx.renderMode === 'draft' ? 'draft' : 'production';
61
+ let byMode = readerAnchorsCache.get(index);
62
+ if (!byMode)
63
+ readerAnchorsCache.set(index, (byMode = new Map()));
64
+ if (!byMode.has(mode))
65
+ byMode.set(mode, (0, ast_helpers_1.readerAnchors)(index, mode));
66
+ return byMode.get(mode);
67
+ };
68
+ // a title written on a link inside hidden content is hidden with it
69
+ const linkTitle = (config, conceal = text => text) => {
52
70
  const { title } = (0, link_config_1.readLinkConfig)(config);
53
- return title === undefined ? '' : ` "${title.replace(/"/g, '\\"')}"`;
71
+ return title === undefined ? '' : ` "${conceal(title).replace(/"/g, '\\"')}"`;
54
72
  };
55
73
  // Markdown has no form for a link whose target the author never wrote — an empty
56
74
  // address there claims the current document — so the text is written on its own.
@@ -70,7 +88,7 @@ const linkWrap = (node, ctx) => {
70
88
  if (resolved === undefined)
71
89
  return (0, handlers_1.wrapContent)('', '');
72
90
  const address = String(resolved);
73
- return (0, handlers_1.wrapContent)(`[`, `](${markdownAddress(address)}${linkTitle((0, config_1.codeConfigWithDefaults)(node, ctx))})`);
91
+ return (0, handlers_1.wrapContent)(`[`, `](${markdownAddress(address)}${linkTitle((0, config_1.codeConfigWithDefaults)(node, ctx), text => covered(node, ctx, text))})`);
74
92
  };
75
93
  // A cell's own text is written whole. Trimming each fragment on its own eats the
76
94
  // spaces that sit between them — between a word and a markup code, or around a
@@ -91,6 +109,35 @@ const writeCellParts = (cell, writer, interator, ctx) => {
91
109
  writer.write(text);
92
110
  });
93
111
  };
112
+ // The body of a fixture or a resource is source, written as it stands inside a
113
+ // fence no run of backticks in it can close.
114
+ const writeSourceBlock = (writer, node, ctx) => {
115
+ const text = (0, handlers_1.collectText)(node.content);
116
+ const fence = '`'.repeat(Math.max(3, (0, test_display_1.longestBacktickRun)(text) + 1));
117
+ writer.writeRaw(`${fence}podlite\n`);
118
+ writer.writeRaw((0, guard_1.isCovered)(node, ctx) ? (0, handlers_1.maskText)(text) : text);
119
+ if (!text.endsWith('\n'))
120
+ writer.writeRaw('\n');
121
+ writer.writeRaw(`${fence}\n`);
122
+ };
123
+ // the words a test is shown by are hidden with the content they stand beside
124
+ const covered = (node, ctx, text) => ((0, guard_1.isCovered)(node, ctx) ? (0, handlers_1.maskText)(text) : text);
125
+ const inlineCode = (text) => {
126
+ const ticks = '`'.repeat((0, test_display_1.longestBacktickRun)(text) + 1);
127
+ const pad = text.startsWith('`') || text.endsWith('`') ? ' ' : '';
128
+ return `${ticks}${pad}${text}${pad}${ticks}`;
129
+ };
130
+ const implicitPara = (0, handlers_1.handleNested)((writer, processor) => (node, ctx, interator) => {
131
+ if (node.content)
132
+ interator(node.content, ctx);
133
+ writer.writeRaw('\n');
134
+ });
135
+ const termPara = (writer, processor) => (node, ctx, interator) => {
136
+ writer.writeRaw('**');
137
+ if (node.content)
138
+ interator(node.content, ctx);
139
+ writer.writeRaw(':** ');
140
+ };
94
141
  const rules = {
95
142
  ':text': (writer, processor) => (node, ctx, interator) => {
96
143
  if (node.value) {
@@ -104,7 +151,7 @@ const rules = {
104
151
  'A<>': (writer, processor) => (node, ctx, interator) => {
105
152
  const term = (0, handlers_1.collectText)(node.content).trim();
106
153
  if (!(ctx.alias && ctx.alias.hasOwnProperty(term))) {
107
- writer.writeRaw(`A<${term}>`);
154
+ writer.writeRaw(`A<${covered(node, ctx, term)}>`);
108
155
  }
109
156
  else {
110
157
  const src = ctx.alias[term].join('\n');
@@ -183,7 +230,7 @@ const rules = {
183
230
  };
184
231
  },
185
232
  'S<>': (writer, processor) => (node, ctx, interator) => {
186
- const text = (0, handlers_1.collectText)(node.content);
233
+ const text = covered(node, ctx, (0, handlers_1.collectText)(node.content));
187
234
  // preserve spaces and newlines
188
235
  writer.writeRaw(text.replace(/ /g, '&nbsp;').replace(/\n/g, ' \n'));
189
236
  },
@@ -207,7 +254,7 @@ const rules = {
207
254
  },
208
255
  'Z<>': handlers_1.emptyContent,
209
256
  pod: handlers_1.content,
210
- ':code': (writer, processor) => (node, ctx, interator) => {
257
+ ':code': (0, handlers_1.handleNested)((writer, processor) => (node, ctx, interator) => {
211
258
  const conf = (0, config_1.default)(node, ctx);
212
259
  const lang = conf.exists('lang') ? conf.getFirstValue('lang') : '';
213
260
  writer.writeRaw('```' + lang + '\n');
@@ -226,7 +273,7 @@ const rules = {
226
273
  });
227
274
  }
228
275
  writer.writeRaw('```\n');
229
- },
276
+ }),
230
277
  code: (0, handlers_1.handleNested)((writer, processor) => (node, ctx, interator) => {
231
278
  const conf = (0, config_1.default)(node, ctx);
232
279
  const lang = conf.exists('lang') ? conf.getFirstValue('lang') : '';
@@ -260,7 +307,7 @@ const rules = {
260
307
  ':config': (0, handlers_1.setFn)((node, ctx) => {
261
308
  if (!ctx.hasOwnProperty('config'))
262
309
  ctx.config = {};
263
- ctx.config[node.name] = node.config;
310
+ ctx.config[node.name] = (0, configPropagation_1.mergeConfigSettings)(node.config, ctx.config[node.name]);
264
311
  return handlers_1.emptyContent;
265
312
  }),
266
313
  ':alias': (0, handlers_1.setFn)((node, ctx) => {
@@ -271,11 +318,7 @@ const rules = {
271
318
  }),
272
319
  // block =para
273
320
  para: (0, handlers_1.handleNested)(handlers_1.content),
274
- ':para': (writer, processor) => (node, ctx, interator) => {
275
- if (node.content)
276
- interator(node.content, ctx);
277
- writer.writeRaw('\n');
278
- },
321
+ ':para': implicitPara,
279
322
  'head:block': (0, handlers_1.subUse)({
280
323
  ':para': handlers_1.content,
281
324
  }, (0, handlers_1.setFn)((node, ctx) => {
@@ -283,6 +326,11 @@ const rules = {
283
326
  const prefix = '#'.repeat(level) + ' ';
284
327
  const numberPrefix = node.numberPrefix ? `${node.numberPrefix} ` : '';
285
328
  return (writer, processor) => (node, ctx, interator) => {
329
+ // the reader cannot build this address out of the heading, so it is written here
330
+ const anchors = markdownAnchors(ctx);
331
+ const own = anchors?.named?.has(node) ? anchors.byNode.get(node) : undefined;
332
+ if (own)
333
+ writer.writeRaw(`<a name="${(0, html_attr_1.quoteAttribute)(own)}"></a>\n\n`);
286
334
  writer.writeRaw(prefix);
287
335
  if (numberPrefix)
288
336
  writer.writeRaw(numberPrefix);
@@ -327,20 +375,56 @@ const rules = {
327
375
  interator(node.content, ctx);
328
376
  },
329
377
  'comment:block': handlers_1.emptyContent,
378
+ 'test:block': (writer, processor) => (node, ctx, interator) => {
379
+ writer.writeRaw('\n**Test** ');
380
+ writer.write(covered(node, ctx, (0, test_display_1.testCaption)(node, ctx)));
381
+ writer.writeRaw('\n\n');
382
+ interator(node.content, ctx);
383
+ writer.writeRaw('\n');
384
+ },
385
+ 'fixture:block': (writer, processor) => (node, ctx) => writeSourceBlock(writer, node, ctx),
386
+ 'assert:block': (writer, processor) => (node, ctx, interator) => {
387
+ const conf = (0, config_1.default)(node, ctx);
388
+ const absent = conf.exists('absent') && Boolean(conf.getFirstValue('absent'));
389
+ const selector = (0, handlers_1.collectText)(node.content).trim();
390
+ writer.writeRaw(`- ${inlineCode((0, guard_1.isCovered)(node, ctx) ? (0, handlers_1.maskText)(selector) : selector)} `);
391
+ writer.writeRaw(absent ? 'must find no block' : 'must find a block');
392
+ if (conf.exists('caption')) {
393
+ writer.writeRaw(': ');
394
+ writer.write(covered(node, ctx, String(conf.getFirstValue('caption'))));
395
+ }
396
+ writer.writeRaw('\n');
397
+ },
398
+ 'resource:block': (writer, processor) => (node, ctx, interator) => {
399
+ const conf = (0, config_1.default)(node, ctx);
400
+ writer.writeRaw('\nResource');
401
+ if (conf.exists('name'))
402
+ writer.writeRaw(` ${inlineCode(covered(node, ctx, String(conf.getFirstValue('name'))))}`);
403
+ writer.writeRaw(':\n\n');
404
+ writeSourceBlock(writer, node, ctx);
405
+ },
330
406
  'boundary:block': (writer, processor) => (node, ctx) => {
331
407
  writer.writeRaw('\n---\n');
332
408
  },
333
- defn: (writer, processor) => (node, ctx, interator) => {
409
+ defn: (0, handlers_1.subUse)([
410
+ {
411
+ // a nested definition starts a line of its own, not the line of its term
412
+ ':para': (writer, processor) => {
413
+ const para = implicitPara(writer, processor);
414
+ return (node, ctx, interator) => {
415
+ if ((0, config_1.default)(node, ctx).getFirstValue('nested'))
416
+ writer.writeRaw('\n');
417
+ para(node, ctx, interator);
418
+ };
419
+ },
420
+ },
421
+ { 'term:para': termPara },
422
+ ], (writer, processor) => (node, ctx, interator) => {
334
423
  if (node.content)
335
424
  interator(node.content, ctx);
336
425
  writer.writeRaw('\n');
337
- },
338
- 'term:para': (writer, processor) => (node, ctx, interator) => {
339
- writer.writeRaw('**');
340
- if (node.content)
341
- interator(node.content, ctx);
342
- writer.writeRaw(':** ');
343
- },
426
+ }),
427
+ 'term:para': termPara,
344
428
  nested: (0, handlers_1.handleNested)(handlers_1.content, 1),
345
429
  output: (0, handlers_1.handleNested)((writer, processor) => (node, ctx, interator) => {
346
430
  writer.writeRaw('```\n');
@@ -359,7 +443,7 @@ const rules = {
359
443
  const conf = (0, config_1.default)(node, ctx);
360
444
  if (conf.exists('caption')) {
361
445
  writer.writeRaw('**');
362
- writer.write(conf.getFirstValue('caption'));
446
+ writer.write(covered(node, ctx, String(conf.getFirstValue('caption'))));
363
447
  writer.writeRaw('**\n\n');
364
448
  }
365
449
  // collect rows data for proper Markdown table rendering
@@ -467,7 +551,7 @@ const rules = {
467
551
  ':image': (writer, processor) => (node, ctx, interator) => {
468
552
  // the alternative text sits between square brackets, where a `]` of its own
469
553
  // would end it, and the address between round ones — the same shape a link has
470
- const alt = ((0, ast_helpers_1.writtenValue)(node.alt) ?? '').replace(/([[\]\\])/g, '\\$1');
554
+ const alt = covered(node, ctx, (0, ast_helpers_1.writtenValue)(node.alt) ?? '').replace(/([[\]\\])/g, '\\$1');
471
555
  const src = markdownAddress(String((0, image_base_1.applyImageBase)(node.src, ctx?.base) ?? ''));
472
556
  writer.writeRaw(`![${alt}](${src})`);
473
557
  },
@@ -487,7 +571,7 @@ const toMarkdown = opt => (0, exportAny_1.default)({
487
571
  if (isSemanticBlock(node)) {
488
572
  const name = node.name;
489
573
  writer.writeRaw('# ');
490
- writer.write(name);
574
+ writer.write(covered(node, ctx, String(name)));
491
575
  writer.writeRaw('\n\n');
492
576
  }
493
577
  if (node.hasOwnProperty('content')) {
@@ -505,7 +589,8 @@ const toMarkdown = opt => (0, exportAny_1.default)({
505
589
  return defaultFn();
506
590
  if (node.guarded)
507
591
  return defaultFn(node, { ...(ctx || {}), maskMode: true }, interator);
508
- if (node.type !== 'block')
592
+ // a paragraph or code written without a marker carries what =config or =set gave it
593
+ if (node.type !== 'block' && node.type !== 'para' && node.type !== 'code')
509
594
  return defaultFn();
510
595
  const conf = (0, config_1.default)(node, ctx || {});
511
596
  if (!conf.exists('masked') || !conf.getFirstValue('masked'))