@tabnas/markdown 0.4.2 → 0.5.1

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/dist/html.js ADDED
@@ -0,0 +1,393 @@
1
+ "use strict";
2
+ /* Copyright (c) 2021-2026 Richard Rodger, MIT License */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.renderHTML = renderHTML;
5
+ const common_ts_1 = require("./common.js");
6
+ const options_ts_1 = require("./options.js");
7
+ /**
8
+ * GFM's `tagfilter` extension. These nine tags change how the *rest* of a
9
+ * document is interpreted (everything after `<xmp>` or `<plaintext>` stops
10
+ * being markup at all), so GFM neutralises them by rewriting the leading `<`
11
+ * as `&lt;` — opening and closing, in any case. Every other tag still passes
12
+ * through verbatim, as CommonMark requires.
13
+ *
14
+ * This is purely a rendering concern: nothing rewrites the node, so the
15
+ * literal in the tree and the `value` in the AST stay exactly as written.
16
+ *
17
+ * The tag name must be followed by whitespace, `/`, `>` or the end of the
18
+ * text, so `<scriptlet>` and `<titles>` are untouched.
19
+ */
20
+ const RE_DISALLOWED_TAG = /<\/?(?:title|textarea|style|xmp|iframe|noembed|noframes|script|plaintext)(?=[\t\n\f\r />]|$)/gi;
21
+ function filterDisallowedTags(html) {
22
+ // Cheap reject: the vast majority of raw HTML holds none of these.
23
+ if (-1 === html.indexOf('<'))
24
+ return html;
25
+ return html.replace(RE_DISALLOWED_TAG, (m) => '&lt;' + m.slice(1));
26
+ }
27
+ /**
28
+ * Render `doc` (a tree that has been through both parse phases) as HTML.
29
+ *
30
+ * Two options reach the renderer. `breaks` turns soft line breaks into hard
31
+ * ones. `gfm` selects one thing only — the disallowed-raw-HTML filter, which
32
+ * the extension defines at render time rather than at parse time. Everything
33
+ * else GFM adds is settled by then: by the time a `del` node or an item's
34
+ * `checked` state exists, the renderer just prints it.
35
+ *
36
+ * `gfm` defaults to whatever the *document* was parsed with rather than to the
37
+ * package default, so `renderHTML(tree)` on a `gfm:false` parse renders plain
38
+ * CommonMark. An explicit `options.gfm` still wins.
39
+ */
40
+ function renderHTML(doc, options) {
41
+ const opts = (0, options_ts_1.resolveOptions)({
42
+ gfm: options?.gfm ?? doc.gfm,
43
+ breaks: options?.breaks,
44
+ });
45
+ /** Raw HTML as written, minus the tags GFM's tagfilter neutralises. */
46
+ const rawHtml = (literal) => {
47
+ const s = null === literal ? '' : literal;
48
+ return opts.gfm ? filterDisallowedTags(s) : s;
49
+ };
50
+ // §6.9 soft line breaks: rendered as a newline, or as a hard break when the
51
+ // caller asks for `breaks`.
52
+ const softbreak = opts.breaks ? '<br />\n' : '\n';
53
+ let buf = '';
54
+ // Tracks whether the buffer is positioned at the start of a line, which is
55
+ // the only thing `cr()` needs to know. An empty buffer counts as at-line-
56
+ // start, so a leading `cr()` (every top-level block opens with one) writes
57
+ // nothing.
58
+ let atLineStart = true;
59
+ function lit(s) {
60
+ // An empty write must not claim the line is dirty, or the next `cr()`
61
+ // would insert a spurious newline.
62
+ if ('' === s)
63
+ return;
64
+ buf += s;
65
+ atLineStart = '\n' === s.charAt(s.length - 1);
66
+ }
67
+ function cr() {
68
+ if (!atLineStart)
69
+ lit('\n');
70
+ }
71
+ function tag(name, attrs, selfClosing) {
72
+ let s = '<' + name;
73
+ if (undefined !== attrs) {
74
+ for (const attr of attrs) {
75
+ s += ' ' + attr[0] + '="' + attr[1] + '"';
76
+ }
77
+ }
78
+ if (true === selfClosing)
79
+ s += ' /';
80
+ lit(s + '>');
81
+ }
82
+ // GFM tables carry their alignment once, on the table, but it is rendered
83
+ // per cell. Tracking the current table's array and the current row's column
84
+ // as the walk goes is what keeps that an O(1) lookup instead of counting a
85
+ // cell's previous siblings — and a table can never contain another table
86
+ // (its cells hold inlines only), so one of each is enough.
87
+ let tableAlign = [];
88
+ let cellIndex = 0;
89
+ const walker = doc.walker();
90
+ let event = walker.next();
91
+ while (null !== event) {
92
+ const node = event.node;
93
+ const entering = event.entering;
94
+ switch (node.type) {
95
+ case 'document':
96
+ break;
97
+ case 'paragraph': {
98
+ // §5.3: "if a list is tight, we remove the <p> tags from the item
99
+ // contents". The paragraph's grandparent is the list — a paragraph
100
+ // whose grandparent is a list is necessarily an item's direct child.
101
+ const grandparent = null === node.parent ? null : node.parent.parent;
102
+ const tight = null !== grandparent &&
103
+ 'list' === grandparent.type &&
104
+ null !== grandparent.listData &&
105
+ grandparent.listData.tight;
106
+ if (entering) {
107
+ if (!tight) {
108
+ cr();
109
+ tag('p');
110
+ }
111
+ // GFM task list item. The block phase consumed the `[x]` marker and
112
+ // left the state on the item, so the checkbox is written here, at
113
+ // the head of the item's first paragraph: directly after `<li>` when
114
+ // the list is tight, and inside the `<p>` when it is loose. The
115
+ // trailing space is the separator the extension's own output shows
116
+ // between the checkbox and the item text.
117
+ const item = node.parent;
118
+ if (null !== item &&
119
+ 'item' === item.type &&
120
+ item.firstChild === node &&
121
+ null !== item.checked) {
122
+ const attrs = [];
123
+ if (item.checked)
124
+ attrs.push(['checked', '']);
125
+ attrs.push(['disabled', '']);
126
+ attrs.push(['type', 'checkbox']);
127
+ tag('input', attrs);
128
+ lit(' ');
129
+ }
130
+ }
131
+ else if (!tight) {
132
+ tag('/p');
133
+ cr();
134
+ }
135
+ break;
136
+ }
137
+ case 'heading': {
138
+ const name = 'h' + node.level;
139
+ if (entering) {
140
+ cr();
141
+ tag(name);
142
+ }
143
+ else {
144
+ tag('/' + name);
145
+ cr();
146
+ }
147
+ break;
148
+ }
149
+ case 'thematic_break':
150
+ cr();
151
+ tag('hr', undefined, true);
152
+ cr();
153
+ break;
154
+ case 'block_quote':
155
+ cr();
156
+ tag(entering ? 'blockquote' : '/blockquote');
157
+ cr();
158
+ break;
159
+ case 'list': {
160
+ const data = node.listData;
161
+ const ordered = null !== data && 'ordered' === data.type;
162
+ const name = ordered ? 'ol' : 'ul';
163
+ if (entering) {
164
+ const attrs = [];
165
+ // §5.3: the start number is only rendered when it is not 1 — and
166
+ // `start="0"` is meaningful, so this is an inequality, not a
167
+ // truthiness test.
168
+ if (ordered && null !== data && 1 !== data.start) {
169
+ attrs.push(['start', String(data.start)]);
170
+ }
171
+ cr();
172
+ tag(name, attrs);
173
+ }
174
+ else {
175
+ cr();
176
+ tag('/' + name);
177
+ }
178
+ cr();
179
+ break;
180
+ }
181
+ case 'item':
182
+ // No `cr()` after `<li>`: a tight item renders `<li>text</li>`, and a
183
+ // loose one gets its newline from the leading `cr()` of the first
184
+ // child block.
185
+ if (entering) {
186
+ tag('li');
187
+ }
188
+ else {
189
+ tag('/li');
190
+ cr();
191
+ }
192
+ break;
193
+ case 'code_block': {
194
+ const attrs = [];
195
+ // §4.5: "the first word of the info string is typically used to
196
+ // specify the language". The info string arrives from the block phase
197
+ // already backslash-unescaped and entity-decoded; only the escaping
198
+ // for attribute context is left to do here.
199
+ const info = null === node.info ? '' : node.info;
200
+ const firstWord = '' === info ? '' : info.split(/\s+/)[0];
201
+ if ('' !== firstWord) {
202
+ attrs.push(['class', 'language-' + (0, common_ts_1.escapeXml)(firstWord)]);
203
+ }
204
+ cr();
205
+ tag('pre');
206
+ tag('code', attrs);
207
+ // The block phase guarantees the literal already ends with a newline
208
+ // (or is empty, for an empty fenced block, which renders as
209
+ // `<pre><code></code></pre>`).
210
+ lit((0, common_ts_1.escapeXml)(null === node.literal ? '' : node.literal));
211
+ tag('/code');
212
+ tag('/pre');
213
+ cr();
214
+ break;
215
+ }
216
+ case 'html_block':
217
+ // §4.6: raw HTML passes through verbatim, unescaped — except for the
218
+ // nine tags GFM's tagfilter neutralises.
219
+ cr();
220
+ lit(rawHtml(node.literal));
221
+ cr();
222
+ break;
223
+ // --- GFM tables ---
224
+ //
225
+ // `<thead>` and `<tbody>` have no node of their own: the header row is
226
+ // the one row flagged as such, and the body is every row after it. That
227
+ // is also why `<tbody>` is written by the *first* body row rather than
228
+ // unconditionally — a table with no body rows must have no `<tbody>` at
229
+ // all.
230
+ case 'table':
231
+ if (entering) {
232
+ tableAlign = node.tableAlign ?? [];
233
+ cr();
234
+ tag('table');
235
+ }
236
+ else {
237
+ cr();
238
+ tag('/table');
239
+ }
240
+ cr();
241
+ break;
242
+ case 'table_row': {
243
+ const header = node.isHeaderRow;
244
+ if (entering) {
245
+ if (header) {
246
+ cr();
247
+ tag('thead');
248
+ }
249
+ else if (null === node.prev || node.prev.isHeaderRow) {
250
+ cr();
251
+ tag('tbody');
252
+ }
253
+ cr();
254
+ tag('tr');
255
+ cellIndex = 0;
256
+ }
257
+ else {
258
+ cr();
259
+ tag('/tr');
260
+ cr();
261
+ if (header)
262
+ tag('/thead');
263
+ else if (null === node.next)
264
+ tag('/tbody');
265
+ }
266
+ cr();
267
+ break;
268
+ }
269
+ case 'table_cell': {
270
+ const name = null !== node.parent && node.parent.isHeaderRow ? 'th' : 'td';
271
+ if (entering) {
272
+ const attrs = [];
273
+ const align = tableAlign[cellIndex];
274
+ if (undefined !== align && null !== align)
275
+ attrs.push(['align', align]);
276
+ cellIndex += 1;
277
+ tag(name, attrs);
278
+ }
279
+ else {
280
+ tag('/' + name);
281
+ cr();
282
+ }
283
+ break;
284
+ }
285
+ case 'text':
286
+ lit((0, common_ts_1.escapeXml)(null === node.literal ? '' : node.literal));
287
+ break;
288
+ case 'softbreak':
289
+ lit(softbreak);
290
+ break;
291
+ case 'linebreak':
292
+ tag('br', undefined, true);
293
+ cr();
294
+ break;
295
+ case 'code':
296
+ tag('code');
297
+ lit((0, common_ts_1.escapeXml)(null === node.literal ? '' : node.literal));
298
+ tag('/code');
299
+ break;
300
+ case 'html_inline':
301
+ lit(rawHtml(node.literal));
302
+ break;
303
+ case 'emph':
304
+ tag(entering ? 'em' : '/em');
305
+ break;
306
+ case 'strong':
307
+ tag(entering ? 'strong' : '/strong');
308
+ break;
309
+ case 'del':
310
+ tag(entering ? 'del' : '/del');
311
+ break;
312
+ case 'link':
313
+ if (entering) {
314
+ const attrs = [['href', (0, common_ts_1.escapeXml)((0, common_ts_1.normalizeURI)(destinationOf(node)))]];
315
+ // An empty title is dropped: `[link](/url "")` renders as a bare
316
+ // `<a href="/url">`.
317
+ if (null !== node.title && '' !== node.title) {
318
+ attrs.push(['title', (0, common_ts_1.escapeXml)(node.title)]);
319
+ }
320
+ tag('a', attrs);
321
+ }
322
+ else {
323
+ tag('/a');
324
+ }
325
+ break;
326
+ case 'image': {
327
+ if (entering) {
328
+ const attrs = [
329
+ ['src', (0, common_ts_1.escapeXml)((0, common_ts_1.normalizeURI)(destinationOf(node)))],
330
+ ['alt', (0, common_ts_1.escapeXml)(altText(node))],
331
+ ];
332
+ if (null !== node.title && '' !== node.title) {
333
+ attrs.push(['title', (0, common_ts_1.escapeXml)(node.title)]);
334
+ }
335
+ tag('img', attrs, true);
336
+ // The children have been consumed into `alt`; jump the walk
337
+ // straight to this image's exit event so they are not also
338
+ // rendered as markup.
339
+ walker.resumeAt(node, false);
340
+ }
341
+ break;
342
+ }
343
+ }
344
+ event = walker.next();
345
+ }
346
+ return buf;
347
+ }
348
+ function destinationOf(node) {
349
+ return null === node.destination ? '' : node.destination;
350
+ }
351
+ /**
352
+ * §6.4 images: "the image description gets represented as the `alt`
353
+ * attribute" — as plain text. Descend the subtree keeping the text and
354
+ * code-span literals and dropping the markup wrappers, so
355
+ * `![foo *bar*](/url)` yields `alt="foo bar"` and a nested link contributes
356
+ * only its text.
357
+ *
358
+ * Raw inline HTML and line breaks inside a description are not exercised by
359
+ * the spec suite and the two reference implementations disagree: cmark
360
+ * escapes the raw HTML into the attribute and turns breaks into spaces,
361
+ * commonmark.js emits the HTML verbatim (producing a malformed attribute)
362
+ * and turns breaks into newlines. We keep the literal — escaped, since the
363
+ * result is attribute-context text — and follow commonmark.js on breaks.
364
+ */
365
+ function altText(image) {
366
+ let alt = '';
367
+ const walker = image.walker();
368
+ walker.next(); // discard the image's own entering event
369
+ let event = walker.next();
370
+ while (null !== event && event.node !== image) {
371
+ const node = event.node;
372
+ if (event.entering) {
373
+ switch (node.type) {
374
+ case 'text':
375
+ case 'code':
376
+ case 'html_inline':
377
+ alt += null === node.literal ? '' : node.literal;
378
+ break;
379
+ case 'softbreak':
380
+ case 'linebreak':
381
+ alt += '\n';
382
+ break;
383
+ default:
384
+ // Containers (emph, strong, link, a nested image) contribute
385
+ // nothing themselves; the walk still descends into their children.
386
+ break;
387
+ }
388
+ }
389
+ event = walker.next();
390
+ }
391
+ return alt;
392
+ }
393
+ //# sourceMappingURL=html.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"html.js","sourceRoot":"","sources":["../src/html.ts"],"names":[],"mappings":";AAAA,yDAAyD;;AAkEzD,gCAyUC;AAnXD,2CAAqD;AACrD,6CAA6C;AAM7C;;;;;;;;;;;;GAYG;AACH,MAAM,iBAAiB,GACrB,gGAAgG,CAAA;AAElG,SAAS,oBAAoB,CAAC,IAAY;IACxC,mEAAmE;IACnE,IAAI,CAAC,CAAC,KAAK,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC;QAAE,OAAO,IAAI,CAAA;IACzC,OAAO,IAAI,CAAC,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;AACpE,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,UAAU,CAAC,GAAW,EAAE,OAAgC;IACtE,MAAM,IAAI,GAAG,IAAA,2BAAc,EAAC;QAC1B,GAAG,EAAE,OAAO,EAAE,GAAG,IAAI,GAAG,CAAC,GAAG;QAC5B,MAAM,EAAE,OAAO,EAAE,MAAM;KACxB,CAAC,CAAA;IAEF,uEAAuE;IACvE,MAAM,OAAO,GAAG,CAAC,OAAsB,EAAU,EAAE;QACjD,MAAM,CAAC,GAAG,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAA;QACzC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IAC/C,CAA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ED,OAAO,GAAG,CAAA;AACZ,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { MdNode } from './node.ts';
2
+ import type { ParserOptions, RefMap } from './options.ts';
3
+ /**
4
+ * Recognise GFM autolink literals throughout one finished block's inlines.
5
+ *
6
+ * Iterative rather than recursive: emphasis nests as deeply as the input says.
7
+ */
8
+ export declare function linkifyAutolinks(block: MdNode): void;
9
+ /**
10
+ * Phase 2 entry point: walk the block tree and parse the string content of
11
+ * every paragraph, heading and table cell into inline children.
12
+ */
13
+ export declare function parseInlines(doc: MdNode, refmap: RefMap, options: ParserOptions): void;
14
+ /**
15
+ * Consume link reference definitions from the front of a paragraph's raw
16
+ * content, adding them to `refmap`. Returns the number of characters
17
+ * consumed, or 0 if `s` does not start with a definition.
18
+ */
19
+ export declare function parseReference(s: string, refmap: RefMap): number;