@mdzip/renderer 0.0.0-stage → 0.2.0
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/README.md +164 -3
- package/dist/highlight-core.d.ts +3 -0
- package/dist/highlight-core.d.ts.map +1 -0
- package/dist/highlight-core.js +53 -0
- package/dist/highlight-core.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/markdown.d.ts +209 -0
- package/dist/markdown.d.ts.map +1 -0
- package/dist/markdown.js +521 -0
- package/dist/markdown.js.map +1 -0
- package/dist/page.d.ts +90 -0
- package/dist/page.d.ts.map +1 -0
- package/dist/page.js +277 -0
- package/dist/page.js.map +1 -0
- package/dist/sha256.d.ts +10 -0
- package/dist/sha256.d.ts.map +1 -0
- package/dist/sha256.js +83 -0
- package/dist/sha256.js.map +1 -0
- package/package.json +61 -6
package/dist/markdown.js
ADDED
|
@@ -0,0 +1,521 @@
|
|
|
1
|
+
import DOMPurify from 'dompurify';
|
|
2
|
+
import { Marked } from 'marked';
|
|
3
|
+
import markedFootnote from 'marked-footnote';
|
|
4
|
+
import hljs from './highlight-core.js';
|
|
5
|
+
// --- Sanitizing ---------------------------------------------------------------
|
|
6
|
+
// In browsers the dompurify default export is already bound to the global
|
|
7
|
+
// window. In Node it is an unbound factory: bind it to a DOM window passed to
|
|
8
|
+
// useMdzipDomWindow(), or to one assigned to globalThis.window (jsdom, say).
|
|
9
|
+
let purifier = null;
|
|
10
|
+
function findPurifier() {
|
|
11
|
+
if (purifier) {
|
|
12
|
+
return purifier;
|
|
13
|
+
}
|
|
14
|
+
if (typeof DOMPurify.sanitize === 'function' && DOMPurify.isSupported) {
|
|
15
|
+
purifier = DOMPurify;
|
|
16
|
+
return purifier;
|
|
17
|
+
}
|
|
18
|
+
const globalWindow = globalThis.window;
|
|
19
|
+
if (!globalWindow) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
purifier = DOMPurify(globalWindow);
|
|
23
|
+
return purifier;
|
|
24
|
+
}
|
|
25
|
+
function resolvePurifier() {
|
|
26
|
+
const found = findPurifier();
|
|
27
|
+
if (!found) {
|
|
28
|
+
throw new Error('Sanitizing needs a DOM. In Node, call useMdzipDomWindow(new JSDOM().window) first, '
|
|
29
|
+
+ 'use renderMdzPage() from @mdzip/renderer/page (it loads jsdom itself), or pass sanitize: false for trusted input.');
|
|
30
|
+
}
|
|
31
|
+
return found;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Gives the sanitizer a DOM window to work in, for environments without a
|
|
35
|
+
* global one (Node). The window isn't assigned to any global.
|
|
36
|
+
*
|
|
37
|
+
* ```js
|
|
38
|
+
* import { JSDOM } from 'jsdom';
|
|
39
|
+
* useMdzipDomWindow(new JSDOM('').window);
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export function useMdzipDomWindow(window) {
|
|
43
|
+
purifier = DOMPurify(window);
|
|
44
|
+
}
|
|
45
|
+
/** Whether sanitizing can run here: a browser, or a window from {@link useMdzipDomWindow} or `globalThis.window`. */
|
|
46
|
+
export function hasMdzipDom() {
|
|
47
|
+
return findPurifier() !== null;
|
|
48
|
+
}
|
|
49
|
+
const BASE_FORBID_TAGS = ['base', 'embed', 'form', 'iframe', 'input', 'link', 'meta', 'object', 'script', 'style'];
|
|
50
|
+
const BASE_FORBID_ATTR = ['style'];
|
|
51
|
+
function lower(value) {
|
|
52
|
+
return value.toLowerCase();
|
|
53
|
+
}
|
|
54
|
+
function buildSanitizeOptions(contributions) {
|
|
55
|
+
const allowSvg = contributions.some((contribution) => contribution.allowSvg);
|
|
56
|
+
const addTags = [...new Set(contributions.flatMap((contribution) => contribution.addTags ?? []))];
|
|
57
|
+
const addAttr = ['class', ...new Set(contributions.flatMap((contribution) => contribution.addAttr ?? []))];
|
|
58
|
+
const unforbidTags = new Set(contributions.flatMap((contribution) => contribution.unforbidTags ?? []).map(lower));
|
|
59
|
+
const unforbidAttr = new Set(contributions.flatMap((contribution) => contribution.unforbidAttr ?? []).map(lower));
|
|
60
|
+
return {
|
|
61
|
+
USE_PROFILES: allowSvg ? { html: true, svg: true, svgFilters: true } : { html: true },
|
|
62
|
+
ADD_TAGS: addTags,
|
|
63
|
+
ADD_ATTR: addAttr,
|
|
64
|
+
FORBID_TAGS: BASE_FORBID_TAGS.filter((tag) => !unforbidTags.has(tag)),
|
|
65
|
+
FORBID_ATTR: BASE_FORBID_ATTR.filter((attr) => !unforbidAttr.has(attr)),
|
|
66
|
+
ALLOW_DATA_ATTR: false
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Sanitizes rendered HTML with the MDZip DOMPurify policy, then finishes it
|
|
71
|
+
* (see {@link finishMdzipHtml}).
|
|
72
|
+
*
|
|
73
|
+
* The policy strips data attributes and inline styles. Markdown render
|
|
74
|
+
* extensions that need to find placeholders again later should use class or
|
|
75
|
+
* id markers and carry payloads out-of-band (a side map keyed by marker id),
|
|
76
|
+
* not element attributes.
|
|
77
|
+
*
|
|
78
|
+
* Pass `contributions` (an extension's {@link MdzipSanitizeContribution}s) to
|
|
79
|
+
* widen the policy just enough for richer output such as inline SVG.
|
|
80
|
+
*/
|
|
81
|
+
export function sanitizeMdzipHtml(html, contributions = [], options = {}) {
|
|
82
|
+
return finishMdzipHtml(resolvePurifier().sanitize(html, buildSanitizeOptions(contributions)), options);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Turns the renderer's markers into their final markup: task-list checkboxes
|
|
86
|
+
* and heading ids. {@link sanitizeMdzipHtml} calls this; call it yourself only
|
|
87
|
+
* for HTML from {@link parseMdzipTokens} that isn't sanitized.
|
|
88
|
+
*
|
|
89
|
+
* The markers exist because the sanitizer would otherwise remove what they
|
|
90
|
+
* stand for: `<input>` is forbidden (so raw-HTML inputs are always stripped,
|
|
91
|
+
* and only task items get checkboxes), and DOMPurify drops an id that names a
|
|
92
|
+
* `document` property, such as a heading called "Images" or "Links".
|
|
93
|
+
*/
|
|
94
|
+
export function finishMdzipHtml(html, options = {}) {
|
|
95
|
+
let result = restoreTaskCheckboxes(html);
|
|
96
|
+
if (result.includes(HEADING_ID_MARK)) {
|
|
97
|
+
result = result.split(`id="${HEADING_ID_MARK}`).join(`id="${options.headingIdPrefix ?? ''}`);
|
|
98
|
+
}
|
|
99
|
+
if (options.externalLinks === 'new-tab') {
|
|
100
|
+
result = result.replace(EXTERNAL_ANCHOR, (match, attrs) => (/\starget\s*=/i.test(attrs) ? match : `<a${attrs} target="_blank" rel="noopener">`));
|
|
101
|
+
}
|
|
102
|
+
return result;
|
|
103
|
+
}
|
|
104
|
+
const EXTERNAL_ANCHOR = /<a\b([^>]*\shref="(?:https?:)?\/\/[^"]*"[^>]*)>/gi;
|
|
105
|
+
const TASK_CHECKBOX_PLACEHOLDER = /<span class="mdzip-task-checkbox( mdzip-task-checked)?"><\/span>/g;
|
|
106
|
+
function taskCheckboxPlaceholder(checked) {
|
|
107
|
+
return `<span class="mdzip-task-checkbox${checked ? ' mdzip-task-checked' : ''}"></span>`;
|
|
108
|
+
}
|
|
109
|
+
function restoreTaskCheckboxes(html) {
|
|
110
|
+
if (!html.includes('mdzip-task-checkbox')) {
|
|
111
|
+
return html;
|
|
112
|
+
}
|
|
113
|
+
return html.replace(TASK_CHECKBOX_PLACEHOLDER, (_match, checked) => `<input type="checkbox" class="task-list-item-checkbox" disabled=""${checked ? ' checked=""' : ''}>`);
|
|
114
|
+
}
|
|
115
|
+
function randomMarker() {
|
|
116
|
+
const bytes = new Uint8Array(6);
|
|
117
|
+
const webCrypto = globalThis.crypto;
|
|
118
|
+
if (webCrypto?.getRandomValues) {
|
|
119
|
+
webCrypto.getRandomValues(bytes);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
for (let i = 0; i < bytes.length; i += 1)
|
|
123
|
+
bytes[i] = Math.floor(Math.random() * 256);
|
|
124
|
+
}
|
|
125
|
+
return [...bytes].map((byte) => byte.toString(16).padStart(2, '0')).join('');
|
|
126
|
+
}
|
|
127
|
+
// A heading id is rendered as this marker plus the slug, and the marker is
|
|
128
|
+
// replaced by the prefix after sanitizing. Random per load, so a document
|
|
129
|
+
// can't write an id that turns into something else.
|
|
130
|
+
const HEADING_ID_MARK = `mdzip-h${randomMarker()}-`;
|
|
131
|
+
function decodeBasicEntities(text) {
|
|
132
|
+
return text
|
|
133
|
+
.replace(/&#x([0-9a-f]+);/gi, (_, hex) => String.fromCodePoint(parseInt(hex, 16)))
|
|
134
|
+
.replace(/&#(\d+);/g, (_, dec) => String.fromCodePoint(parseInt(dec, 10)))
|
|
135
|
+
.replace(/"/g, '"')
|
|
136
|
+
.replace(/'|'/g, "'")
|
|
137
|
+
.replace(/</g, '<')
|
|
138
|
+
.replace(/>/g, '>')
|
|
139
|
+
.replace(/&/g, '&')
|
|
140
|
+
// Any other named entity (© etc.) decodes to a symbol the slug
|
|
141
|
+
// pass would strip anyway.
|
|
142
|
+
.replace(/&[a-z][a-z0-9]*;/gi, '');
|
|
143
|
+
}
|
|
144
|
+
function inlineTokensPlainText(tokens) {
|
|
145
|
+
let text = '';
|
|
146
|
+
for (const token of tokens ?? []) {
|
|
147
|
+
const inline = token;
|
|
148
|
+
if (inline.type === 'br') {
|
|
149
|
+
text += ' ';
|
|
150
|
+
}
|
|
151
|
+
else if (inline.type === 'html') {
|
|
152
|
+
// Tag markers only — their inner text arrives as sibling text tokens.
|
|
153
|
+
}
|
|
154
|
+
else if (inline.tokens) {
|
|
155
|
+
text += inlineTokensPlainText(inline.tokens);
|
|
156
|
+
}
|
|
157
|
+
else if (typeof inline.text === 'string') {
|
|
158
|
+
text += inline.text;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return decodeBasicEntities(text);
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* The heading slug shared by the MDZip editor, mdzip.org and the MDZip Pandoc
|
|
165
|
+
* filter: lowercased; everything but letters, marks, numbers, `_`, `-` and
|
|
166
|
+
* whitespace removed (so punctuation and emoji go); each run of whitespace and
|
|
167
|
+
* hyphens turned into one `-`; and no `-` at either end.
|
|
168
|
+
*
|
|
169
|
+
* `Why isn't it "here"?` → `why-isnt-it-here`, `mdz — the CLI` → `mdz-the-cli`,
|
|
170
|
+
* `🪟 Windows` → `windows`, `Über Café` → `über-café`.
|
|
171
|
+
*/
|
|
172
|
+
export function slugifyMdzipHeading(text) {
|
|
173
|
+
return text
|
|
174
|
+
.toLowerCase()
|
|
175
|
+
.replace(/[^\p{L}\p{M}\p{N}\p{Pc}\s-]/gu, '')
|
|
176
|
+
.replace(/[\s-]+/g, '-')
|
|
177
|
+
.replace(/^-+|-+$/g, '');
|
|
178
|
+
}
|
|
179
|
+
function forEachHeadingToken(tokens, visit) {
|
|
180
|
+
for (const token of tokens) {
|
|
181
|
+
if (token.type === 'heading') {
|
|
182
|
+
visit(token);
|
|
183
|
+
}
|
|
184
|
+
else if (token.type === 'blockquote' || token.type === 'list' || token.type === 'list_item') {
|
|
185
|
+
const container = token;
|
|
186
|
+
forEachHeadingToken(container.tokens ?? container.items ?? [], visit);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Gives every heading token (including ones nested in blockquotes and lists)
|
|
192
|
+
* the id its rendered `<hN>` will carry, in document order, numbering repeats
|
|
193
|
+
* as GitHub does (`intro`, `intro-1`, `intro-2`). Has to run over the whole
|
|
194
|
+
* document's tokens before they are split into chunks — a chunk rendered on
|
|
195
|
+
* its own can't know how many earlier chunks already used a slug. A heading
|
|
196
|
+
* whose text slugifies to nothing (e.g. only punctuation) gets no id.
|
|
197
|
+
*/
|
|
198
|
+
export function assignMdzipHeadingIds(tokens) {
|
|
199
|
+
const used = new Map();
|
|
200
|
+
forEachHeadingToken(tokens, (token) => {
|
|
201
|
+
const base = slugifyMdzipHeading(inlineTokensPlainText(token.tokens));
|
|
202
|
+
if (!base) {
|
|
203
|
+
delete token.mdzipAnchorId;
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
let candidate = base;
|
|
207
|
+
while (used.has(candidate)) {
|
|
208
|
+
const next = (used.get(base) ?? 0) + 1;
|
|
209
|
+
used.set(base, next);
|
|
210
|
+
candidate = `${base}-${next}`;
|
|
211
|
+
}
|
|
212
|
+
used.set(candidate, 0);
|
|
213
|
+
token.mdzipAnchorId = candidate;
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
/** The ids {@link assignMdzipHeadingIds} gave the headings in `tokens`, in order (without any prefix). */
|
|
217
|
+
export function collectMdzipHeadingIds(tokens) {
|
|
218
|
+
const ids = [];
|
|
219
|
+
forEachHeadingToken(tokens, (token) => {
|
|
220
|
+
if (token.mdzipAnchorId) {
|
|
221
|
+
ids.push(token.mdzipAnchorId);
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
return ids;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Every heading that has an id, in document order, for a table of contents.
|
|
228
|
+
* Run {@link assignMdzipHeadingIds} (or {@link tokenizeMdzipMarkdown}) on the
|
|
229
|
+
* tokens first.
|
|
230
|
+
*/
|
|
231
|
+
export function collectMdzipHeadings(tokens) {
|
|
232
|
+
const headings = [];
|
|
233
|
+
forEachHeadingToken(tokens, (token) => {
|
|
234
|
+
if (token.mdzipAnchorId) {
|
|
235
|
+
const text = inlineTokensPlainText(token.tokens).replace(/\s+/g, ' ').trim();
|
|
236
|
+
headings.push({ id: token.mdzipAnchorId, text, level: token.depth });
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
return headings;
|
|
240
|
+
}
|
|
241
|
+
// --- Code highlighting --------------------------------------------------------
|
|
242
|
+
/**
|
|
243
|
+
* Highlights `code` with highlight.js when `language` is one of the bundled
|
|
244
|
+
* grammars (`vue` counts as `html`); returns `null` otherwise. The output is
|
|
245
|
+
* highlight.js's span markup, for a `<code class="hljs">`.
|
|
246
|
+
*/
|
|
247
|
+
export function highlightMdzipCode(code, language) {
|
|
248
|
+
const grammar = language === 'vue' ? 'html' : language;
|
|
249
|
+
if (!grammar || !hljs.getLanguage(grammar)) {
|
|
250
|
+
return null;
|
|
251
|
+
}
|
|
252
|
+
try {
|
|
253
|
+
return hljs.highlight(code, { language: grammar, ignoreIllegals: true }).value;
|
|
254
|
+
}
|
|
255
|
+
catch {
|
|
256
|
+
return null;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
// --- Video -------------------------------------------------------------------
|
|
260
|
+
/**
|
|
261
|
+
* File extensions an image reference (``) renders as a video
|
|
262
|
+
* player instead of an `<img>`. Whether a given file plays depends on the
|
|
263
|
+
* browser: most play H.264 or VP9 video in an `.mp4` or `.webm`.
|
|
264
|
+
*/
|
|
265
|
+
export const MDZIP_VIDEO_EXTENSIONS = ['mp4', 'm4v', 'webm', 'ogv', 'mov'];
|
|
266
|
+
const VIDEO_PATH = new RegExp(`\\.(?:${MDZIP_VIDEO_EXTENSIONS.join('|')})$`, 'i');
|
|
267
|
+
/** Whether a path or URL names a video file, ignoring any `?query` or `#fragment` (`reel.mp4#t=83` is a video). */
|
|
268
|
+
export function isMdzipVideoPath(path) {
|
|
269
|
+
return VIDEO_PATH.test(path.split(/[?#]/, 1)[0] ?? '');
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* The start time, in seconds, of a media fragment (`#t=83`, `#t=1:23`,
|
|
273
|
+
* `#t=npt:0:01:23.5`, `#t=83,95`), or `null` when the fragment has none.
|
|
274
|
+
* Accepts the fragment with or without its `#`, or a whole URL.
|
|
275
|
+
*/
|
|
276
|
+
export function parseMdzipMediaTime(fragmentOrUrl) {
|
|
277
|
+
const hash = fragmentOrUrl.includes('#') ? fragmentOrUrl.slice(fragmentOrUrl.indexOf('#') + 1) : fragmentOrUrl;
|
|
278
|
+
const value = /(?:^|&)t=(?:npt:)?([^&,]*)/i.exec(hash)?.[1];
|
|
279
|
+
if (!value) {
|
|
280
|
+
return null;
|
|
281
|
+
}
|
|
282
|
+
const match = /^(?:(?:(\d+):)?(\d+):)?(\d+(?:\.\d+)?)$/.exec(value);
|
|
283
|
+
if (!match) {
|
|
284
|
+
return null;
|
|
285
|
+
}
|
|
286
|
+
const [, hours, minutes, seconds] = match;
|
|
287
|
+
return Number(hours ?? 0) * 3600 + Number(minutes ?? 0) * 60 + Number(seconds);
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* A video player for an image reference to a video file. The alt text labels
|
|
291
|
+
* the player and, as a link to the file, is what a browser that can't play
|
|
292
|
+
* video at all shows instead.
|
|
293
|
+
*/
|
|
294
|
+
function renderVideo(href, title, text) {
|
|
295
|
+
const src = escapeHtml(href);
|
|
296
|
+
const label = text ? ` aria-label="${escapeHtml(text)}"` : '';
|
|
297
|
+
const titleAttr = title ? ` title="${escapeHtml(title)}"` : '';
|
|
298
|
+
const fallback = escapeHtml(text || href.split(/[?#]/, 1)[0].split('/').pop() || href);
|
|
299
|
+
return `<video class="mdzip-video" controls preload="metadata" src="${src}"${label}${titleAttr}><a href="${src}">${fallback}</a></video>`;
|
|
300
|
+
}
|
|
301
|
+
// --- Marked -----------------------------------------------------------------
|
|
302
|
+
const marked = new Marked({
|
|
303
|
+
renderer: {
|
|
304
|
+
// An image reference to a video file is a player; any other image falls
|
|
305
|
+
// back to marked's own <img> rendering.
|
|
306
|
+
image(token) {
|
|
307
|
+
if (typeof token.href !== 'string' || !isMdzipVideoPath(token.href)) {
|
|
308
|
+
return false;
|
|
309
|
+
}
|
|
310
|
+
return renderVideo(token.href, token.title, token.text);
|
|
311
|
+
},
|
|
312
|
+
heading(token) {
|
|
313
|
+
const id = token.mdzipAnchorId ? ` id="${HEADING_ID_MARK}${escapeHtml(token.mdzipAnchorId)}"` : '';
|
|
314
|
+
return `<h${token.depth}${id}>${this.parser.parseInline(token.tokens)}</h${token.depth}>\n`;
|
|
315
|
+
},
|
|
316
|
+
code(token) {
|
|
317
|
+
const requestedLanguage = token.lang || '';
|
|
318
|
+
const highlighted = highlightMdzipCode(token.text, requestedLanguage);
|
|
319
|
+
if (highlighted !== null) {
|
|
320
|
+
return `<pre><code class="hljs language-${escapeHtml(requestedLanguage)}">${highlighted}</code></pre>`;
|
|
321
|
+
}
|
|
322
|
+
// Preserve the requested language as a class even when it is not a
|
|
323
|
+
// highlightable language (e.g. `mermaid`), so render extensions and
|
|
324
|
+
// client-side highlighters can still find and claim the block.
|
|
325
|
+
const className = requestedLanguage ? ` class="language-${escapeHtml(requestedLanguage)}"` : '';
|
|
326
|
+
return `<pre><code${className}>${escapeHtml(token.text)}</code></pre>`;
|
|
327
|
+
},
|
|
328
|
+
list(token) {
|
|
329
|
+
const type = token.ordered ? 'ol' : 'ul';
|
|
330
|
+
const start = token.ordered && token.start !== 1 && token.start !== '' ? ` start="${token.start}"` : '';
|
|
331
|
+
const className = token.items.some((item) => item.task) ? ' class="contains-task-list"' : '';
|
|
332
|
+
const body = token.items.map((item) => this.listitem(item)).join('');
|
|
333
|
+
return `<${type}${start}${className}>\n${body}</${type}>\n`;
|
|
334
|
+
},
|
|
335
|
+
// Same as marked's listitem, plus GitHub's `task-list-item` class. The
|
|
336
|
+
// checkbox is a token inside the item (inside its first paragraph when
|
|
337
|
+
// the list is loose), rendered by `checkbox` below.
|
|
338
|
+
listitem(item) {
|
|
339
|
+
return `<li${item.task ? ' class="task-list-item"' : ''}>${this.parser.parse(item.tokens)}</li>\n`;
|
|
340
|
+
},
|
|
341
|
+
checkbox({ checked }) {
|
|
342
|
+
return `${taskCheckboxPlaceholder(checked)} `;
|
|
343
|
+
},
|
|
344
|
+
table(token) {
|
|
345
|
+
const renderCell = (cell) => {
|
|
346
|
+
const tag = cell.header ? 'th' : 'td';
|
|
347
|
+
const align = cell.align ? ` align="${cell.align}"` : '';
|
|
348
|
+
return `<${tag}${align}>${this.parser.parseInline(cell.tokens)}</${tag}>\n`;
|
|
349
|
+
};
|
|
350
|
+
const renderRow = (cells) => `<tr>\n${cells.map(renderCell).join('')}</tr>\n`;
|
|
351
|
+
const header = renderRow(token.header);
|
|
352
|
+
const body = token.rows.length
|
|
353
|
+
? `<tbody>\n${token.rows.map(renderRow).join('')}</tbody>\n`
|
|
354
|
+
: '';
|
|
355
|
+
return `<div class="mdzip-table-scroll"><table>\n<thead>\n${header}</thead>\n${body}</table></div>\n`;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
});
|
|
359
|
+
// GFM footnotes: `[^1]` references and `[^1]: ...` definitions, rendered as
|
|
360
|
+
// superscript links to a footnotes section at the end, with back-links.
|
|
361
|
+
marked.use(markedFootnote());
|
|
362
|
+
/**
|
|
363
|
+
* Calls `callback` on every token, depth first, in the same order as marked's
|
|
364
|
+
* own `walkTokens` (table cells, list items, extension child tokens, then
|
|
365
|
+
* `tokens`). Marked's version also collects every callback's return value by
|
|
366
|
+
* concatenating arrays as it goes, which is quadratic in the token count: on
|
|
367
|
+
* a large chat export it took 13 seconds plus 6 of garbage collection. Those
|
|
368
|
+
* values only matter to marked's async mode, which isn't used here.
|
|
369
|
+
*/
|
|
370
|
+
export function walkMdzipTokens(tokens, callback) {
|
|
371
|
+
const childTokens = marked.defaults.extensions?.childTokens ?? {};
|
|
372
|
+
const visit = (list) => {
|
|
373
|
+
for (const token of list) {
|
|
374
|
+
callback.call(marked, token);
|
|
375
|
+
switch (token.type) {
|
|
376
|
+
case 'table': {
|
|
377
|
+
const table = token;
|
|
378
|
+
for (const cell of table.header) {
|
|
379
|
+
visit(cell.tokens);
|
|
380
|
+
}
|
|
381
|
+
for (const row of table.rows) {
|
|
382
|
+
for (const cell of row) {
|
|
383
|
+
visit(cell.tokens);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
break;
|
|
387
|
+
}
|
|
388
|
+
case 'list':
|
|
389
|
+
visit(token.items);
|
|
390
|
+
break;
|
|
391
|
+
default: {
|
|
392
|
+
const names = childTokens[token.type];
|
|
393
|
+
if (names) {
|
|
394
|
+
for (const name of names) {
|
|
395
|
+
visit((token[name] ?? []).flat(Infinity));
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
else if ('tokens' in token && token.tokens) {
|
|
399
|
+
visit(token.tokens);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
};
|
|
405
|
+
visit(tokens);
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* `marked.lexer()` plus the extensions' `walkTokens` hooks, which marked only
|
|
409
|
+
* runs inside `parse()`. The footnote extension needs its hook to move the
|
|
410
|
+
* footnotes section to the end and reset its per-document state.
|
|
411
|
+
*/
|
|
412
|
+
function lexMarkdown(markdown) {
|
|
413
|
+
const tokens = marked.lexer(markdown);
|
|
414
|
+
const walkTokens = marked.defaults.walkTokens;
|
|
415
|
+
if (walkTokens) {
|
|
416
|
+
walkMdzipTokens(tokens, walkTokens);
|
|
417
|
+
}
|
|
418
|
+
// The extension adds its section token to every document, first; the hook
|
|
419
|
+
// moves a non-empty one to the end and leaves an empty `space` token behind.
|
|
420
|
+
// Drop both leftovers so token positions (and chunking) are as before.
|
|
421
|
+
for (let i = tokens.length - 1; i >= 0; i -= 1) {
|
|
422
|
+
const token = tokens[i];
|
|
423
|
+
const emptySection = token.type === 'footnotes' && !token.items?.length;
|
|
424
|
+
const placeholder = i === 0 && token.type === 'space' && token.raw === '';
|
|
425
|
+
if (emptySection || placeholder) {
|
|
426
|
+
tokens.splice(i, 1);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
return tokens;
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Lexes Markdown into top-level block tokens with heading ids assigned, for
|
|
433
|
+
* callers that render it in parts (see {@link parseMdzipTokens}). The tokens
|
|
434
|
+
* tile the source: their `raw` strings joined give back the whole input.
|
|
435
|
+
*/
|
|
436
|
+
export function tokenizeMdzipMarkdown(markdown) {
|
|
437
|
+
const tokens = lexMarkdown(markdown);
|
|
438
|
+
assignMdzipHeadingIds(tokens);
|
|
439
|
+
return tokens;
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Renders tokens from {@link tokenizeMdzipMarkdown} to HTML that is neither
|
|
443
|
+
* sanitized nor finished: pass it through {@link sanitizeMdzipHtml} (or,
|
|
444
|
+
* for trusted input, {@link finishMdzipHtml}) before use.
|
|
445
|
+
*/
|
|
446
|
+
export function parseMdzipTokens(tokens, options = {}) {
|
|
447
|
+
if (!options.markBlocks) {
|
|
448
|
+
return marked.parser(tokens);
|
|
449
|
+
}
|
|
450
|
+
// A comment before each top-level token's output. One parse, as without marks.
|
|
451
|
+
const withMarks = [];
|
|
452
|
+
tokens.forEach((token, index) => {
|
|
453
|
+
withMarks.push({ type: 'html', block: true, pre: false, raw: '', text: `<!--${BLOCK_MARK}${index}-->` }, token);
|
|
454
|
+
});
|
|
455
|
+
return marked.parser(withMarks);
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* The attribute {@link applyMdzipBlockMarks} puts on the first element each
|
|
459
|
+
* top-level token rendered to: the token's index in the list given to
|
|
460
|
+
* {@link parseMdzipTokens}. Allow it when sanitizing (`addAttr`) to keep it.
|
|
461
|
+
*/
|
|
462
|
+
export const MDZIP_BLOCK_ATTRIBUTE = 'data-mdzip-block';
|
|
463
|
+
const BLOCK_MARK = 'mdzip-block:';
|
|
464
|
+
const BLOCK_MARK_BEFORE_TAG = /<!--mdzip-block:(\d+)-->(\s*)<([a-zA-Z][a-zA-Z0-9-]*)/g;
|
|
465
|
+
const BLOCK_MARK_LEFT = /<!--mdzip-block:\d+-->/g;
|
|
466
|
+
const BLOCK_ATTRIBUTE = /\sdata-mdzip-block="\d+"/g;
|
|
467
|
+
/**
|
|
468
|
+
* Turns the comments {@link parseMdzipTokens} `markBlocks` leaves into
|
|
469
|
+
* `data-mdzip-block="<index>"` on the element that follows each, and drops
|
|
470
|
+
* those with no element after them (a blank line, a raw HTML comment).
|
|
471
|
+
*/
|
|
472
|
+
export function applyMdzipBlockMarks(html) {
|
|
473
|
+
return html
|
|
474
|
+
.replace(BLOCK_MARK_BEFORE_TAG, (_match, index, space, tag) => `${space}<${tag} ${MDZIP_BLOCK_ATTRIBUTE}="${index}"`)
|
|
475
|
+
.replace(BLOCK_MARK_LEFT, '');
|
|
476
|
+
}
|
|
477
|
+
/** Removes block marks, comments or attributes, from HTML that leaves the page (a copy, an export). */
|
|
478
|
+
export function stripMdzipBlockMarks(html) {
|
|
479
|
+
return html.replace(BLOCK_ATTRIBUTE, '').replace(BLOCK_MARK_LEFT, '');
|
|
480
|
+
}
|
|
481
|
+
const EXTERNAL_OR_ANCHOR = /^(?:[a-z][a-z0-9+.-]*:|\/\/|#)/i;
|
|
482
|
+
/**
|
|
483
|
+
* Rewrites the `href` of every Markdown link in `tokens` through `resolve`.
|
|
484
|
+
* Links that are absolute (`https:`, `mailto:`, any scheme), protocol-relative
|
|
485
|
+
* or in-page (`#…`) are left alone. Raw HTML `<a>` tags aren't touched.
|
|
486
|
+
*/
|
|
487
|
+
export function rewriteMdzipLinks(tokens, resolve) {
|
|
488
|
+
walkMdzipTokens(tokens, (token) => {
|
|
489
|
+
if (token.type === 'link') {
|
|
490
|
+
const link = token;
|
|
491
|
+
if (typeof link.href === 'string' && !EXTERNAL_OR_ANCHOR.test(link.href)) {
|
|
492
|
+
link.href = resolve(link.href);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* MDZip Markdown to HTML: GitHub Flavored Markdown with footnotes, task
|
|
499
|
+
* lists, highlighted code, heading ids, and tables in a scrolling wrapper;
|
|
500
|
+
* ` ```mermaid ` blocks stay as `<pre><code class="language-mermaid">` for a
|
|
501
|
+
* client-side renderer; sanitized unless `sanitize: false`.
|
|
502
|
+
*/
|
|
503
|
+
export function renderMdzipMarkdown(markdown, options = {}) {
|
|
504
|
+
const tokens = tokenizeMdzipMarkdown(markdown);
|
|
505
|
+
if (options.resolveLink) {
|
|
506
|
+
rewriteMdzipLinks(tokens, options.resolveLink);
|
|
507
|
+
}
|
|
508
|
+
const html = parseMdzipTokens(tokens);
|
|
509
|
+
return options.sanitize === false
|
|
510
|
+
? finishMdzipHtml(html, options)
|
|
511
|
+
: sanitizeMdzipHtml(html, options.sanitizeContributions ?? [], options);
|
|
512
|
+
}
|
|
513
|
+
export function escapeHtml(value) {
|
|
514
|
+
return value
|
|
515
|
+
.replace(/&/g, '&')
|
|
516
|
+
.replace(/</g, '<')
|
|
517
|
+
.replace(/>/g, '>')
|
|
518
|
+
.replace(/"/g, '"')
|
|
519
|
+
.replace(/'/g, ''');
|
|
520
|
+
}
|
|
521
|
+
//# sourceMappingURL=markdown.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown.js","sourceRoot":"","sources":["../src/markdown.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,MAAM,EAA4C,MAAM,QAAQ,CAAC;AAC1E,OAAO,cAAc,MAAM,iBAAiB,CAAC;AAC7C,OAAO,IAAI,MAAM,qBAAqB,CAAC;AAIvC,iFAAiF;AAEjF,0EAA0E;AAC1E,8EAA8E;AAC9E,6EAA6E;AAC7E,IAAI,QAAQ,GAAwC,IAAI,CAAC;AAEzD,SAAS,YAAY;IACnB,IAAI,QAAQ,EAAE,CAAC;QACb,OAAO,QAAQ,CAAC;IAClB,CAAC;IACD,IAAI,OAAO,SAAS,CAAC,QAAQ,KAAK,UAAU,IAAI,SAAS,CAAC,WAAW,EAAE,CAAC;QACtE,QAAQ,GAAG,SAAS,CAAC;QACrB,OAAO,QAAQ,CAAC;IAClB,CAAC;IACD,MAAM,YAAY,GAAI,UAAmC,CAAC,MAAM,CAAC;IACjE,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,QAAQ,GAAG,SAAS,CAAC,YAA0C,CAAC,CAAC;IACjE,OAAO,QAAQ,CAAC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OAAO,CAAC,qBAAqB,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC;AAC5E,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,KAAa;IACtC,OAAO,KAAK;SACT,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC;SACtB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;SACrB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;SACrB,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC;SACvB,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AAC7B,CAAC"}
|
package/dist/page.d.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { type MdzManifest } from '@mdzip/core-js';
|
|
2
|
+
import { type MdzipMarkdownOptions } from './markdown.js';
|
|
3
|
+
export interface MdzipPageAsset {
|
|
4
|
+
/** Where the picture is in the archive, e.g. `images/logo.png`. */
|
|
5
|
+
archivePath: string;
|
|
6
|
+
/** Content-hashed file name, e.g. `a1b2c3d4e5f6.png`. The same bytes always get the same name. */
|
|
7
|
+
fileName: string;
|
|
8
|
+
/** Where to save it, relative to the page: `<assetDir>/<fileName>`. */
|
|
9
|
+
path: string;
|
|
10
|
+
/** The address the page's HTML uses for it: `path`, unless `assetUrl` or `withAssetUrls()` changed it. */
|
|
11
|
+
url: string;
|
|
12
|
+
bytes: Uint8Array;
|
|
13
|
+
}
|
|
14
|
+
export interface MdzipPage {
|
|
15
|
+
/** The manifest's `title`, or `null`. */
|
|
16
|
+
title: string | null;
|
|
17
|
+
/** The manifest's `description`, or `null`. */
|
|
18
|
+
description: string | null;
|
|
19
|
+
manifest: MdzManifest | null;
|
|
20
|
+
/** The archive path of the rendered document. */
|
|
21
|
+
entryPoint: string;
|
|
22
|
+
/** The document's HTML: the page body, without `<html>`, `<head>` or a style sheet. */
|
|
23
|
+
html: string;
|
|
24
|
+
/**
|
|
25
|
+
* The pictures and videos the HTML uses. Save each one's `bytes` at its
|
|
26
|
+
* `path` beside the page. With `inlineImages`, only the videos, which are
|
|
27
|
+
* never inlined.
|
|
28
|
+
*/
|
|
29
|
+
assets: MdzipPageAsset[];
|
|
30
|
+
/**
|
|
31
|
+
* The same page with other addresses for its pictures, for hosts that only
|
|
32
|
+
* know a picture's address after uploading it (CMS media libraries, some
|
|
33
|
+
* CDNs). `urls` maps an asset's `archivePath` or `fileName` to its address,
|
|
34
|
+
* or is a function of the asset. Pictures it has no address for keep theirs.
|
|
35
|
+
*/
|
|
36
|
+
withAssetUrls(urls: Record<string, string> | ((asset: MdzipPageAsset) => string | undefined)): MdzipPage;
|
|
37
|
+
}
|
|
38
|
+
export interface MdzipPageOptions extends Omit<MdzipMarkdownOptions, 'sanitizeContributions'> {
|
|
39
|
+
/** Folder the pictures go in, relative to the page. Default `assets/page-images`. */
|
|
40
|
+
assetDir?: string;
|
|
41
|
+
/**
|
|
42
|
+
* The address the HTML uses for a picture stored somewhere other than its
|
|
43
|
+
* `path`. Gets the content-hashed file name and the asset.
|
|
44
|
+
*/
|
|
45
|
+
assetUrl?: (fileName: string, asset: Omit<MdzipPageAsset, 'url'>) => string;
|
|
46
|
+
/**
|
|
47
|
+
* Put the pictures in the HTML as `data:` URIs, for a single self-contained
|
|
48
|
+
* page; `assets` then holds only videos, which stay files. Binary pictures
|
|
49
|
+
* are base64-encoded; SVGs are percent-encoded (`data:image/svg+xml,…`),
|
|
50
|
+
* which is usually smaller.
|
|
51
|
+
*/
|
|
52
|
+
inlineImages?: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Put SVG pictures that contain links into the page itself, so the links
|
|
55
|
+
* can be clicked (an SVG shown with `<img>` is a flat picture). Default `true`.
|
|
56
|
+
* See the README for how they're isolated and when one isn't inlined.
|
|
57
|
+
*/
|
|
58
|
+
inlineLinkedSvg?: boolean;
|
|
59
|
+
/** Reports problems that don't stop the render, such as an SVG with links that couldn't be inlined. */
|
|
60
|
+
onWarning?: (message: string) => void;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The local (relative) pictures and videos a Markdown document refers to:
|
|
64
|
+
* Markdown images (a video file there is a player), raw-HTML `<img>` tags,
|
|
65
|
+
* the `<source>` tags of a `<picture>` (a srcset of one image, no size list),
|
|
66
|
+
* and raw-HTML `<video>` (`src`, `poster`) and `<source src>` tags.
|
|
67
|
+
* References inside code are ignored. Sorted, without duplicates; a
|
|
68
|
+
* `#t=` fragment stays on its reference.
|
|
69
|
+
*/
|
|
70
|
+
export declare function collectLocalImageRefs(markdown: string): string[];
|
|
71
|
+
/**
|
|
72
|
+
* Why an SVG with links can't be put into a page, or `null` when it can.
|
|
73
|
+
*/
|
|
74
|
+
export declare function inlineSvgProblem(svgText: string): string | null;
|
|
75
|
+
/**
|
|
76
|
+
* Renders an `.mdz` archive's entry-point document as a static page. See
|
|
77
|
+
* {@link MdzipPage} for the result and {@link MdzipPageOptions} for the options.
|
|
78
|
+
*
|
|
79
|
+
* ```js
|
|
80
|
+
* const page = await renderMdzPage(bytes);
|
|
81
|
+
* await writeFile('index.html', `<!doctype html><title>${page.title}</title>${page.html}`);
|
|
82
|
+
* for (const asset of page.assets) await writeFile(asset.path, asset.bytes);
|
|
83
|
+
* ```
|
|
84
|
+
*
|
|
85
|
+
* The page is sanitized with the same policy as the MDZip editor's preview;
|
|
86
|
+
* in Node that needs jsdom (an optional peer dependency), or pass
|
|
87
|
+
* `sanitize: false` for archives you trust.
|
|
88
|
+
*/
|
|
89
|
+
export declare function renderMdzPage(source: Uint8Array | ArrayBuffer, options?: MdzipPageOptions): Promise<MdzipPage>;
|
|
90
|
+
//# sourceMappingURL=page.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page.d.ts","sourceRoot":"","sources":["../src/page.ts"],"names":[],"mappings":"AAEA,OAAO,EAAkB,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,EAKL,KAAK,oBAAoB,EAC1B,MAAM,eAAe,CAAC;AAGvB,MAAM,WAAW,cAAc;IAC7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