@podlite/schema 0.0.79 → 0.0.81
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.podlite +44 -0
- package/esm/ast-helpers.d.ts +8 -1
- package/esm/ast-helpers.js +172 -47
- package/esm/ast-helpers.js.map +1 -1
- package/esm/exportAny.d.ts +1 -0
- package/esm/exportAny.js +11 -0
- package/esm/exportAny.js.map +1 -1
- package/esm/exportHtml.js +58 -1
- package/esm/exportHtml.js.map +1 -1
- package/esm/exportMarkdown.js +604 -137
- package/esm/exportMarkdown.js.map +1 -1
- package/esm/helpers/code-config.d.ts +1 -0
- package/esm/helpers/code-config.js +4 -0
- package/esm/helpers/code-config.js.map +1 -0
- package/esm/helpers/corePlugins.js +4 -0
- package/esm/helpers/corePlugins.js.map +1 -1
- package/esm/helpers/handlers.js +8 -4
- package/esm/helpers/handlers.js.map +1 -1
- package/esm/index.d.ts +2 -0
- package/esm/index.js +1 -0
- package/esm/index.js.map +1 -1
- package/esm/markdown-heading-text.d.ts +3 -0
- package/esm/markdown-heading-text.js +36 -0
- package/esm/markdown-heading-text.js.map +1 -0
- package/esm/plugin-formatting-codes.js +1 -3
- package/esm/plugin-formatting-codes.js.map +1 -1
- package/esm/plugin-tables.d.ts +4 -1
- package/esm/plugin-tables.js +99 -26
- package/esm/plugin-tables.js.map +1 -1
- package/esm/test-display.js +8 -1
- package/esm/test-display.js.map +1 -1
- package/esm/title.d.ts +13 -0
- package/esm/title.js +22 -0
- package/esm/title.js.map +1 -0
- package/esm/types.d.ts +9 -4
- package/esm/version.d.ts +1 -1
- package/esm/version.js +1 -1
- package/esm/writerMarkdown.d.ts +9 -0
- package/esm/writerMarkdown.js +103 -1
- package/esm/writerMarkdown.js.map +1 -1
- package/lib/ast-helpers.d.ts +8 -1
- package/lib/ast-helpers.js +176 -48
- package/lib/exportAny.d.ts +1 -0
- package/lib/exportAny.js +11 -0
- package/lib/exportHtml.js +58 -1
- package/lib/exportMarkdown.js +607 -140
- package/lib/helpers/code-config.d.ts +1 -0
- package/lib/helpers/code-config.js +8 -0
- package/lib/helpers/corePlugins.js +4 -0
- package/lib/helpers/handlers.js +8 -4
- package/lib/index.d.ts +2 -0
- package/lib/index.js +5 -2
- package/lib/markdown-heading-text.d.ts +3 -0
- package/lib/markdown-heading-text.js +40 -0
- package/lib/plugin-formatting-codes.js +2 -4
- package/lib/plugin-tables.d.ts +4 -1
- package/lib/plugin-tables.js +99 -26
- package/lib/test-display.js +8 -1
- package/lib/title.d.ts +13 -0
- package/lib/title.js +27 -0
- package/lib/types.d.ts +9 -4
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/lib/writerMarkdown.d.ts +9 -0
- package/lib/writerMarkdown.js +103 -1
- package/package.json +3 -2
- package/schema/AstTree.json +246 -0
- package/schema/PodliteDocument.json +246 -0
package/lib/ast-helpers.js
CHANGED
|
@@ -3,11 +3,12 @@ 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.readerAnchors = 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.headingsWithCodeLinks = exports.indexAnchors = exports.nodesOfTree = exports.decodeEntities = exports.markdownStyle = exports.htmlStyle = exports.toMarkdownFragment = exports.toFragment = exports.getNodeId = void 0;
|
|
7
7
|
const entities_1 = require("entities");
|
|
8
8
|
const _1 = require(".");
|
|
9
9
|
const config_1 = __importDefault(require("./helpers/config"));
|
|
10
10
|
const handlers_1 = require("./helpers/handlers");
|
|
11
|
+
const title_1 = require("./title");
|
|
11
12
|
const getNodeId = (node, ctx) => {
|
|
12
13
|
const conf = (0, config_1.default)(node, ctx);
|
|
13
14
|
if (conf.exists('id')) {
|
|
@@ -53,44 +54,79 @@ const takeUnique = (fragment, taken, firstRepeat) => {
|
|
|
53
54
|
taken.set(result, taken.get(result) || 0);
|
|
54
55
|
return result;
|
|
55
56
|
};
|
|
57
|
+
const isScalarValue = (value) => Number.isInteger(value) && value >= 0 && value <= 0x10ffff && (value < 0xd800 || value > 0xdfff);
|
|
58
|
+
/*
|
|
59
|
+
=begin pod :kind<export>
|
|
60
|
+
|
|
61
|
+
=head2 decodeEntities
|
|
62
|
+
|
|
63
|
+
The characters an C<E<>> code stands for, given the content of its node. A number gives
|
|
64
|
+
the character at that code point and a name the HTML5 character of that name. A number
|
|
65
|
+
that is not a Unicode scalar value, such as one past 0x10FFFF, a surrogate or the C<NaN>
|
|
66
|
+
the parser gives for C<E<0o9>>, gives nothing, and so does a Unicode character name.
|
|
67
|
+
|
|
68
|
+
=end pod
|
|
69
|
+
*/
|
|
56
70
|
const decodeEntities = (content) => Array.isArray(content)
|
|
57
71
|
? content
|
|
58
72
|
.map((element) => {
|
|
59
73
|
if (element?.type === 'number' && typeof element.value === 'number')
|
|
60
|
-
return String.
|
|
74
|
+
return isScalarValue(element.value) ? String.fromCodePoint(element.value) : '';
|
|
61
75
|
if (element?.type === 'html_named' && typeof element.value === 'string')
|
|
62
76
|
return (0, entities_1.decodeHTMLStrict)(`&${element.value};`);
|
|
63
77
|
return '';
|
|
64
78
|
})
|
|
65
79
|
.join('')
|
|
66
80
|
: '';
|
|
81
|
+
exports.decodeEntities = decodeEntities;
|
|
67
82
|
// The text the markdown output puts into a heading, as a reader sees it. Hidden parts
|
|
68
83
|
// come out masked when the output masks them, and G<> masks everything written inside
|
|
69
|
-
// it at once. The markdown export writes
|
|
70
|
-
// number, and S<> with unbreakable spaces, which a reader drops from
|
|
71
|
-
|
|
84
|
+
// it at once. The markdown export writes the characters of E<> and nothing for Z<>, a
|
|
85
|
+
// footnote as its number, and S<> with unbreakable spaces, which a reader drops from
|
|
86
|
+
// the address.
|
|
87
|
+
// The line of a heading is one line: a line break of code is a space, one S<> keeps is
|
|
88
|
+
// a tag the reader drops, and every other one, with the spaces around it, is a space.
|
|
89
|
+
const codeNames = ['C', 'K', 'T'];
|
|
90
|
+
const markdownText = (node, masked, footnotes, covered = false, inCode = false) => {
|
|
91
|
+
const line = (text) => (inCode ? text.replace(/\n/g, ' ') : text);
|
|
72
92
|
if (typeof node === 'string')
|
|
73
|
-
return covered && masked ? (0, handlers_1.maskText)(node) : node;
|
|
93
|
+
return line(covered && masked ? (0, handlers_1.maskText)(node) : node);
|
|
74
94
|
if (Array.isArray(node))
|
|
75
|
-
return node.map(child => markdownText(child, masked, footnotes, covered)).join('');
|
|
95
|
+
return node.map(child => markdownText(child, masked, footnotes, covered, inCode)).join('');
|
|
76
96
|
if (!node || typeof node !== 'object')
|
|
77
97
|
return '';
|
|
78
98
|
const n = node;
|
|
79
99
|
const hidden = covered || n.guarded === true;
|
|
100
|
+
const code = inCode || (n.type === 'fcode' && codeNames.includes(String(n.name)));
|
|
80
101
|
if (n.type === 'fcode') {
|
|
81
102
|
if (n.name === 'G' && masked)
|
|
82
|
-
return (0, handlers_1.maskText)((0, handlers_1.collectText)(n.content));
|
|
83
|
-
if (n.name === 'E'
|
|
103
|
+
return line((0, handlers_1.maskText)((0, handlers_1.collectText)(n.content)));
|
|
104
|
+
if (n.name === 'E') {
|
|
105
|
+
const text = (0, exports.decodeEntities)(n.content);
|
|
106
|
+
return line(hidden && masked ? (0, handlers_1.maskText)(text) : text);
|
|
107
|
+
}
|
|
108
|
+
if (n.name === 'Z')
|
|
84
109
|
return '';
|
|
85
110
|
if (n.name === 'N')
|
|
86
111
|
return String(footnotes.get(node) ?? '');
|
|
87
112
|
if (n.name === 'S')
|
|
88
|
-
return markdownText(n.content, masked, footnotes, hidden).replace(/ /g, '\u00a0');
|
|
113
|
+
return markdownText(n.content, masked, footnotes, hidden, code).replace(/ /g, '\u00a0').replace(/\n/g, '');
|
|
89
114
|
}
|
|
90
115
|
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);
|
|
116
|
+
return line(hidden && masked ? (0, handlers_1.maskText)(n.value) : n.value);
|
|
117
|
+
return markdownText(n.content, masked, footnotes, hidden, code);
|
|
93
118
|
};
|
|
119
|
+
const headingText = (text) => text.replace(/[ \t]*\n[ \t]*/g, ' ').trim();
|
|
120
|
+
// The text of a =TITLE the markdown output writes as its heading: the paragraphs that
|
|
121
|
+
// show something, one after another. A paragraph keeps its own mask.
|
|
122
|
+
const titleText = (node, masked, footnotes) => (0, title_1.titleParts)(node)
|
|
123
|
+
.flatMap(entry => entry.kind === 'part'
|
|
124
|
+
? [
|
|
125
|
+
headingText(markdownText(entry.content, masked, footnotes, entry.owners.some(owner => owner.guarded === true))),
|
|
126
|
+
]
|
|
127
|
+
: [])
|
|
128
|
+
.filter(text => /\S/.test(text))
|
|
129
|
+
.join(' ');
|
|
94
130
|
// Footnotes are numbered in the order the markdown export meets them in the text. It
|
|
95
131
|
// writes nothing for a comment or a data block, reaches a footnote inside another one
|
|
96
132
|
// only when the notes are written at the end, and in production a G<> writes its text
|
|
@@ -134,7 +170,7 @@ const hiddenPart = (node, covered = false) => {
|
|
|
134
170
|
const n = node;
|
|
135
171
|
const hidden = covered || n.guarded === true;
|
|
136
172
|
if (n.type === 'fcode' && n.name === 'E')
|
|
137
|
-
return hidden ? decodeEntities(n.content) : '';
|
|
173
|
+
return hidden ? (0, exports.decodeEntities)(n.content) : '';
|
|
138
174
|
if ((n.type === 'text' || n.type === 'verbatim') && typeof n.value === 'string')
|
|
139
175
|
return hidden ? n.value : '';
|
|
140
176
|
return hiddenPart(n.content, hidden);
|
|
@@ -158,6 +194,14 @@ const walkNodes = (node, visit) => {
|
|
|
158
194
|
if ('content' in node)
|
|
159
195
|
walkNodes(node.content, visit);
|
|
160
196
|
};
|
|
197
|
+
// The nodes of a tree. A node the output makes as it writes, such as a heading an alias
|
|
198
|
+
// brings, is not one of them: it is a new node on every walk.
|
|
199
|
+
const nodesOfTree = (tree) => {
|
|
200
|
+
const nodes = new WeakSet();
|
|
201
|
+
walkNodes(tree, node => nodes.add(node));
|
|
202
|
+
return nodes;
|
|
203
|
+
};
|
|
204
|
+
exports.nodesOfTree = nodesOfTree;
|
|
161
205
|
// A heading with hidden text gets a name made of nothing it hides, and it takes no
|
|
162
206
|
// place in the numbering of repeats: otherwise the number of an open neighbour would
|
|
163
207
|
// say that a hidden heading above carries the same name.
|
|
@@ -207,11 +251,18 @@ const readerSlugs = (headings, masked, footnotes) => {
|
|
|
207
251
|
for (const node of headings) {
|
|
208
252
|
const n = node;
|
|
209
253
|
const prefix = n.numberPrefix;
|
|
254
|
+
if ((0, title_1.isTitleBlock)(n) && !/\S/.test(titleText(n, masked, numbers))) {
|
|
255
|
+
// a title with nothing to show writes no heading and takes no address
|
|
256
|
+
slugs.push('');
|
|
257
|
+
continue;
|
|
258
|
+
}
|
|
210
259
|
const text = n.name === 'head'
|
|
211
|
-
? `${prefix ? `${prefix} ` : ''}${markdownText(n.content, masked, numbers)}
|
|
212
|
-
: n
|
|
213
|
-
? (
|
|
214
|
-
:
|
|
260
|
+
? headingText(`${prefix ? `${prefix} ` : ''}${markdownText(n.content, masked, numbers)}`)
|
|
261
|
+
: (0, title_1.isTitleBlock)(n)
|
|
262
|
+
? titleText(n, masked, numbers)
|
|
263
|
+
: n.guarded === true && masked
|
|
264
|
+
? (0, handlers_1.maskText)(String(n.name))
|
|
265
|
+
: String(n.name);
|
|
215
266
|
const base = (0, exports.toMarkdownFragment)(text);
|
|
216
267
|
let slug = base;
|
|
217
268
|
while (occurrences.has(slug)) {
|
|
@@ -254,6 +305,41 @@ const indexAnchors = (tree, style = exports.htmlStyle) => {
|
|
|
254
305
|
return { ...assignAnchors(heads, style, reserved), pageHeadings, footnotes };
|
|
255
306
|
};
|
|
256
307
|
exports.indexAnchors = indexAnchors;
|
|
308
|
+
// A heading whose code holds a link to this document reads its address as text, so that
|
|
309
|
+
// address must not depend on reading it: the heading and the target of such a link take
|
|
310
|
+
// the address the html index gave them.
|
|
311
|
+
const headingsWithCodeLinks = (tree, bindings) => {
|
|
312
|
+
const found = new Set();
|
|
313
|
+
const linksInCode = (node, inCode, out) => {
|
|
314
|
+
if (Array.isArray(node))
|
|
315
|
+
return node.forEach(child => linksInCode(child, inCode, out));
|
|
316
|
+
if (!node || typeof node !== 'object')
|
|
317
|
+
return;
|
|
318
|
+
const n = node;
|
|
319
|
+
if (n.type === 'fcode' && inCode && (n.name === 'L' || n.name === 'W')) {
|
|
320
|
+
const target = (0, exports.linkTarget)(n);
|
|
321
|
+
if (typeof target === 'string' && target.startsWith('#') && target.length > 1)
|
|
322
|
+
out.push(target.slice(1));
|
|
323
|
+
}
|
|
324
|
+
linksInCode(n.content, inCode || (n.type === 'fcode' && codeNames.includes(String(n.name))), out);
|
|
325
|
+
};
|
|
326
|
+
walkNodes(tree, node => {
|
|
327
|
+
if (node.type !== 'block' || (node.name !== 'head' && !isSemanticBlock(node)))
|
|
328
|
+
return;
|
|
329
|
+
const targets = [];
|
|
330
|
+
linksInCode(node.content, false, targets);
|
|
331
|
+
if (targets.length === 0)
|
|
332
|
+
return;
|
|
333
|
+
found.add(node);
|
|
334
|
+
for (const target of targets) {
|
|
335
|
+
const bound = bindings ? (0, exports.bindTarget)(target, bindings) : undefined;
|
|
336
|
+
if (bound?.found)
|
|
337
|
+
found.add(bound.node);
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
return found;
|
|
341
|
+
};
|
|
342
|
+
exports.headingsWithCodeLinks = headingsWithCodeLinks;
|
|
257
343
|
// The same headings in the same order, shaped for another output.
|
|
258
344
|
const restyleAnchors = (index, style) => index && {
|
|
259
345
|
...assignAnchors(index.byNode.keys(), style, index.reserved),
|
|
@@ -261,34 +347,47 @@ const restyleAnchors = (index, style) => index && {
|
|
|
261
347
|
footnotes: index.footnotes,
|
|
262
348
|
};
|
|
263
349
|
exports.restyleAnchors = restyleAnchors;
|
|
264
|
-
|
|
265
|
-
=
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
const readerAnchors = (index, renderMode) => {
|
|
350
|
+
const slugsOfWritten = (written) => {
|
|
351
|
+
const occurrences = new Map();
|
|
352
|
+
const slugOf = new Map();
|
|
353
|
+
for (const { node, text } of written) {
|
|
354
|
+
if (text === null)
|
|
355
|
+
continue;
|
|
356
|
+
const base = (0, exports.toMarkdownFragment)(text);
|
|
357
|
+
let slug = base;
|
|
358
|
+
while (occurrences.has(slug)) {
|
|
359
|
+
const count = (occurrences.get(base) || 0) + 1;
|
|
360
|
+
occurrences.set(base, count);
|
|
361
|
+
slug = `${base}-${count}`;
|
|
362
|
+
}
|
|
363
|
+
occurrences.set(slug, 0);
|
|
364
|
+
slugOf.set(node, slug);
|
|
365
|
+
}
|
|
366
|
+
return slugOf;
|
|
367
|
+
};
|
|
368
|
+
const readerAnchors = (index, renderMode, written, alsoNamed) => {
|
|
283
369
|
if (!index)
|
|
284
370
|
return index;
|
|
285
371
|
const headings = index.pageHeadings || [...index.byNode.keys()];
|
|
286
|
-
const slugs = readerSlugs(headings, renderMode !== 'draft', index.footnotes);
|
|
287
372
|
const slugOf = new Map();
|
|
288
|
-
|
|
289
|
-
|
|
373
|
+
if (written)
|
|
374
|
+
slugsOfWritten(written).forEach((slug, node) => slugOf.set(node, slug));
|
|
375
|
+
else {
|
|
376
|
+
const slugs = readerSlugs(headings, renderMode !== 'draft', index.footnotes);
|
|
377
|
+
headings.forEach((node, at) => slugOf.set(node, slugs[at]));
|
|
378
|
+
}
|
|
379
|
+
const named = new Set([...index.byNode.keys()].filter(node => hasOwnAddress(node) || alsoNamed?.has(node)));
|
|
380
|
+
// Every heading the output writes keeps the address the reader builds from its text,
|
|
381
|
+
// a named one too. With the texts the output wrote, a named anchor moves off every such
|
|
382
|
+
// address of another heading; without them, a heading whose address meets a named one
|
|
383
|
+
// is named as well, as before.
|
|
384
|
+
const builtBy = new Map();
|
|
385
|
+
if (written)
|
|
386
|
+
for (const { node, text } of written)
|
|
387
|
+
if (text !== null)
|
|
388
|
+
builtBy.set((slugOf.get(node) || '').toLowerCase(), node);
|
|
290
389
|
const namedAddresses = () => new Set([...named].map(node => (index.byNode.get(node) || '').toLowerCase()));
|
|
291
|
-
for (let changed =
|
|
390
|
+
for (let changed = !written; changed;) {
|
|
292
391
|
changed = false;
|
|
293
392
|
const taken = namedAddresses();
|
|
294
393
|
for (const node of index.byNode.keys()) {
|
|
@@ -301,23 +400,46 @@ const readerAnchors = (index, renderMode) => {
|
|
|
301
400
|
const byNode = new Map();
|
|
302
401
|
const byName = new Map();
|
|
303
402
|
const namesGiven = new Set();
|
|
403
|
+
const takenByOther = (anchor, node) => {
|
|
404
|
+
const owner = builtBy.get(anchor);
|
|
405
|
+
return owner !== undefined && owner !== node;
|
|
406
|
+
};
|
|
407
|
+
// A named place takes its own address, moved off the addresses named before it and off
|
|
408
|
+
// the address a reader builds for another heading. The address the reader builds for
|
|
409
|
+
// this very heading needs no anchor: a second one would give the page the address twice.
|
|
410
|
+
// The address a link writes is the same either way, so a line that holds it keeps its text.
|
|
411
|
+
const nameAnchor = (node, base) => {
|
|
412
|
+
let anchor = base;
|
|
413
|
+
for (let count = 1; namesGiven.has(anchor) || takenByOther(anchor, node);)
|
|
414
|
+
anchor = `${base}-${++count}`;
|
|
415
|
+
namesGiven.add(anchor);
|
|
416
|
+
if (written && builtBy.get(anchor) === node)
|
|
417
|
+
named.delete(node);
|
|
418
|
+
else
|
|
419
|
+
named.add(node);
|
|
420
|
+
return anchor;
|
|
421
|
+
};
|
|
304
422
|
for (const [node, ownAddress] of index.byNode) {
|
|
305
423
|
// lowercased: a reader such as GitHub finds a named anchor by the lowercased
|
|
306
424
|
// address, and one written in capitals is not reached. Two addresses apart only
|
|
307
425
|
// by case would then meet, so a repeat gets a number, as the reader numbers slugs.
|
|
308
|
-
|
|
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
|
-
}
|
|
426
|
+
const anchor = named.has(node) ? nameAnchor(node, ownAddress.toLowerCase()) : slugOf.get(node) || '';
|
|
316
427
|
byNode.set(node, anchor);
|
|
317
428
|
const id = (0, exports.getNodeId)(node, {});
|
|
318
429
|
if (id != null && !hidesText(node) && !byName.has(id.toString()))
|
|
319
430
|
byName.set(id.toString(), anchor);
|
|
320
431
|
}
|
|
432
|
+
// a title or a block named in capitals the author gave an id is reached by a named
|
|
433
|
+
// anchor, under the same rule
|
|
434
|
+
if (written)
|
|
435
|
+
for (const node of headings) {
|
|
436
|
+
if (index.byNode.has(node) || !hasExplicitId(node))
|
|
437
|
+
continue;
|
|
438
|
+
const own = (0, config_1.default)(node, {}).getFirstValue('id');
|
|
439
|
+
if (own == null)
|
|
440
|
+
continue;
|
|
441
|
+
byNode.set(node, nameAnchor(node, (0, exports.toMarkdownFragment)(String(own).replace(/\s/g, '-')).toLowerCase()));
|
|
442
|
+
}
|
|
321
443
|
return {
|
|
322
444
|
byNode,
|
|
323
445
|
byName,
|
|
@@ -438,6 +560,12 @@ const buildBindingIndex = (tree, style = exports.htmlStyle) => {
|
|
|
438
560
|
written.push([key.normalize('NFC').trim(), node, 'explicit-id']);
|
|
439
561
|
}
|
|
440
562
|
}
|
|
563
|
+
// a title with no :id is reached by the id its parse gave it, which the outputs
|
|
564
|
+
// write on its heading, or on an empty anchor when there is nothing to show; an
|
|
565
|
+
// entry of the contents that picks the title asks for it
|
|
566
|
+
if ((0, title_1.isTitleBlock)(node) && typeof node.id === 'string' && (0, exports.getExplicitNodeId)(node, {}) === null) {
|
|
567
|
+
written.push([node.id, node, 'explicit-id']);
|
|
568
|
+
}
|
|
441
569
|
if (node.name !== 'head')
|
|
442
570
|
return;
|
|
443
571
|
const name = (0, _1.getTextContentFromNode)(node).normalize('NFC').trim();
|
package/lib/exportAny.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export type Options = {
|
|
|
2
2
|
processor?: any;
|
|
3
3
|
writer?: any;
|
|
4
4
|
context?: Record<string, unknown>;
|
|
5
|
+
prepare?: (tree: any, context: Record<string, unknown>, walk: (context: Record<string, unknown>, writerClass: (writer: any) => any) => void) => void;
|
|
5
6
|
};
|
|
6
7
|
export declare const toAny: (options?: Options, plugins?: any[]) => {
|
|
7
8
|
(root: any): void;
|
package/lib/exportAny.js
CHANGED
|
@@ -55,6 +55,17 @@ const toAny = (options = {}, plugins = []) => {
|
|
|
55
55
|
const interator = (0, makeInterator_1.default)(newFns.map(rule => (0, makeQuery_1.makeRule)(rule.rule, rule.fn(writer, processor, tree))).reverse());
|
|
56
56
|
// Every exporter needs the same anchors: assigned once, before the walk starts.
|
|
57
57
|
const context = { __anchors: (0, ast_helpers_1.indexAnchors)(tree), __bindings: (0, ast_helpers_1.buildBindingIndex)(tree), ...(options.context || {}) };
|
|
58
|
+
if (options.prepare) {
|
|
59
|
+
const walkAside = (asideContext, writerClass) => {
|
|
60
|
+
const WriterClass = writerClass(writer);
|
|
61
|
+
const aside = new WriterClass(() => { });
|
|
62
|
+
const walk = (0, makeInterator_1.default)(newFns.map(rule => (0, makeQuery_1.makeRule)(rule.rule, rule.fn(aside, processor, tree))).reverse());
|
|
63
|
+
aside.startWrite(tree);
|
|
64
|
+
walk(tree, asideContext);
|
|
65
|
+
aside.endWrite();
|
|
66
|
+
};
|
|
67
|
+
options.prepare(tree, context, walkAside);
|
|
68
|
+
}
|
|
58
69
|
writer.startWrite(tree);
|
|
59
70
|
const result = interator(tree, context);
|
|
60
71
|
writer.endWrite();
|
package/lib/exportHtml.js
CHANGED
|
@@ -43,6 +43,7 @@ const config_1 = __importStar(require("./helpers/config"));
|
|
|
43
43
|
const configPropagation_1 = require("./helpers/configPropagation");
|
|
44
44
|
const image_base_1 = require("./image-base");
|
|
45
45
|
const guard_1 = require("./guard");
|
|
46
|
+
const title_1 = require("./title");
|
|
46
47
|
const writerHtml_1 = __importDefault(require("./writerHtml"));
|
|
47
48
|
const plugin_clean_location_1 = __importDefault(require("./plugin-clean-location"));
|
|
48
49
|
const alias_1 = require("./helpers/alias");
|
|
@@ -97,6 +98,59 @@ const atLine = (node) => {
|
|
|
97
98
|
};
|
|
98
99
|
const label = (value) => (typeof value === 'string' ? value : '?');
|
|
99
100
|
const covered = (node, ctx, text) => ((0, guard_1.isCovered)(node, ctx) ? (0, handlers_1.maskText)(text) : text);
|
|
101
|
+
// What a part of the output writes, kept aside instead of written
|
|
102
|
+
const writtenAside = (writer, write) => {
|
|
103
|
+
const original = writer.output;
|
|
104
|
+
const parts = [];
|
|
105
|
+
writer.output = (str) => parts.push(str);
|
|
106
|
+
try {
|
|
107
|
+
write();
|
|
108
|
+
}
|
|
109
|
+
finally {
|
|
110
|
+
writer.output = original;
|
|
111
|
+
}
|
|
112
|
+
return parts.join('');
|
|
113
|
+
};
|
|
114
|
+
// A part of a title is seen when it shows a character or a picture
|
|
115
|
+
const seenHtml = (html) => /<img\b/.test(html) || /\S/.test((0, entities_1.decodeHTMLStrict)(html.replace(/<[^>]*>/g, '')));
|
|
116
|
+
// a paragraph a title takes apart keeps its own mask for the text it gives the title
|
|
117
|
+
const maskedOwner = (owner, ctx) => {
|
|
118
|
+
if (ctx?.maskMode || ctx?.renderMode === 'draft')
|
|
119
|
+
return false;
|
|
120
|
+
if (owner.guarded)
|
|
121
|
+
return true;
|
|
122
|
+
const conf = (0, config_1.default)(owner, ctx || {});
|
|
123
|
+
return Boolean(conf.exists('masked') && conf.getFirstValue('masked'));
|
|
124
|
+
};
|
|
125
|
+
// =TITLE shows its content as the title of the document, as to-jsx does: its paragraphs
|
|
126
|
+
// in one heading, other blocks after it, a directive acting from where it stands. A
|
|
127
|
+
// title with nothing to show keeps only an empty anchor, so a link to it has a target.
|
|
128
|
+
const titleBlock = (writer, node, ctx, interator) => {
|
|
129
|
+
const heading = [];
|
|
130
|
+
const rest = [];
|
|
131
|
+
(0, title_1.titleParts)(node).forEach(entry => {
|
|
132
|
+
if (entry.kind === 'rest') {
|
|
133
|
+
rest.push(writtenAside(writer, () => interator([entry.node], ctx)));
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
const masked = entry.owners.some(owner => maskedOwner(owner, ctx));
|
|
137
|
+
const part = writtenAside(writer, () => interator(entry.content, masked ? { ...ctx, maskMode: true } : ctx));
|
|
138
|
+
if (seenHtml(part))
|
|
139
|
+
heading.push(part);
|
|
140
|
+
});
|
|
141
|
+
const id = (0, ast_helpers_1.getSafeNodeId)(node, ctx);
|
|
142
|
+
const anchor = id ? ` id="${id}"` : '';
|
|
143
|
+
if (heading.length) {
|
|
144
|
+
writer.writeRaw('<h1 class="');
|
|
145
|
+
writer.write(node.name);
|
|
146
|
+
writer.writeRaw(`"${anchor}>${heading.join(' ')}</h1>`);
|
|
147
|
+
}
|
|
148
|
+
else if (anchor) {
|
|
149
|
+
// nothing to show, but an entry of the contents or a link may still lead here
|
|
150
|
+
writer.writeRaw(`<span${anchor}></span>`);
|
|
151
|
+
}
|
|
152
|
+
rest.forEach(html => writer.writeRaw(html));
|
|
153
|
+
};
|
|
100
154
|
const openTag = (tag, node, ctx, attrs = '') => {
|
|
101
155
|
const id = anchorOf(node, ctx);
|
|
102
156
|
return `<${tag}${id ? ` id="${id}"` : ''}${attrs}>`;
|
|
@@ -549,7 +603,8 @@ const rules = {
|
|
|
549
603
|
// one as "decorative", so an alternative text the author never wrote is left out
|
|
550
604
|
const altText = (0, ast_helpers_1.writtenValue)(node.alt);
|
|
551
605
|
const alt = altText === undefined ? '' : ` alt="${(0, html_attr_1.quoteAttribute)(covered(node, ctx, altText))}"`;
|
|
552
|
-
|
|
606
|
+
const title = typeof node.title === 'string' ? ` title="${(0, html_attr_1.quoteAttribute)(covered(node, ctx, node.title))}"` : '';
|
|
607
|
+
writer.writeRaw(`<img src="${src}"${alt}${title}/>`);
|
|
553
608
|
},
|
|
554
609
|
};
|
|
555
610
|
const toHtml = opt => (0, exportAny_1.default)({
|
|
@@ -570,6 +625,8 @@ const toHtml = opt => (0, exportAny_1.default)({
|
|
|
570
625
|
if ((0, makeTransformer_1.isNamedBlock)(node.name)) {
|
|
571
626
|
return true;
|
|
572
627
|
}
|
|
628
|
+
if ((0, title_1.isTitleBlock)(node))
|
|
629
|
+
return titleBlock(writer, node, ctx, interator);
|
|
573
630
|
if (isSemanticBlock(node)) {
|
|
574
631
|
const name = node.name;
|
|
575
632
|
writer.writeRaw('<h1 class="');
|