@tanstack/markdown 0.0.4 → 0.0.5
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.d.ts.map +1 -1
- package/dist/html.js +23 -1
- package/dist/inline.js +64 -1
- package/dist/parser.d.ts.map +1 -1
- package/dist/parser.js +54 -12
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +34 -1
- package/dist/types.d.ts +22 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +1 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +5 -0
- package/package.json +11 -10
package/dist/html.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html.d.ts","sourceRoot":"","sources":["../src/html.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"html.d.ts","sourceRoot":"","sources":["../src/html.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAyD,UAAU,EAAE,gBAAgB,EAAE,aAAa,EAAE,aAAa,EAAiB,MAAM,YAAY,CAAA;AAG7K,wBAAgB,UAAU,CAAC,KAAK,EAAE,aAAa,EAAE,OAAO,GAAE,aAAkB,GAAG,MAAM,CAGpF;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,GAAE,aAAkB,GAAG,MAAM,CAwChF;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,GAAE,aAAkB,GAAG,MAAM,CA0BlF;AAED,wBAAgB,cAAc,CAAC,QAAQ,EAAE,gBAAgB,EAAE,OAAO,GAAE,aAAkB,GAAG,MAAM,CAE9F"}
|
package/dist/html.js
CHANGED
|
@@ -33,6 +33,8 @@ export function renderBlock(node, options = {}) {
|
|
|
33
33
|
.join('')}</tbody>`;
|
|
34
34
|
return `<table>${header}${body}</table>`;
|
|
35
35
|
}
|
|
36
|
+
case 'footnotes':
|
|
37
|
+
return renderFootnotes(node.items, options);
|
|
36
38
|
case 'thematicBreak':
|
|
37
39
|
return '<hr>';
|
|
38
40
|
case 'html':
|
|
@@ -57,7 +59,9 @@ export function renderInline(node, options = {}) {
|
|
|
57
59
|
case 'emphasis':
|
|
58
60
|
return `<em>${renderInlines(node.children, options)}</em>`;
|
|
59
61
|
case 'strike':
|
|
60
|
-
return `<
|
|
62
|
+
return `<del>${renderInlines(node.children, options)}</del>`;
|
|
63
|
+
case 'footnoteReference':
|
|
64
|
+
return `<sup><a id="user-content-fnref-${escapeAttr(node.id)}" data-footnote-ref="" aria-describedby="footnote-label" href="#user-content-fn-${escapeAttr(node.id)}">${node.number}</a></sup>`;
|
|
61
65
|
case 'link':
|
|
62
66
|
return `<a href="${escapeAttr(node.href)}"${node.title ? ` title="${escapeAttr(node.title)}"` : ''}>${renderInlines(node.children, options)}</a>`;
|
|
63
67
|
case 'image':
|
|
@@ -106,6 +110,24 @@ function renderCallout(node, options) {
|
|
|
106
110
|
const children = node.children.map(child => renderBlock(child, options)).join('\n');
|
|
107
111
|
return `<div class="markdown-alert markdown-alert-${escapeAttr(kind)}"><p class="markdown-alert-title">${escapeHtml(node.title)}</p><div class="markdown-alert-content">${children}</div></div>`;
|
|
108
112
|
}
|
|
113
|
+
function renderFootnotes(items, options) {
|
|
114
|
+
const renderedItems = items.map(item => `<li id="user-content-fn-${escapeAttr(item.id)}">\n${renderFootnoteItem(item, options)}\n</li>`).join('\n');
|
|
115
|
+
return `<section data-footnotes="" class="footnotes"><h2 id="footnote-label" class="sr-only">Footnotes${renderHeadingAnchor('footnote-label', options)}</h2>\n<ol>\n${renderedItems}\n</ol>\n</section>`;
|
|
116
|
+
}
|
|
117
|
+
function renderFootnoteItem(item, options) {
|
|
118
|
+
const backref = ` <a data-footnote-backref="" aria-label="Back to reference ${item.number}" class="data-footnote-backref" href="#user-content-fnref-${escapeAttr(item.id)}">↩</a>`;
|
|
119
|
+
const lastIndex = item.children.length - 1;
|
|
120
|
+
if (lastIndex < 0)
|
|
121
|
+
return `<p>${backref.trimStart()}</p>`;
|
|
122
|
+
return item.children
|
|
123
|
+
.map((child, index) => {
|
|
124
|
+
if (index === lastIndex && child.type === 'paragraph') {
|
|
125
|
+
return `<p>${renderInlines(child.children, options)}${backref}</p>`;
|
|
126
|
+
}
|
|
127
|
+
return renderBlock(child, options);
|
|
128
|
+
})
|
|
129
|
+
.join('\n');
|
|
130
|
+
}
|
|
109
131
|
function renderComponent(node, options) {
|
|
110
132
|
const tag = node.tagName ?? 'md-comment-component';
|
|
111
133
|
const attrs = renderComponentAttrs(node);
|
package/dist/inline.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { normalizeReferenceLabel, sanitizeUrl } from './utils.js';
|
|
1
|
+
import { footnoteId, normalizeReferenceLabel, sanitizeUrl } from './utils.js';
|
|
2
2
|
export function parseInline(value, options = {}) {
|
|
3
3
|
const nodes = parseInlineRaw(value, options);
|
|
4
4
|
let result = mergeText(nodes);
|
|
@@ -61,6 +61,13 @@ function parseInlineRaw(value, options) {
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
if (char === '[') {
|
|
64
|
+
const footnote = parseFootnoteReference(value, index, options);
|
|
65
|
+
if (footnote) {
|
|
66
|
+
pushText();
|
|
67
|
+
nodes.push(footnote.node);
|
|
68
|
+
index = footnote.end;
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
64
71
|
const parsed = parseLinkish(value, index, options);
|
|
65
72
|
if (parsed) {
|
|
66
73
|
const href = sanitizeUrl(parsed.href);
|
|
@@ -110,6 +117,18 @@ function parseInlineRaw(value, options) {
|
|
|
110
117
|
index += 2;
|
|
111
118
|
continue;
|
|
112
119
|
}
|
|
120
|
+
if (char === '~') {
|
|
121
|
+
const close = findSingleTildeDelimiter(value, index + 1);
|
|
122
|
+
if (close !== -1) {
|
|
123
|
+
pushText();
|
|
124
|
+
nodes.push({
|
|
125
|
+
type: 'strike',
|
|
126
|
+
children: parseInlineRaw(value.slice(index + 1, close), options),
|
|
127
|
+
});
|
|
128
|
+
index = close + 1;
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
113
132
|
if (char === '*' || char === '_') {
|
|
114
133
|
const close = findDelimiter(value, index + 1, char);
|
|
115
134
|
if (close !== -1 && !isIntrawordUnderscore(value, index, close, char)) {
|
|
@@ -137,6 +156,31 @@ function parseInlineRaw(value, options) {
|
|
|
137
156
|
pushText();
|
|
138
157
|
return nodes;
|
|
139
158
|
}
|
|
159
|
+
function parseFootnoteReference(value, open, options) {
|
|
160
|
+
if (value[open + 1] !== '^')
|
|
161
|
+
return undefined;
|
|
162
|
+
const close = value.indexOf(']', open + 2);
|
|
163
|
+
if (close === -1)
|
|
164
|
+
return undefined;
|
|
165
|
+
const label = value.slice(open + 2, close);
|
|
166
|
+
const key = normalizeReferenceLabel(label);
|
|
167
|
+
const definition = options.footnotes?.[key];
|
|
168
|
+
if (!definition || !options.footnoteOrder)
|
|
169
|
+
return undefined;
|
|
170
|
+
let orderIndex = options.footnoteOrder.indexOf(key);
|
|
171
|
+
if (orderIndex === -1) {
|
|
172
|
+
options.footnoteOrder.push(key);
|
|
173
|
+
orderIndex = options.footnoteOrder.length - 1;
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
node: {
|
|
177
|
+
type: 'footnoteReference',
|
|
178
|
+
id: footnoteId(definition.label),
|
|
179
|
+
number: orderIndex + 1,
|
|
180
|
+
},
|
|
181
|
+
end: close + 1,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
140
184
|
function parseLinkish(value, open, options) {
|
|
141
185
|
const closeBracket = findBalanced(value, open, '[', ']');
|
|
142
186
|
if (closeBracket === -1)
|
|
@@ -221,11 +265,30 @@ function findDelimiter(value, start, delimiter) {
|
|
|
221
265
|
}
|
|
222
266
|
return -1;
|
|
223
267
|
}
|
|
268
|
+
function findSingleTildeDelimiter(value, start) {
|
|
269
|
+
if (isWhitespace(value[start] ?? ''))
|
|
270
|
+
return -1;
|
|
271
|
+
for (let index = start; index < value.length; index++) {
|
|
272
|
+
if (value[index - 1] === '\\')
|
|
273
|
+
continue;
|
|
274
|
+
if (value[index] !== '~')
|
|
275
|
+
continue;
|
|
276
|
+
if (value[index + 1] === '~')
|
|
277
|
+
continue;
|
|
278
|
+
if (isWhitespace(value[index - 1] ?? ''))
|
|
279
|
+
return -1;
|
|
280
|
+
return index;
|
|
281
|
+
}
|
|
282
|
+
return -1;
|
|
283
|
+
}
|
|
224
284
|
function isIntrawordUnderscore(value, open, close, delimiter) {
|
|
225
285
|
if (delimiter !== '_')
|
|
226
286
|
return false;
|
|
227
287
|
return /\w/.test(value[open - 1] ?? '') && /\w/.test(value[close + 1] ?? '');
|
|
228
288
|
}
|
|
289
|
+
function isWhitespace(value) {
|
|
290
|
+
return /\s/.test(value);
|
|
291
|
+
}
|
|
229
292
|
function textFromMarkdown(value) {
|
|
230
293
|
return parseInlineRaw(value, {}).map(node => (node.type === 'text' || node.type === 'inlineCode' ? node.value : '')).join('');
|
|
231
294
|
}
|
package/dist/parser.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAOV,gBAAgB,EAChB,YAAY,EAGb,MAAM,YAAY,CAAA;AAKnB,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,GAAE,YAAiB,GAAG,gBAAgB,
|
|
1
|
+
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAOV,gBAAgB,EAChB,YAAY,EAGb,MAAM,YAAY,CAAA;AAKnB,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,GAAE,YAAiB,GAAG,gBAAgB,CAwC5F"}
|
package/dist/parser.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { parseInline } from './inline.js';
|
|
2
|
-
import { createSlugger, isBlank, normalizeInput, normalizeReferenceLabel, plainText, stripIndent } from './utils.js';
|
|
2
|
+
import { createSlugger, footnoteId, isBlank, normalizeInput, normalizeReferenceLabel, plainText, stripIndent } from './utils.js';
|
|
3
3
|
export function parseMarkdown(markdown, options = {}) {
|
|
4
4
|
const normalized = normalizeInput(markdown);
|
|
5
5
|
const frontmatterEnabled = options.frontmatter !== false;
|
|
@@ -12,16 +12,23 @@ export function parseMarkdown(markdown, options = {}) {
|
|
|
12
12
|
lines = lines.slice(end + 1);
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
-
const
|
|
16
|
-
lines =
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
const definitions = extractDefinitions(lines);
|
|
16
|
+
lines = definitions.lines;
|
|
17
|
+
const footnoteOrder = [];
|
|
18
|
+
const hasReferences = Object.keys(definitions.references).length > 0;
|
|
19
|
+
const hasFootnotes = Object.keys(definitions.footnotes).length > 0;
|
|
20
|
+
const parseOptions = hasReferences || hasFootnotes
|
|
21
|
+
? {
|
|
20
22
|
...options,
|
|
21
|
-
references:
|
|
22
|
-
|
|
23
|
+
...(hasReferences ? { references: definitions.references } : {}),
|
|
24
|
+
...(hasFootnotes ? { footnotes: definitions.footnotes, footnoteOrder } : {}),
|
|
25
|
+
}
|
|
26
|
+
: options;
|
|
23
27
|
const parser = new BlockParser(lines, parseOptions, createSlugger());
|
|
24
28
|
const children = parser.parse();
|
|
29
|
+
if (hasFootnotes && footnoteOrder.length > 0) {
|
|
30
|
+
children.push(createFootnotesBlock(definitions.footnotes, footnoteOrder, parseOptions));
|
|
31
|
+
}
|
|
25
32
|
let document = frontmatter === undefined ? { type: 'root', children } : { type: 'root', frontmatter, children };
|
|
26
33
|
for (const extension of parseOptions.extensions ?? []) {
|
|
27
34
|
document = extension.transformDocument?.(document, { options: parseOptions }) ?? document;
|
|
@@ -287,12 +294,15 @@ function parseCodeInfo(info) {
|
|
|
287
294
|
...(highlightLines.length ? { highlightLines } : {}),
|
|
288
295
|
};
|
|
289
296
|
}
|
|
290
|
-
function
|
|
297
|
+
function extractDefinitions(lines) {
|
|
291
298
|
const references = {};
|
|
299
|
+
const footnotes = {};
|
|
292
300
|
const remaining = [];
|
|
293
301
|
let fenceMarker;
|
|
294
302
|
let fenceSize = 0;
|
|
295
|
-
|
|
303
|
+
let index = 0;
|
|
304
|
+
while (index < lines.length) {
|
|
305
|
+
const line = lines[index];
|
|
296
306
|
const fence = line.match(/^ {0,3}(`{3,}|~{3,})/);
|
|
297
307
|
if (fence) {
|
|
298
308
|
const marker = fence[1][0];
|
|
@@ -305,18 +315,50 @@ function extractReferenceDefinitions(lines) {
|
|
|
305
315
|
fenceSize = 0;
|
|
306
316
|
}
|
|
307
317
|
remaining.push(line);
|
|
318
|
+
index++;
|
|
308
319
|
continue;
|
|
309
320
|
}
|
|
310
321
|
if (!fenceMarker) {
|
|
322
|
+
const footnote = line.match(/^ {0,3}\[\^([^\]\n]+)\]:[ \t]*(.*)$/);
|
|
323
|
+
if (footnote) {
|
|
324
|
+
const label = footnote[1];
|
|
325
|
+
const content = [footnote[2] ?? ''];
|
|
326
|
+
index++;
|
|
327
|
+
while (index < lines.length) {
|
|
328
|
+
const continuation = lines[index];
|
|
329
|
+
if (!/^(?: {4,}|\t)/.test(continuation))
|
|
330
|
+
break;
|
|
331
|
+
content.push(continuation.replace(/^(?: {4}|\t)/, ''));
|
|
332
|
+
index++;
|
|
333
|
+
}
|
|
334
|
+
footnotes[normalizeReferenceLabel(label)] = { label, content: content.join('\n') };
|
|
335
|
+
continue;
|
|
336
|
+
}
|
|
311
337
|
const definition = line.match(/^ {0,3}\[([^\]\n]+)\]:[ \t]*(\S+)[ \t]*$/);
|
|
312
338
|
if (definition) {
|
|
313
339
|
references[normalizeReferenceLabel(definition[1])] = { href: definition[2].replace(/^<|>$/g, '') };
|
|
340
|
+
index++;
|
|
314
341
|
continue;
|
|
315
342
|
}
|
|
316
343
|
}
|
|
317
344
|
remaining.push(line);
|
|
345
|
+
index++;
|
|
346
|
+
}
|
|
347
|
+
return { lines: remaining, references, footnotes };
|
|
348
|
+
}
|
|
349
|
+
function createFootnotesBlock(footnotes, footnoteOrder, options) {
|
|
350
|
+
const items = [];
|
|
351
|
+
for (let index = 0; index < footnoteOrder.length; index++) {
|
|
352
|
+
const definition = footnotes[footnoteOrder[index]];
|
|
353
|
+
if (!definition)
|
|
354
|
+
continue;
|
|
355
|
+
items.push({
|
|
356
|
+
id: footnoteId(definition.label),
|
|
357
|
+
number: index + 1,
|
|
358
|
+
children: new BlockParser(normalizeInput(definition.content).split('\n'), options, createSlugger()).parse(),
|
|
359
|
+
});
|
|
318
360
|
}
|
|
319
|
-
return {
|
|
361
|
+
return { type: 'footnotes', items };
|
|
320
362
|
}
|
|
321
363
|
function parseLineRanges(value) {
|
|
322
364
|
const lines = new Set();
|
|
@@ -359,7 +401,7 @@ function looksLikeTableHeader(header, delimiter) {
|
|
|
359
401
|
if (!header.includes('|'))
|
|
360
402
|
return false;
|
|
361
403
|
const cells = splitTableRow(delimiter);
|
|
362
|
-
return cells.length > 0 && cells.every(cell => /^:?-{
|
|
404
|
+
return cells.length > 0 && cells.every(cell => /^:?-{2,}:?$/.test(cell.trim()));
|
|
363
405
|
}
|
|
364
406
|
function splitTableRow(value) {
|
|
365
407
|
let row = value.trim();
|
package/dist/react.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../src/react.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAEnE,OAAO,KAAK,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../src/react.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAEnE,OAAO,KAAK,EAAE,SAAS,EAAmC,UAAU,EAAE,aAAa,EAAE,aAAa,EAAiB,MAAM,YAAY,CAAA;AAErI,KAAK,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;AAExE,MAAM,WAAW,oBAAqB,SAAQ,aAAa;IACzD,UAAU,CAAC,EAAE,YAAY,CAAA;CAC1B;AAED,MAAM,WAAW,aAAc,SAAQ,oBAAoB;IACzD,QAAQ,EAAE,aAAa,CAAA;CACxB;AAED,wBAAgB,QAAQ,CAAC,EAAE,QAAQ,EAAE,GAAG,OAAO,EAAE,EAAE,aAAa,GAAG,YAAY,CAE9E;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,aAAa,EAAE,OAAO,GAAE,oBAAyB,GAAG,SAAS,CAGvG;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,GAAE,oBAAyB,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,YAAY,CA6DhH;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,GAAE,oBAAyB,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAwC/G"}
|
package/dist/react.js
CHANGED
|
@@ -23,6 +23,8 @@ export function renderBlockReact(node, options = {}, key) {
|
|
|
23
23
|
return h(options, 'blockquote', { key }, node.children.map((child, index) => renderBlockReact(child, options, `${key}:${index}`)));
|
|
24
24
|
case 'table':
|
|
25
25
|
return h(options, 'table', { key }, h(options, 'thead', null, h(options, 'tr', null, node.header.map((cell, index) => renderTableCellReact('th', cell, node.align[index], options, index)))), h(options, 'tbody', null, node.rows.map((row, rowIndex) => h(options, 'tr', { key: rowIndex }, row.map((cell, index) => renderTableCellReact('td', cell, node.align[index], options, index))))));
|
|
26
|
+
case 'footnotes':
|
|
27
|
+
return renderFootnotesReact(node.items, options, key);
|
|
26
28
|
case 'thematicBreak':
|
|
27
29
|
return h(options, 'hr', { key });
|
|
28
30
|
case 'html':
|
|
@@ -46,7 +48,14 @@ export function renderInlineReact(node, options = {}, key) {
|
|
|
46
48
|
case 'emphasis':
|
|
47
49
|
return h(options, 'em', { key }, renderInlines(node.children, options));
|
|
48
50
|
case 'strike':
|
|
49
|
-
return h(options, '
|
|
51
|
+
return h(options, 'del', { key }, renderInlines(node.children, options));
|
|
52
|
+
case 'footnoteReference':
|
|
53
|
+
return h(options, 'sup', { key }, h(options, 'a', {
|
|
54
|
+
id: `user-content-fnref-${node.id}`,
|
|
55
|
+
'data-footnote-ref': '',
|
|
56
|
+
'aria-describedby': 'footnote-label',
|
|
57
|
+
href: `#user-content-fn-${node.id}`,
|
|
58
|
+
}, node.number));
|
|
50
59
|
case 'link':
|
|
51
60
|
return h(options, 'a', { key, href: node.href, ...(node.title ? { title: node.title } : {}) }, renderInlines(node.children, options));
|
|
52
61
|
case 'image':
|
|
@@ -119,6 +128,30 @@ function renderListChildReact(child, loose, options, key) {
|
|
|
119
128
|
function renderTableCellReact(tag, cell, align, options, key) {
|
|
120
129
|
return h(options, tag, { key, ...(align ? { style: { textAlign: align } } : {}) }, renderInlines(cell.children, options));
|
|
121
130
|
}
|
|
131
|
+
function renderFootnotesReact(items, options, key) {
|
|
132
|
+
return h(options, 'section', { key, 'data-footnotes': '', className: 'footnotes' }, h(options, 'h2', { id: 'footnote-label', className: 'sr-only' }, 'Footnotes', renderHeadingAnchorReact('footnote-label', options)), h(options, 'ol', null, items.map(item => h(options, 'li', { key: item.id, id: `user-content-fn-${item.id}` }, renderFootnoteItemReact(item, options)))));
|
|
133
|
+
}
|
|
134
|
+
function renderFootnoteItemReact(item, options) {
|
|
135
|
+
const lastIndex = item.children.length - 1;
|
|
136
|
+
const backref = renderFootnoteBackrefReact(item, options, 'backref');
|
|
137
|
+
if (lastIndex < 0)
|
|
138
|
+
return [h(options, 'p', { key: 'backref-wrapper' }, backref)];
|
|
139
|
+
return item.children.map((child, index) => {
|
|
140
|
+
if (index === lastIndex && child.type === 'paragraph') {
|
|
141
|
+
return h(options, 'p', { key: index }, renderInlines(child.children, options), ' ', backref);
|
|
142
|
+
}
|
|
143
|
+
return renderBlockReact(child, options, `${index}`);
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
function renderFootnoteBackrefReact(item, options, key) {
|
|
147
|
+
return h(options, 'a', {
|
|
148
|
+
key,
|
|
149
|
+
'data-footnote-backref': '',
|
|
150
|
+
'aria-label': `Back to reference ${item.number}`,
|
|
151
|
+
className: 'data-footnote-backref',
|
|
152
|
+
href: `#user-content-fnref-${item.id}`,
|
|
153
|
+
}, '\u21a9');
|
|
154
|
+
}
|
|
122
155
|
function h(options, tag, props, ...children) {
|
|
123
156
|
const component = typeof tag === 'string' ? options.components?.[tag] ?? tag : tag;
|
|
124
157
|
return createElement(component, props, ...children);
|
package/dist/types.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export interface MarkdownDocument {
|
|
|
5
5
|
frontmatter?: string;
|
|
6
6
|
headings?: MarkdownHeading[];
|
|
7
7
|
}
|
|
8
|
-
export type BlockNode = HeadingNode | ParagraphNode | CodeBlockNode | ListNode | BlockquoteNode | TableNode | ThematicBreakNode | HtmlBlockNode | CalloutNode | ComponentNode;
|
|
8
|
+
export type BlockNode = HeadingNode | ParagraphNode | CodeBlockNode | ListNode | BlockquoteNode | TableNode | FootnotesNode | ThematicBreakNode | HtmlBlockNode | CalloutNode | ComponentNode;
|
|
9
9
|
export interface HeadingNode {
|
|
10
10
|
type: 'heading';
|
|
11
11
|
depth: 1 | 2 | 3 | 4 | 5 | 6;
|
|
@@ -53,6 +53,15 @@ export interface TableCellNode {
|
|
|
53
53
|
type: 'tableCell';
|
|
54
54
|
children: InlineNode[];
|
|
55
55
|
}
|
|
56
|
+
export interface FootnotesNode {
|
|
57
|
+
type: 'footnotes';
|
|
58
|
+
items: FootnoteItemNode[];
|
|
59
|
+
}
|
|
60
|
+
export interface FootnoteItemNode {
|
|
61
|
+
id: string;
|
|
62
|
+
number: number;
|
|
63
|
+
children: BlockNode[];
|
|
64
|
+
}
|
|
56
65
|
export interface ThematicBreakNode {
|
|
57
66
|
type: 'thematicBreak';
|
|
58
67
|
}
|
|
@@ -74,7 +83,7 @@ export interface ComponentNode {
|
|
|
74
83
|
tagName?: string;
|
|
75
84
|
properties?: Record<string, string>;
|
|
76
85
|
}
|
|
77
|
-
export type InlineNode = TextNode | CodeSpanNode | StrongNode | EmphasisNode | StrikeNode | LinkNode | ImageNode | BreakNode | HtmlInlineNode;
|
|
86
|
+
export type InlineNode = TextNode | CodeSpanNode | StrongNode | EmphasisNode | StrikeNode | FootnoteReferenceNode | LinkNode | ImageNode | BreakNode | HtmlInlineNode;
|
|
78
87
|
export interface TextNode {
|
|
79
88
|
type: 'text';
|
|
80
89
|
value: string;
|
|
@@ -95,6 +104,11 @@ export interface StrikeNode {
|
|
|
95
104
|
type: 'strike';
|
|
96
105
|
children: InlineNode[];
|
|
97
106
|
}
|
|
107
|
+
export interface FootnoteReferenceNode {
|
|
108
|
+
type: 'footnoteReference';
|
|
109
|
+
id: string;
|
|
110
|
+
number: number;
|
|
111
|
+
}
|
|
98
112
|
export interface LinkNode {
|
|
99
113
|
type: 'link';
|
|
100
114
|
href: string;
|
|
@@ -146,6 +160,8 @@ export interface ParseOptions {
|
|
|
146
160
|
headingIds?: boolean | ((text: string, index: number) => string);
|
|
147
161
|
extensions?: MarkdownExtension[];
|
|
148
162
|
references?: Record<string, LinkReferenceDefinition>;
|
|
163
|
+
footnotes?: Record<string, FootnoteDefinition>;
|
|
164
|
+
footnoteOrder?: string[];
|
|
149
165
|
}
|
|
150
166
|
export interface RenderOptions extends ParseOptions {
|
|
151
167
|
highlighter?: CodeHighlighter;
|
|
@@ -175,4 +191,8 @@ export interface LinkReferenceDefinition {
|
|
|
175
191
|
href: string;
|
|
176
192
|
title?: string;
|
|
177
193
|
}
|
|
194
|
+
export interface FootnoteDefinition {
|
|
195
|
+
label: string;
|
|
196
|
+
content: string;
|
|
197
|
+
}
|
|
178
198
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,gBAAgB,CAAA;AAErD,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,SAAS,EAAE,CAAA;IACrB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,eAAe,EAAE,CAAA;CAC7B;AAED,MAAM,MAAM,SAAS,GACjB,WAAW,GACX,aAAa,GACb,aAAa,GACb,QAAQ,GACR,cAAc,GACd,SAAS,GACT,iBAAiB,GACjB,aAAa,GACb,WAAW,GACX,aAAa,CAAA;AAEjB,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,SAAS,CAAA;IACf,KAAK,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IAC5B,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,UAAU,EAAE,CAAA;CACvB;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,WAAW,CAAA;IACjB,QAAQ,EAAE,UAAU,EAAE,CAAA;CACvB;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;IACb,cAAc,CAAC,EAAE,MA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AQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;IACb,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,MAAM,CAAA;CAChB"}
|
package/dist/utils.d.ts
CHANGED
|
@@ -8,5 +8,6 @@ export declare function plainText(nodes: InlineNode[]): string;
|
|
|
8
8
|
export declare function createSlugger(): (value: string) => string;
|
|
9
9
|
export declare function sanitizeUrl(value: string): string;
|
|
10
10
|
export declare function normalizeReferenceLabel(value: string): string;
|
|
11
|
+
export declare function footnoteId(label: string): string;
|
|
11
12
|
export declare function splitLines(value: string): string[];
|
|
12
13
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAU5C,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAE9C;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAI/D;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,UAAU,EAAE,GAAG,MAAM,CAQrD;AAED,wBAAgB,aAAa,KAGnB,OAAO,MAAM,YActB;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAOjD;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE7D;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAIlD"}
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAU5C,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAE9C;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAI/D;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,UAAU,EAAE,GAAG,MAAM,CAQrD;AAED,wBAAgB,aAAa,KAGnB,OAAO,MAAM,YActB;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAOjD;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE7D;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAIhD;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAIlD"}
|
package/dist/utils.js
CHANGED
|
@@ -65,6 +65,11 @@ export function sanitizeUrl(value) {
|
|
|
65
65
|
export function normalizeReferenceLabel(value) {
|
|
66
66
|
return value.trim().toLowerCase();
|
|
67
67
|
}
|
|
68
|
+
export function footnoteId(label) {
|
|
69
|
+
return normalizeReferenceLabel(label)
|
|
70
|
+
.replace(/[^a-z0-9_-]+/g, '-')
|
|
71
|
+
.replace(/^-+|-+$/g, '');
|
|
72
|
+
}
|
|
68
73
|
export function splitLines(value) {
|
|
69
74
|
const lines = value.split('\n');
|
|
70
75
|
if (lines.at(-1) === '')
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/markdown",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A tiny deterministic TanStack-flavored markdown renderer.",
|
|
6
6
|
"license": "MIT",
|
|
7
|
+
"packageManager": "pnpm@11.4.0",
|
|
7
8
|
"sideEffects": false,
|
|
8
9
|
"files": [
|
|
9
10
|
"dist",
|
|
@@ -52,6 +53,14 @@
|
|
|
52
53
|
"import": "./dist/extensions/tabs.js"
|
|
53
54
|
}
|
|
54
55
|
},
|
|
56
|
+
"scripts": {
|
|
57
|
+
"build": "rm -rf dist && tsc -p tsconfig.build.json",
|
|
58
|
+
"typecheck": "tsc --noEmit",
|
|
59
|
+
"test": "vitest run",
|
|
60
|
+
"bench": "tsx scripts/bench.ts",
|
|
61
|
+
"size": "tsx scripts/measure-size.ts",
|
|
62
|
+
"research": "pnpm run size && pnpm run bench"
|
|
63
|
+
},
|
|
55
64
|
"publishConfig": {
|
|
56
65
|
"access": "public"
|
|
57
66
|
},
|
|
@@ -82,13 +91,5 @@
|
|
|
82
91
|
"typescript": "^5.8.0",
|
|
83
92
|
"unified": "^11.0.5",
|
|
84
93
|
"vitest": "^3.2.0"
|
|
85
|
-
},
|
|
86
|
-
"scripts": {
|
|
87
|
-
"build": "rm -rf dist && tsc -p tsconfig.build.json",
|
|
88
|
-
"typecheck": "tsc --noEmit",
|
|
89
|
-
"test": "vitest run",
|
|
90
|
-
"bench": "tsx scripts/bench.ts",
|
|
91
|
-
"size": "tsx scripts/measure-size.ts",
|
|
92
|
-
"research": "pnpm run size && pnpm run bench"
|
|
93
94
|
}
|
|
94
|
-
}
|
|
95
|
+
}
|