tsondb 0.10.1 → 0.10.2
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.
|
@@ -24,11 +24,17 @@ type AttributedStringMarkdownNode = {
|
|
|
24
24
|
attributes: Record<string, string | number | boolean>;
|
|
25
25
|
content: InlineMarkdownNode[];
|
|
26
26
|
};
|
|
27
|
+
type SuperscriptInlineNode = {
|
|
28
|
+
kind: "superscript";
|
|
29
|
+
content: InlineMarkdownNode[];
|
|
30
|
+
};
|
|
27
31
|
type FootnoteRefInlineNode = {
|
|
28
32
|
kind: "footnoteRef";
|
|
29
33
|
label: string;
|
|
30
34
|
};
|
|
31
|
-
export type InlineMarkdownNode = BoldMarkdownNode | ItalicMarkdownNode | CodeMarkdownNode | LinkMarkdownNode | AttributedStringMarkdownNode | TextNode | FootnoteRefInlineNode;
|
|
35
|
+
export type InlineMarkdownNode = BoldMarkdownNode | ItalicMarkdownNode | CodeMarkdownNode | LinkMarkdownNode | AttributedStringMarkdownNode | TextNode | SuperscriptInlineNode | FootnoteRefInlineNode;
|
|
36
|
+
export declare const parseInlineMarkdown: (text: string) => InlineMarkdownNode[];
|
|
37
|
+
export declare const parseInlineMarkdownForSyntaxHighlighting: (text: string) => InlineMarkdownNode[];
|
|
32
38
|
export declare const checkTableRowsAreSections: (rows: TableRowBlockNode[] | TableSectionBlockNode[]) => rows is TableSectionBlockNode[];
|
|
33
39
|
export declare const syntaxNodeToString: (node: BlockSyntaxMarkdownNode) => string;
|
|
34
40
|
export type ParagraphBlockNode = {
|
|
@@ -150,6 +150,17 @@ const attributedRule = {
|
|
|
150
150
|
};
|
|
151
151
|
},
|
|
152
152
|
};
|
|
153
|
+
const superscriptRule = {
|
|
154
|
+
pattern: /\^(.*?)\^/,
|
|
155
|
+
map: (result, parseInside) => ({
|
|
156
|
+
kind: "superscript",
|
|
157
|
+
content: parseInside(result[1] ?? ""),
|
|
158
|
+
}),
|
|
159
|
+
mapHighlighting: (result, parseInside) => ({
|
|
160
|
+
kind: "superscript",
|
|
161
|
+
content: [textNode("^"), ...parseInside(result[1] ?? ""), textNode("^")],
|
|
162
|
+
}),
|
|
163
|
+
};
|
|
153
164
|
const footnoteRefRule = {
|
|
154
165
|
pattern: /(?<!\\)\[\^([a-zA-Z0-9*]+?)\]/,
|
|
155
166
|
map: ([_match, label = ""]) => ({
|
|
@@ -185,6 +196,7 @@ const inlineRules = [
|
|
|
185
196
|
italicWithBoldRule,
|
|
186
197
|
boldRule,
|
|
187
198
|
italicRule,
|
|
199
|
+
superscriptRule,
|
|
188
200
|
footnoteRefRule,
|
|
189
201
|
textRule,
|
|
190
202
|
];
|
|
@@ -210,7 +222,8 @@ const parseForInlineRules = (rules, text, forSyntaxHighlighting) => {
|
|
|
210
222
|
return parseForInlineRules(rules.slice(1), text, forSyntaxHighlighting);
|
|
211
223
|
}
|
|
212
224
|
};
|
|
213
|
-
const parseInlineMarkdown = (text
|
|
225
|
+
export const parseInlineMarkdown = (text) => parseForInlineRules(inlineRules, text, false);
|
|
226
|
+
export const parseInlineMarkdownForSyntaxHighlighting = (text) => reduceSyntaxNodes(parseForInlineRules(inlineRules, text, true));
|
|
214
227
|
const nodesForTrailingWhitespace = (text) => {
|
|
215
228
|
const trailingWhitespace = text ?? "";
|
|
216
229
|
return trailingWhitespace.length === 0 ? [] : [textNode(trailingWhitespace)];
|
|
@@ -222,7 +235,7 @@ const listRule = {
|
|
|
222
235
|
ordered: /^\d+\. /.test(result[0]),
|
|
223
236
|
content: (result[1] ?? "").split("\n").map(item => ({
|
|
224
237
|
kind: "listItem",
|
|
225
|
-
content: parseInlineMarkdown(item.replace(/^\d+\. |[-*] /, "")
|
|
238
|
+
content: parseInlineMarkdown(item.replace(/^\d+\. |[-*] /, "")),
|
|
226
239
|
})),
|
|
227
240
|
}),
|
|
228
241
|
mapHighlighting: result => [
|
|
@@ -231,7 +244,7 @@ const listRule = {
|
|
|
231
244
|
kind: "listItemMarker",
|
|
232
245
|
content: /^(\d+\. |[-*] )/.exec(item)?.[1] ?? "",
|
|
233
246
|
},
|
|
234
|
-
...
|
|
247
|
+
...parseInlineMarkdownForSyntaxHighlighting(item.replace(/^\d+\. |[-*] /, "")),
|
|
235
248
|
...(index < array.length - 1 ? [textNode("\n")] : []),
|
|
236
249
|
]),
|
|
237
250
|
...nodesForTrailingWhitespace(result[2]),
|
|
@@ -241,10 +254,10 @@ const paragraphRule = {
|
|
|
241
254
|
pattern: /^((?:[^\n]+?)(?:\n[^\n]+?)*)(\n{2,}|\s*$)/,
|
|
242
255
|
map: ([_res, content = "", _trailingWhitespace]) => ({
|
|
243
256
|
kind: "paragraph",
|
|
244
|
-
content: parseInlineMarkdown(content
|
|
257
|
+
content: parseInlineMarkdown(content),
|
|
245
258
|
}),
|
|
246
259
|
mapHighlighting: ([_res, content = "", trailingWhitespace]) => [
|
|
247
|
-
...
|
|
260
|
+
...parseInlineMarkdownForSyntaxHighlighting(content),
|
|
248
261
|
...nodesForTrailingWhitespace(trailingWhitespace),
|
|
249
262
|
],
|
|
250
263
|
};
|
|
@@ -253,11 +266,11 @@ const headingRule = {
|
|
|
253
266
|
map: result => ({
|
|
254
267
|
kind: "heading",
|
|
255
268
|
level: result[1]?.length ?? 1,
|
|
256
|
-
content: parseInlineMarkdown(result[3] ?? ""
|
|
269
|
+
content: parseInlineMarkdown(result[3] ?? ""),
|
|
257
270
|
}),
|
|
258
271
|
mapHighlighting: result => [
|
|
259
272
|
{ kind: "headingMarker", content: (result[1] ?? "") + (result[2] ?? "") },
|
|
260
|
-
...
|
|
273
|
+
...parseInlineMarkdownForSyntaxHighlighting(result[3] ?? ""),
|
|
261
274
|
...nodesForTrailingWhitespace(result[4]),
|
|
262
275
|
],
|
|
263
276
|
};
|
|
@@ -279,7 +292,7 @@ const parseContentRow = (row) => row
|
|
|
279
292
|
omitUndefinedKeys({
|
|
280
293
|
kind: "tableCell",
|
|
281
294
|
colSpan: colSpan !== undefined && colSpan > 1 ? colSpan : undefined,
|
|
282
|
-
content: parseInlineMarkdown(segment.trim()
|
|
295
|
+
content: parseInlineMarkdown(segment.trim()),
|
|
283
296
|
}),
|
|
284
297
|
];
|
|
285
298
|
}
|
|
@@ -287,7 +300,7 @@ const parseContentRow = (row) => row
|
|
|
287
300
|
}, []);
|
|
288
301
|
const parseContentRowForSyntaxHighlighting = (row) => row.split(/(\|+)/).reduce((acc, segment, index) => {
|
|
289
302
|
if (index % 2 === 0) {
|
|
290
|
-
return [...acc, ...
|
|
303
|
+
return [...acc, ...parseInlineMarkdownForSyntaxHighlighting(segment)];
|
|
291
304
|
}
|
|
292
305
|
else {
|
|
293
306
|
return [...acc, tableMarker(segment)];
|
|
@@ -313,7 +326,9 @@ const tableRule = {
|
|
|
313
326
|
pattern: /^(?:(\|#)(.+?)(#\|)\n)?(\|)?(.+?(?:(?<!\\)\|.+?)+)((?<!\\)\|)?\n((?:\| *)?(?:-{3,}|:-{2,}|-{2,}:|:-+:)(?: *\| *(?:-{3,}|:-{2,}|-{2,}:|:-+:))*(?: *\|)?)((?:\n\|?.+?(?:(?<!\\)\|+.+?)*(?:(?<!\\)\|+)?)+)(\n{2,}|$)/,
|
|
314
327
|
map: ([_res, _captionMarkerStart, caption, _captionMarkerEnd, _headerMarkerStart, headers, _headerMarkerEnd, bodySeparators = "", body, _trailingWhitespace,]) => omitUndefinedKeys({
|
|
315
328
|
kind: "table",
|
|
316
|
-
caption: caption !== undefined
|
|
329
|
+
caption: caption !== undefined
|
|
330
|
+
? parseInlineMarkdownForSyntaxHighlighting(caption.trim())
|
|
331
|
+
: undefined,
|
|
317
332
|
columns: trimPipes(bodySeparators)
|
|
318
333
|
.split("|")
|
|
319
334
|
.map(col => omitUndefinedKeys({
|
|
@@ -387,7 +402,7 @@ const tableRule = {
|
|
|
387
402
|
...(caption !== undefined
|
|
388
403
|
? [
|
|
389
404
|
tableMarker(captionMarkerStart ?? ""),
|
|
390
|
-
...
|
|
405
|
+
...parseInlineMarkdownForSyntaxHighlighting(caption),
|
|
391
406
|
tableMarker(captionMarkerEnd ?? ""),
|
|
392
407
|
textNode("\n"),
|
|
393
408
|
]
|
|
@@ -396,8 +411,8 @@ const tableRule = {
|
|
|
396
411
|
...(headers
|
|
397
412
|
?.split("|")
|
|
398
413
|
.flatMap((th, i) => i === 0
|
|
399
|
-
?
|
|
400
|
-
: [tableMarker("|"), ...
|
|
414
|
+
? parseInlineMarkdownForSyntaxHighlighting(th)
|
|
415
|
+
: [tableMarker("|"), ...parseInlineMarkdownForSyntaxHighlighting(th)]) ?? []),
|
|
401
416
|
tableMarker(headerMarkerEnd ?? ""),
|
|
402
417
|
textNode("\n"),
|
|
403
418
|
tableMarker(bodySeparators ?? ""),
|
|
@@ -439,6 +454,7 @@ export const syntaxNodeToString = (node) => {
|
|
|
439
454
|
case "italic":
|
|
440
455
|
case "link":
|
|
441
456
|
case "attributed":
|
|
457
|
+
case "superscript":
|
|
442
458
|
return node.content.map(syntaxNodeToString).join("");
|
|
443
459
|
case "text":
|
|
444
460
|
case "code":
|
|
@@ -461,6 +477,7 @@ const addIndentationToSyntax = (nodes, nextUpperNode) => nodes.reduce((accNodes,
|
|
|
461
477
|
case "italic":
|
|
462
478
|
case "link":
|
|
463
479
|
case "attributed":
|
|
480
|
+
case "superscript":
|
|
464
481
|
return [
|
|
465
482
|
...accNodes,
|
|
466
483
|
{
|
|
@@ -516,7 +533,7 @@ const definitionListRule = {
|
|
|
516
533
|
const terms = termsText
|
|
517
534
|
.trim()
|
|
518
535
|
.split("\n")
|
|
519
|
-
.map(term => parseInlineMarkdown(term.trim()
|
|
536
|
+
.map(term => parseInlineMarkdown(term.trim()));
|
|
520
537
|
const definitions = definitionsText
|
|
521
538
|
.split("\n:")
|
|
522
539
|
.slice(1)
|
|
@@ -537,7 +554,7 @@ const definitionListRule = {
|
|
|
537
554
|
const terms = termsText
|
|
538
555
|
.split("\n")
|
|
539
556
|
.flatMap((term, index, termArray) => [
|
|
540
|
-
...
|
|
557
|
+
...parseInlineMarkdownForSyntaxHighlighting(term),
|
|
541
558
|
...(index < termArray.length - 1 ? [textNode("\n")] : []),
|
|
542
559
|
]);
|
|
543
560
|
const definitions = definitionsText
|
|
@@ -602,6 +619,7 @@ const reduceSyntaxNode = (node) => {
|
|
|
602
619
|
case "bold":
|
|
603
620
|
case "italic":
|
|
604
621
|
case "link":
|
|
622
|
+
case "superscript":
|
|
605
623
|
return { ...node, content: reduceSyntaxNodes(node.content) };
|
|
606
624
|
case "code":
|
|
607
625
|
case "attributed":
|
|
@@ -628,6 +646,7 @@ const syntaxNodeMergeRules = {
|
|
|
628
646
|
headingMarker: (a, b) => ({ ...a, content: a.content + b.content }),
|
|
629
647
|
sectionMarker: (a, b) => ({ ...a, content: a.content + b.content }),
|
|
630
648
|
footnoteMarker: (a, b) => ({ ...a, content: a.content + b.content }),
|
|
649
|
+
superscript: (a, b) => ({ ...a, content: [...a.content, ...b.content] }),
|
|
631
650
|
definitionMarker: (a, b) => ({ ...a, content: a.content + b.content }),
|
|
632
651
|
footnoteRef: null,
|
|
633
652
|
link: null,
|
|
@@ -22,6 +22,8 @@ export const InlineMarkdown = ({ node }) => {
|
|
|
22
22
|
const trailingNodes = node.content.slice(attributesEnd);
|
|
23
23
|
return (_jsxs("span", { class: "attributed", ...Object.fromEntries(Object.entries(node.attributes).map(([k, v]) => [`data-${k}`, v.toString()])), children: [leadingNodes.map((inline, i) => (_jsx(InlineMarkdown, { node: inline }, i))), Array.from({ length: count }, (_, i) => (_jsxs(Fragment, { children: [_jsx("span", { class: "attributed__name", children: _jsx(InlineMarkdown, { node: attributes[i * 4] ?? emptyNode }) }), _jsx("span", { class: "attributed__separator", children: _jsx(InlineMarkdown, { node: attributes[i * 4 + 1] ?? emptyNode }) }), _jsx("span", { class: "attributed__value", children: _jsx(InlineMarkdown, { node: attributes[i * 4 + 2] ?? emptyNode }) }), i < count - 1 && (_jsx("span", { class: "attributed__separator", children: _jsx(InlineMarkdown, { node: attributes[i * 4 + 3] ?? emptyNode }) }))] }, `attr-${(i + 1).toString()}`))), trailingNodes.map((inline, i) => (_jsx(InlineMarkdown, { node: inline }, i)))] }));
|
|
24
24
|
}
|
|
25
|
+
case "superscript":
|
|
26
|
+
return (_jsx("sup", { children: node.content.map((inline, i) => (_jsx(InlineMarkdown, { node: inline }, i))) }));
|
|
25
27
|
case "footnoteRef": {
|
|
26
28
|
const isNumeric = /^\d+$/.test(node.label);
|
|
27
29
|
return (_jsx("sup", { class: "footnote-ref" + (isNumeric ? " footnote-ref--numeric" : ""), "data-reference": node.label, style: { "--label": isNumeric ? Number.parseInt(node.label) : node.label }, children: _jsx("span", { class: "footnote-label", children: node.label }) }));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tsondb",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "Lukas Obermann",
|
|
@@ -32,19 +32,19 @@
|
|
|
32
32
|
"release:sign": "commit-and-tag-version --sign --signoff"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@eslint/js": "^9.
|
|
35
|
+
"@eslint/js": "^9.37.0",
|
|
36
36
|
"@types/debug": "^4.1.12",
|
|
37
37
|
"@types/express": "^5.0.3",
|
|
38
|
-
"@types/node": "^24.
|
|
38
|
+
"@types/node": "^24.8.1",
|
|
39
39
|
"commit-and-tag-version": "^12.6.0",
|
|
40
|
-
"eslint": "^9.
|
|
40
|
+
"eslint": "^9.37.0",
|
|
41
41
|
"eslint-plugin-react": "^7.37.5",
|
|
42
|
-
"eslint-plugin-react-hooks": "^
|
|
42
|
+
"eslint-plugin-react-hooks": "^7.0.0",
|
|
43
43
|
"globals": "^16.4.0",
|
|
44
44
|
"prettier": "^3.6.2",
|
|
45
45
|
"tsx": "^4.20.6",
|
|
46
46
|
"typescript": "^5.9.3",
|
|
47
|
-
"typescript-eslint": "^8.
|
|
47
|
+
"typescript-eslint": "^8.46.1"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"@preact/signals": "^2.3.2",
|