@nuucognition/ncm-ui 0.1.1-beta.0 → 0.1.1-beta.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.
- package/dist/blocks/admonition/index.js +118 -46
- package/dist/blocks/aside/index.js +118 -46
- package/dist/blocks/blockquote/index.d.ts +7 -5
- package/dist/blocks/blockquote/index.js +1218 -36
- package/dist/blocks/chart/index.js +2 -1
- package/dist/blocks/container/index.js +72 -31
- package/dist/blocks/custom-code/index.js +1 -1
- package/dist/blocks/dataview/index.js +2 -1
- package/dist/blocks/definition/index.js +117 -45
- package/dist/blocks/embedding/index.js +72 -31
- package/dist/blocks/figure/index.js +72 -31
- package/dist/blocks/footnote/index.js +118 -46
- package/dist/blocks/header/index.js +72 -31
- package/dist/blocks/html/index.js +2 -1
- package/dist/blocks/index.js +118 -46
- package/dist/blocks/latex/index.js +2 -2
- package/dist/blocks/list/index.js +72 -31
- package/dist/blocks/math/index.js +3 -2
- package/dist/blocks/mermaid/index.js +2 -1
- package/dist/blocks/paragraph/index.js +72 -31
- package/dist/blocks/spoiler/index.js +118 -46
- package/dist/blocks/table/index.js +73 -32
- package/dist/blocks/task-list/index.js +72 -31
- package/dist/components/index.js +157 -65
- package/dist/components/ncm-block.js +118 -46
- package/dist/components/ncm-document.js +157 -65
- package/dist/context/index.d.ts +1 -1
- package/dist/context/index.js +119 -44
- package/dist/hooks/index.js +118 -46
- package/dist/hooks/use-block-renderer.js +118 -46
- package/dist/index.d.ts +1 -1
- package/dist/index.js +164 -58
- package/dist/inline/index.d.ts +2 -3
- package/dist/inline/index.js +72 -31
- package/dist/lib/defaults.js +118 -46
- package/dist/references-BM-lvGrq.d.ts +99 -0
- package/dist/styles/nuu.css +39 -16
- package/package.json +3 -4
- package/dist/references-BYW5pnj_.d.ts +0 -63
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { createContext, createElement, useContext, useRef, Component, useState, useEffect,
|
|
2
|
+
import { createContext, createElement, useContext, useMemo, useRef, Component, useState, useEffect, useCallback, useId } from 'react';
|
|
3
3
|
import { clsx } from 'clsx';
|
|
4
4
|
import { twMerge } from 'tailwind-merge';
|
|
5
5
|
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
6
|
+
import { serializeInlineContent, isTypedNestedList, parseNcm } from '@nuucognition/ncm';
|
|
6
7
|
import { extractExtension, embedTypeFromExtension } from '@nuucognition/mesh-core';
|
|
7
|
-
import { serializeInlineContent, isTypedNestedList } from '@nuucognition/ncm';
|
|
8
8
|
|
|
9
9
|
// src/components/block-shell.tsx
|
|
10
10
|
function cn(...inputs) {
|
|
@@ -84,6 +84,52 @@ function tryParseInlineRef(input) {
|
|
|
84
84
|
}
|
|
85
85
|
return { token: { type: "inline_ref", kind: "footnote", content: inner.trim() }, length };
|
|
86
86
|
}
|
|
87
|
+
function runLength(input, index, char) {
|
|
88
|
+
let end = index;
|
|
89
|
+
while (end < input.length && input[end] === char) end++;
|
|
90
|
+
return end - index;
|
|
91
|
+
}
|
|
92
|
+
function tryParseEmphasis(input) {
|
|
93
|
+
const char = input[0];
|
|
94
|
+
if (char !== "*" && char !== "_") return null;
|
|
95
|
+
const open = Math.min(3, runLength(input, 0, char));
|
|
96
|
+
const need = open;
|
|
97
|
+
let i = open;
|
|
98
|
+
while (i < input.length) {
|
|
99
|
+
const ch = input[i];
|
|
100
|
+
if (ch === "`") {
|
|
101
|
+
const close = input.indexOf("`", i + 1);
|
|
102
|
+
if (close === -1) break;
|
|
103
|
+
i = close + 1;
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
if (ch !== char) {
|
|
107
|
+
i++;
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
const run = runLength(input, i, char);
|
|
111
|
+
const closes = need === 1 ? run % 2 === 1 : run >= need;
|
|
112
|
+
if (!closes) {
|
|
113
|
+
i += run;
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
const extra = run - need;
|
|
117
|
+
const inner = input.slice(open, i + extra);
|
|
118
|
+
if (inner.length === 0) return null;
|
|
119
|
+
const length = i + run;
|
|
120
|
+
const children = parseInline(inner);
|
|
121
|
+
let token;
|
|
122
|
+
if (need === 3) {
|
|
123
|
+
token = { type: "bold", children: [{ type: "italic", children }] };
|
|
124
|
+
} else if (need === 2) {
|
|
125
|
+
token = { type: "bold", children };
|
|
126
|
+
} else {
|
|
127
|
+
token = { type: "italic", children };
|
|
128
|
+
}
|
|
129
|
+
return { token, length };
|
|
130
|
+
}
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
87
133
|
function parseInline(content) {
|
|
88
134
|
if (!content) return [];
|
|
89
135
|
const tokens = [];
|
|
@@ -155,17 +201,11 @@ function parseInline(content) {
|
|
|
155
201
|
remaining = remaining.slice(linkMatch[0].length);
|
|
156
202
|
continue;
|
|
157
203
|
}
|
|
158
|
-
const
|
|
159
|
-
if (
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
type: "bold",
|
|
164
|
-
children: parseInline(innerContent)
|
|
165
|
-
});
|
|
166
|
-
remaining = remaining.slice(boldMatch[0].length);
|
|
167
|
-
continue;
|
|
168
|
-
}
|
|
204
|
+
const emphasis = tryParseEmphasis(remaining);
|
|
205
|
+
if (emphasis) {
|
|
206
|
+
tokens.push(emphasis.token);
|
|
207
|
+
remaining = remaining.slice(emphasis.length);
|
|
208
|
+
continue;
|
|
169
209
|
}
|
|
170
210
|
const strikeMatch = remaining.match(/^~~(.+?)~~/);
|
|
171
211
|
if (strikeMatch && strikeMatch[1] !== void 0) {
|
|
@@ -176,18 +216,6 @@ function parseInline(content) {
|
|
|
176
216
|
remaining = remaining.slice(strikeMatch[0].length);
|
|
177
217
|
continue;
|
|
178
218
|
}
|
|
179
|
-
const italicMatch = remaining.match(/^\*([^*]+)\*|^_([^_]+)_/);
|
|
180
|
-
if (italicMatch) {
|
|
181
|
-
const innerContent = italicMatch[1] ?? italicMatch[2];
|
|
182
|
-
if (innerContent !== void 0) {
|
|
183
|
-
tokens.push({
|
|
184
|
-
type: "italic",
|
|
185
|
-
children: parseInline(innerContent)
|
|
186
|
-
});
|
|
187
|
-
remaining = remaining.slice(italicMatch[0].length);
|
|
188
|
-
continue;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
219
|
const nextSpecial = findNextSpecialChar(remaining);
|
|
192
220
|
if (nextSpecial > 0) {
|
|
193
221
|
tokens.push({ type: "text", content: remaining.slice(0, nextSpecial) });
|
|
@@ -298,17 +326,30 @@ function ReferenceMarker({ kind, number, children }) {
|
|
|
298
326
|
}
|
|
299
327
|
);
|
|
300
328
|
}
|
|
301
|
-
|
|
329
|
+
function normalizeReferenceContent(content) {
|
|
330
|
+
return content.replace(/\s+/g, " ").trim().toLowerCase();
|
|
331
|
+
}
|
|
332
|
+
var ReferenceNumberingContext = createContext(null);
|
|
302
333
|
var BlockReferenceScopeContext = createContext(null);
|
|
303
|
-
function BlockReferenceScope({
|
|
304
|
-
const
|
|
305
|
-
const
|
|
334
|
+
function BlockReferenceScope({ children }) {
|
|
335
|
+
const numbering = useContext(ReferenceNumberingContext);
|
|
336
|
+
const local = useRef({ ref: /* @__PURE__ */ new Map(), footnote: /* @__PURE__ */ new Map() });
|
|
306
337
|
const counter = useRef({ ref: 0, footnote: 0 });
|
|
307
|
-
counter.current = { ref: 0, footnote: 0 };
|
|
308
338
|
const value = {
|
|
339
|
+
numberFor(kind, content) {
|
|
340
|
+
const key = normalizeReferenceContent(content);
|
|
341
|
+
const fromDocument = numbering?.[kind].get(key);
|
|
342
|
+
if (fromDocument !== void 0) return fromDocument;
|
|
343
|
+
const map = local.current[kind];
|
|
344
|
+
const existing = map.get(key);
|
|
345
|
+
if (existing !== void 0) return existing;
|
|
346
|
+
counter.current[kind] += 1;
|
|
347
|
+
map.set(key, counter.current[kind]);
|
|
348
|
+
return counter.current[kind];
|
|
349
|
+
},
|
|
309
350
|
next(kind) {
|
|
310
351
|
counter.current[kind] += 1;
|
|
311
|
-
return
|
|
352
|
+
return counter.current[kind];
|
|
312
353
|
}
|
|
313
354
|
};
|
|
314
355
|
return /* @__PURE__ */ jsx(BlockReferenceScopeContext.Provider, { value, children });
|
|
@@ -316,7 +357,7 @@ function BlockReferenceScope({ blockId, children }) {
|
|
|
316
357
|
function useBlockReferenceScope() {
|
|
317
358
|
return useContext(BlockReferenceScopeContext);
|
|
318
359
|
}
|
|
319
|
-
var INERT_SCOPE = { next: () => 0 };
|
|
360
|
+
var INERT_SCOPE = { numberFor: () => 0, next: () => 0 };
|
|
320
361
|
function InertReferenceScope({ children }) {
|
|
321
362
|
return /* @__PURE__ */ jsx(BlockReferenceScopeContext.Provider, { value: INERT_SCOPE, children });
|
|
322
363
|
}
|
|
@@ -607,7 +648,7 @@ function TokenRenderer({ token, disableBionic, disableBeeline }) {
|
|
|
607
648
|
);
|
|
608
649
|
}
|
|
609
650
|
case "inline_ref": {
|
|
610
|
-
const number = refScope?.
|
|
651
|
+
const number = refScope?.numberFor(token.kind, token.content) ?? 0;
|
|
611
652
|
return /* @__PURE__ */ jsx(ReferenceMarker, { kind: token.kind, number, children: token.content ? /* @__PURE__ */ jsx(InertReferenceScope, { children: /* @__PURE__ */ jsx(InlineContent, { content: token.content, disableBionic: true, disableBeeline: true }) }) : null });
|
|
612
653
|
}
|
|
613
654
|
default:
|
|
@@ -673,8 +714,32 @@ function renderReadingText(content, opts) {
|
|
|
673
714
|
if (cursor < content.length) pieces.push(content.slice(cursor));
|
|
674
715
|
return /* @__PURE__ */ jsx(Fragment, { children: pieces });
|
|
675
716
|
}
|
|
717
|
+
function quoteBlocks(block) {
|
|
718
|
+
try {
|
|
719
|
+
const doc = parseNcm(block.content, {
|
|
720
|
+
preset: "ncm-full",
|
|
721
|
+
allowMissingFrontmatter: true,
|
|
722
|
+
// Attribution off, as the NUU Editor's bridge keeps it: the promoter's
|
|
723
|
+
// trigger is any last quote line starting with `-`, so a nested quote
|
|
724
|
+
// ending in a list item would lose that item to a `— Author` line.
|
|
725
|
+
blockOptions: { extensions: { attribution: false } }
|
|
726
|
+
});
|
|
727
|
+
const blocks = doc.blocks ?? [];
|
|
728
|
+
if (blocks.length === 0 || blocks.some((child) => child.type === "frontmatter")) {
|
|
729
|
+
return null;
|
|
730
|
+
}
|
|
731
|
+
return blocks.map((child, index) => ({ ...child, id: `${block.id}.${index + 1}`, stableId: void 0 }));
|
|
732
|
+
} catch {
|
|
733
|
+
return null;
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
function QuotedLines({ content }) {
|
|
737
|
+
const lines = content.split("\n");
|
|
738
|
+
return /* @__PURE__ */ jsx(Fragment, { children: lines.map((line, index) => /* @__PURE__ */ jsx("p", { children: line.trim().length > 0 ? /* @__PURE__ */ jsx(InlineContent, { content: line }) : /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: "\xA0" }) }, index)) });
|
|
739
|
+
}
|
|
676
740
|
function BlockquoteBlock({ block, className }) {
|
|
677
|
-
const
|
|
741
|
+
const multiline = block.content.includes("\n");
|
|
742
|
+
const blocks = useMemo(() => multiline ? quoteBlocks(block) : null, [block, multiline]);
|
|
678
743
|
return /* @__PURE__ */ jsx(
|
|
679
744
|
"blockquote",
|
|
680
745
|
{
|
|
@@ -684,7 +749,9 @@ function BlockquoteBlock({ block, className }) {
|
|
|
684
749
|
"data-block-id": block.id,
|
|
685
750
|
"data-ncm-blockquote": "",
|
|
686
751
|
className,
|
|
687
|
-
children:
|
|
752
|
+
children: !multiline ? /* @__PURE__ */ jsx(InlineContent, { content: block.content }) : blocks === null ? /* @__PURE__ */ jsx(QuotedLines, { content: block.content }) : blocks.map(
|
|
753
|
+
(child) => child.type === "paragraph" ? /* @__PURE__ */ jsx(QuotedLines, { content: child.content ?? "" }, blockKey(child)) : /* @__PURE__ */ jsx(NcmBlock, { block: child }, blockKey(child))
|
|
754
|
+
)
|
|
688
755
|
}
|
|
689
756
|
);
|
|
690
757
|
}
|
|
@@ -699,7 +766,8 @@ function ChartBlock({ block, className }) {
|
|
|
699
766
|
"data-ncm-chart": "",
|
|
700
767
|
"data-ncm-chart-type": block.chartType ?? "unknown",
|
|
701
768
|
className: cn(
|
|
702
|
-
|
|
769
|
+
// `overflow-y-hidden` pairs with `overflow-x-auto` on purpose — see the note in `lib/defaults.ts`.
|
|
770
|
+
"overflow-x-auto overflow-y-hidden rounded-lg border border-border bg-muted p-4 font-mono text-sm",
|
|
703
771
|
className
|
|
704
772
|
),
|
|
705
773
|
children: /* @__PURE__ */ jsx("code", { children: block.content })
|
|
@@ -879,7 +947,8 @@ function DataviewBlock({ block, className }) {
|
|
|
879
947
|
"data-ncm-dataview": "",
|
|
880
948
|
"data-ncm-query-type": block.queryType,
|
|
881
949
|
className: cn(
|
|
882
|
-
|
|
950
|
+
// `overflow-y-hidden` pairs with `overflow-x-auto` on purpose — see the note in `lib/defaults.ts`.
|
|
951
|
+
"overflow-x-auto overflow-y-hidden rounded-lg border border-border bg-muted p-4 font-mono text-sm",
|
|
883
952
|
className
|
|
884
953
|
),
|
|
885
954
|
children: /* @__PURE__ */ jsx("code", { children: block.query })
|
|
@@ -1218,7 +1287,8 @@ function HtmlBlock({ block, className }) {
|
|
|
1218
1287
|
"data-block-id": block.id,
|
|
1219
1288
|
"data-ncm-html": "",
|
|
1220
1289
|
className: cn(
|
|
1221
|
-
|
|
1290
|
+
// `overflow-y-hidden` pairs with `overflow-x-auto` on purpose — see the note in `lib/defaults.ts`.
|
|
1291
|
+
"overflow-x-auto overflow-y-hidden rounded-lg border border-border bg-muted p-4 font-mono text-sm",
|
|
1222
1292
|
className
|
|
1223
1293
|
),
|
|
1224
1294
|
children: /* @__PURE__ */ jsx("code", { children: block.content })
|
|
@@ -1256,7 +1326,7 @@ function LatexDisplayBlock({ block, className }) {
|
|
|
1256
1326
|
"data-ncm-type": block.type,
|
|
1257
1327
|
"data-block-id": block.id,
|
|
1258
1328
|
"data-ncm-latex-display": "",
|
|
1259
|
-
className: cn("overflow-x-auto", className),
|
|
1329
|
+
className: cn("overflow-x-auto overflow-y-hidden", className),
|
|
1260
1330
|
dangerouslySetInnerHTML: { __html: html }
|
|
1261
1331
|
}
|
|
1262
1332
|
);
|
|
@@ -1271,7 +1341,7 @@ function LatexDisplayBlock({ block, className }) {
|
|
|
1271
1341
|
"data-ncm-type": block.type,
|
|
1272
1342
|
"data-block-id": block.id,
|
|
1273
1343
|
"data-ncm-latex-display": "",
|
|
1274
|
-
className: cn("overflow-x-auto rounded-lg border border-border bg-muted p-4 font-mono text-sm", className),
|
|
1344
|
+
className: cn("overflow-x-auto overflow-y-hidden rounded-lg border border-border bg-muted p-4 font-mono text-sm", className),
|
|
1275
1345
|
children: /* @__PURE__ */ jsx("code", { children: block.content })
|
|
1276
1346
|
}
|
|
1277
1347
|
);
|
|
@@ -1391,7 +1461,7 @@ function MathBlock({ block, className }) {
|
|
|
1391
1461
|
"data-ncm-type": block.type,
|
|
1392
1462
|
"data-block-id": block.id,
|
|
1393
1463
|
"data-ncm-math": "",
|
|
1394
|
-
className: cn("overflow-x-auto", className),
|
|
1464
|
+
className: cn("overflow-x-auto overflow-y-hidden", className),
|
|
1395
1465
|
dangerouslySetInnerHTML: { __html: html }
|
|
1396
1466
|
}
|
|
1397
1467
|
);
|
|
@@ -1407,7 +1477,8 @@ function MathBlock({ block, className }) {
|
|
|
1407
1477
|
"data-block-id": block.id,
|
|
1408
1478
|
"data-ncm-math": "",
|
|
1409
1479
|
className: cn(
|
|
1410
|
-
|
|
1480
|
+
// `overflow-y-hidden` pairs with `overflow-x-auto` on purpose — see the note in `lib/defaults.ts`.
|
|
1481
|
+
"overflow-x-auto overflow-y-hidden rounded-lg border border-border bg-muted p-4 font-mono text-sm",
|
|
1411
1482
|
className
|
|
1412
1483
|
),
|
|
1413
1484
|
children: /* @__PURE__ */ jsx("code", { children: block.content })
|
|
@@ -1425,7 +1496,8 @@ function MermaidBlock({ block, className }) {
|
|
|
1425
1496
|
"data-ncm-mermaid": "",
|
|
1426
1497
|
"data-ncm-diagram-type": block.diagramType,
|
|
1427
1498
|
className: cn(
|
|
1428
|
-
|
|
1499
|
+
// `overflow-y-hidden` pairs with `overflow-x-auto` on purpose — see the note in `lib/defaults.ts`.
|
|
1500
|
+
"overflow-x-auto overflow-y-hidden rounded-lg border border-border bg-muted p-4 font-mono text-sm",
|
|
1429
1501
|
className
|
|
1430
1502
|
),
|
|
1431
1503
|
children: /* @__PURE__ */ jsx("code", { children: block.content })
|
|
@@ -1486,7 +1558,7 @@ function TableBlock({ block, className }) {
|
|
|
1486
1558
|
"data-ncm-type": block.type,
|
|
1487
1559
|
"data-block-id": block.id,
|
|
1488
1560
|
"data-ncm-table": "",
|
|
1489
|
-
className: cn("w-full overflow-x-auto", className),
|
|
1561
|
+
className: cn("w-full overflow-x-auto overflow-y-hidden", className),
|
|
1490
1562
|
children: /* @__PURE__ */ jsxs("table", { role: "table", "data-ncm-table-element": "", children: [
|
|
1491
1563
|
/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsx("tr", { "data-ncm-table-row": "", children: block.headers.map((header, index) => /* @__PURE__ */ jsx("th", { "data-ncm-table-header": "", children: /* @__PURE__ */ jsx(InlineContent, { content: header }) }, index)) }) }),
|
|
1492
1564
|
/* @__PURE__ */ jsx("tbody", { children: block.rows.map((row, rowIndex) => {
|
|
@@ -1572,7 +1644,7 @@ function FallbackBlock({ block, className }) {
|
|
|
1572
1644
|
"data-block-id": block.id,
|
|
1573
1645
|
"data-ncm-fallback": "",
|
|
1574
1646
|
className: cn(
|
|
1575
|
-
"overflow-x-auto rounded-lg border border-border bg-muted p-4 font-mono text-sm",
|
|
1647
|
+
"overflow-x-auto overflow-y-hidden rounded-lg border border-border bg-muted p-4 font-mono text-sm",
|
|
1576
1648
|
className
|
|
1577
1649
|
)
|
|
1578
1650
|
},
|
|
@@ -1628,7 +1700,7 @@ function CustomCodeBlock({ block, className }) {
|
|
|
1628
1700
|
"data-block-id": block.id,
|
|
1629
1701
|
"data-ncm-custom-code": "",
|
|
1630
1702
|
"data-ncm-language": block.language,
|
|
1631
|
-
className: cn("overflow-x-auto", className),
|
|
1703
|
+
className: cn("overflow-x-auto overflow-y-hidden", className),
|
|
1632
1704
|
children: [
|
|
1633
1705
|
/* @__PURE__ */ jsx("div", { className: "mb-2 text-xs font-medium text-muted-foreground", children: block.language }),
|
|
1634
1706
|
/* @__PURE__ */ jsx("pre", { children: /* @__PURE__ */ jsx("code", { children: block.content }) })
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { createContext, createElement, useContext, useRef, Component, useState, useEffect,
|
|
2
|
+
import { createContext, createElement, useContext, useMemo, useRef, Component, useState, useEffect, useCallback, useId } from 'react';
|
|
3
3
|
import { clsx } from 'clsx';
|
|
4
4
|
import { twMerge } from 'tailwind-merge';
|
|
5
5
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
6
|
+
import { serializeInlineContent, isTypedNestedList, parseNcm } from '@nuucognition/ncm';
|
|
6
7
|
import { extractExtension, embedTypeFromExtension } from '@nuucognition/mesh-core';
|
|
7
|
-
import { serializeInlineContent, isTypedNestedList } from '@nuucognition/ncm';
|
|
8
8
|
|
|
9
9
|
// src/components/block-shell.tsx
|
|
10
10
|
function cn(...inputs) {
|
|
@@ -109,6 +109,52 @@ function tryParseInlineRef(input) {
|
|
|
109
109
|
}
|
|
110
110
|
return { token: { type: "inline_ref", kind: "footnote", content: inner.trim() }, length };
|
|
111
111
|
}
|
|
112
|
+
function runLength(input, index, char) {
|
|
113
|
+
let end = index;
|
|
114
|
+
while (end < input.length && input[end] === char) end++;
|
|
115
|
+
return end - index;
|
|
116
|
+
}
|
|
117
|
+
function tryParseEmphasis(input) {
|
|
118
|
+
const char = input[0];
|
|
119
|
+
if (char !== "*" && char !== "_") return null;
|
|
120
|
+
const open = Math.min(3, runLength(input, 0, char));
|
|
121
|
+
const need = open;
|
|
122
|
+
let i = open;
|
|
123
|
+
while (i < input.length) {
|
|
124
|
+
const ch = input[i];
|
|
125
|
+
if (ch === "`") {
|
|
126
|
+
const close = input.indexOf("`", i + 1);
|
|
127
|
+
if (close === -1) break;
|
|
128
|
+
i = close + 1;
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
if (ch !== char) {
|
|
132
|
+
i++;
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
const run = runLength(input, i, char);
|
|
136
|
+
const closes = need === 1 ? run % 2 === 1 : run >= need;
|
|
137
|
+
if (!closes) {
|
|
138
|
+
i += run;
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
const extra = run - need;
|
|
142
|
+
const inner = input.slice(open, i + extra);
|
|
143
|
+
if (inner.length === 0) return null;
|
|
144
|
+
const length = i + run;
|
|
145
|
+
const children = parseInline(inner);
|
|
146
|
+
let token;
|
|
147
|
+
if (need === 3) {
|
|
148
|
+
token = { type: "bold", children: [{ type: "italic", children }] };
|
|
149
|
+
} else if (need === 2) {
|
|
150
|
+
token = { type: "bold", children };
|
|
151
|
+
} else {
|
|
152
|
+
token = { type: "italic", children };
|
|
153
|
+
}
|
|
154
|
+
return { token, length };
|
|
155
|
+
}
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
112
158
|
function parseInline(content) {
|
|
113
159
|
if (!content) return [];
|
|
114
160
|
const tokens = [];
|
|
@@ -180,17 +226,11 @@ function parseInline(content) {
|
|
|
180
226
|
remaining = remaining.slice(linkMatch[0].length);
|
|
181
227
|
continue;
|
|
182
228
|
}
|
|
183
|
-
const
|
|
184
|
-
if (
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
type: "bold",
|
|
189
|
-
children: parseInline(innerContent)
|
|
190
|
-
});
|
|
191
|
-
remaining = remaining.slice(boldMatch[0].length);
|
|
192
|
-
continue;
|
|
193
|
-
}
|
|
229
|
+
const emphasis = tryParseEmphasis(remaining);
|
|
230
|
+
if (emphasis) {
|
|
231
|
+
tokens.push(emphasis.token);
|
|
232
|
+
remaining = remaining.slice(emphasis.length);
|
|
233
|
+
continue;
|
|
194
234
|
}
|
|
195
235
|
const strikeMatch = remaining.match(/^~~(.+?)~~/);
|
|
196
236
|
if (strikeMatch && strikeMatch[1] !== void 0) {
|
|
@@ -201,18 +241,6 @@ function parseInline(content) {
|
|
|
201
241
|
remaining = remaining.slice(strikeMatch[0].length);
|
|
202
242
|
continue;
|
|
203
243
|
}
|
|
204
|
-
const italicMatch = remaining.match(/^\*([^*]+)\*|^_([^_]+)_/);
|
|
205
|
-
if (italicMatch) {
|
|
206
|
-
const innerContent = italicMatch[1] ?? italicMatch[2];
|
|
207
|
-
if (innerContent !== void 0) {
|
|
208
|
-
tokens.push({
|
|
209
|
-
type: "italic",
|
|
210
|
-
children: parseInline(innerContent)
|
|
211
|
-
});
|
|
212
|
-
remaining = remaining.slice(italicMatch[0].length);
|
|
213
|
-
continue;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
244
|
const nextSpecial = findNextSpecialChar(remaining);
|
|
217
245
|
if (nextSpecial > 0) {
|
|
218
246
|
tokens.push({ type: "text", content: remaining.slice(0, nextSpecial) });
|
|
@@ -323,17 +351,30 @@ function ReferenceMarker({ kind, number, children }) {
|
|
|
323
351
|
}
|
|
324
352
|
);
|
|
325
353
|
}
|
|
326
|
-
|
|
354
|
+
function normalizeReferenceContent(content) {
|
|
355
|
+
return content.replace(/\s+/g, " ").trim().toLowerCase();
|
|
356
|
+
}
|
|
357
|
+
var ReferenceNumberingContext = createContext(null);
|
|
327
358
|
var BlockReferenceScopeContext = createContext(null);
|
|
328
|
-
function BlockReferenceScope({
|
|
329
|
-
const
|
|
330
|
-
const
|
|
359
|
+
function BlockReferenceScope({ children }) {
|
|
360
|
+
const numbering = useContext(ReferenceNumberingContext);
|
|
361
|
+
const local = useRef({ ref: /* @__PURE__ */ new Map(), footnote: /* @__PURE__ */ new Map() });
|
|
331
362
|
const counter = useRef({ ref: 0, footnote: 0 });
|
|
332
|
-
counter.current = { ref: 0, footnote: 0 };
|
|
333
363
|
const value = {
|
|
364
|
+
numberFor(kind, content) {
|
|
365
|
+
const key = normalizeReferenceContent(content);
|
|
366
|
+
const fromDocument = numbering?.[kind].get(key);
|
|
367
|
+
if (fromDocument !== void 0) return fromDocument;
|
|
368
|
+
const map = local.current[kind];
|
|
369
|
+
const existing = map.get(key);
|
|
370
|
+
if (existing !== void 0) return existing;
|
|
371
|
+
counter.current[kind] += 1;
|
|
372
|
+
map.set(key, counter.current[kind]);
|
|
373
|
+
return counter.current[kind];
|
|
374
|
+
},
|
|
334
375
|
next(kind) {
|
|
335
376
|
counter.current[kind] += 1;
|
|
336
|
-
return
|
|
377
|
+
return counter.current[kind];
|
|
337
378
|
}
|
|
338
379
|
};
|
|
339
380
|
return /* @__PURE__ */ jsx(BlockReferenceScopeContext.Provider, { value, children });
|
|
@@ -341,7 +382,7 @@ function BlockReferenceScope({ blockId, children }) {
|
|
|
341
382
|
function useBlockReferenceScope() {
|
|
342
383
|
return useContext(BlockReferenceScopeContext);
|
|
343
384
|
}
|
|
344
|
-
var INERT_SCOPE = { next: () => 0 };
|
|
385
|
+
var INERT_SCOPE = { numberFor: () => 0, next: () => 0 };
|
|
345
386
|
function InertReferenceScope({ children }) {
|
|
346
387
|
return /* @__PURE__ */ jsx(BlockReferenceScopeContext.Provider, { value: INERT_SCOPE, children });
|
|
347
388
|
}
|
|
@@ -632,7 +673,7 @@ function TokenRenderer({ token, disableBionic, disableBeeline }) {
|
|
|
632
673
|
);
|
|
633
674
|
}
|
|
634
675
|
case "inline_ref": {
|
|
635
|
-
const number = refScope?.
|
|
676
|
+
const number = refScope?.numberFor(token.kind, token.content) ?? 0;
|
|
636
677
|
return /* @__PURE__ */ jsx(ReferenceMarker, { kind: token.kind, number, children: token.content ? /* @__PURE__ */ jsx(InertReferenceScope, { children: /* @__PURE__ */ jsx(InlineContent, { content: token.content, disableBionic: true, disableBeeline: true }) }) : null });
|
|
637
678
|
}
|
|
638
679
|
default:
|
|
@@ -698,8 +739,32 @@ function renderReadingText(content, opts) {
|
|
|
698
739
|
if (cursor < content.length) pieces.push(content.slice(cursor));
|
|
699
740
|
return /* @__PURE__ */ jsx(Fragment, { children: pieces });
|
|
700
741
|
}
|
|
742
|
+
function quoteBlocks(block) {
|
|
743
|
+
try {
|
|
744
|
+
const doc = parseNcm(block.content, {
|
|
745
|
+
preset: "ncm-full",
|
|
746
|
+
allowMissingFrontmatter: true,
|
|
747
|
+
// Attribution off, as the NUU Editor's bridge keeps it: the promoter's
|
|
748
|
+
// trigger is any last quote line starting with `-`, so a nested quote
|
|
749
|
+
// ending in a list item would lose that item to a `— Author` line.
|
|
750
|
+
blockOptions: { extensions: { attribution: false } }
|
|
751
|
+
});
|
|
752
|
+
const blocks = doc.blocks ?? [];
|
|
753
|
+
if (blocks.length === 0 || blocks.some((child) => child.type === "frontmatter")) {
|
|
754
|
+
return null;
|
|
755
|
+
}
|
|
756
|
+
return blocks.map((child, index) => ({ ...child, id: `${block.id}.${index + 1}`, stableId: void 0 }));
|
|
757
|
+
} catch {
|
|
758
|
+
return null;
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
function QuotedLines({ content }) {
|
|
762
|
+
const lines = content.split("\n");
|
|
763
|
+
return /* @__PURE__ */ jsx(Fragment, { children: lines.map((line, index) => /* @__PURE__ */ jsx("p", { children: line.trim().length > 0 ? /* @__PURE__ */ jsx(InlineContent, { content: line }) : /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: "\xA0" }) }, index)) });
|
|
764
|
+
}
|
|
701
765
|
function BlockquoteBlock({ block, className }) {
|
|
702
|
-
const
|
|
766
|
+
const multiline = block.content.includes("\n");
|
|
767
|
+
const blocks = useMemo(() => multiline ? quoteBlocks(block) : null, [block, multiline]);
|
|
703
768
|
return /* @__PURE__ */ jsx(
|
|
704
769
|
"blockquote",
|
|
705
770
|
{
|
|
@@ -709,7 +774,9 @@ function BlockquoteBlock({ block, className }) {
|
|
|
709
774
|
"data-block-id": block.id,
|
|
710
775
|
"data-ncm-blockquote": "",
|
|
711
776
|
className,
|
|
712
|
-
children:
|
|
777
|
+
children: !multiline ? /* @__PURE__ */ jsx(InlineContent, { content: block.content }) : blocks === null ? /* @__PURE__ */ jsx(QuotedLines, { content: block.content }) : blocks.map(
|
|
778
|
+
(child) => child.type === "paragraph" ? /* @__PURE__ */ jsx(QuotedLines, { content: child.content ?? "" }, blockKey(child)) : /* @__PURE__ */ jsx(NcmBlock, { block: child }, blockKey(child))
|
|
779
|
+
)
|
|
713
780
|
}
|
|
714
781
|
);
|
|
715
782
|
}
|
|
@@ -724,7 +791,8 @@ function ChartBlock({ block, className }) {
|
|
|
724
791
|
"data-ncm-chart": "",
|
|
725
792
|
"data-ncm-chart-type": block.chartType ?? "unknown",
|
|
726
793
|
className: cn(
|
|
727
|
-
|
|
794
|
+
// `overflow-y-hidden` pairs with `overflow-x-auto` on purpose — see the note in `lib/defaults.ts`.
|
|
795
|
+
"overflow-x-auto overflow-y-hidden rounded-lg border border-border bg-muted p-4 font-mono text-sm",
|
|
728
796
|
className
|
|
729
797
|
),
|
|
730
798
|
children: /* @__PURE__ */ jsx("code", { children: block.content })
|
|
@@ -904,7 +972,8 @@ function DataviewBlock({ block, className }) {
|
|
|
904
972
|
"data-ncm-dataview": "",
|
|
905
973
|
"data-ncm-query-type": block.queryType,
|
|
906
974
|
className: cn(
|
|
907
|
-
|
|
975
|
+
// `overflow-y-hidden` pairs with `overflow-x-auto` on purpose — see the note in `lib/defaults.ts`.
|
|
976
|
+
"overflow-x-auto overflow-y-hidden rounded-lg border border-border bg-muted p-4 font-mono text-sm",
|
|
908
977
|
className
|
|
909
978
|
),
|
|
910
979
|
children: /* @__PURE__ */ jsx("code", { children: block.query })
|
|
@@ -1243,7 +1312,8 @@ function HtmlBlock({ block, className }) {
|
|
|
1243
1312
|
"data-block-id": block.id,
|
|
1244
1313
|
"data-ncm-html": "",
|
|
1245
1314
|
className: cn(
|
|
1246
|
-
|
|
1315
|
+
// `overflow-y-hidden` pairs with `overflow-x-auto` on purpose — see the note in `lib/defaults.ts`.
|
|
1316
|
+
"overflow-x-auto overflow-y-hidden rounded-lg border border-border bg-muted p-4 font-mono text-sm",
|
|
1247
1317
|
className
|
|
1248
1318
|
),
|
|
1249
1319
|
children: /* @__PURE__ */ jsx("code", { children: block.content })
|
|
@@ -1281,7 +1351,7 @@ function LatexDisplayBlock({ block, className }) {
|
|
|
1281
1351
|
"data-ncm-type": block.type,
|
|
1282
1352
|
"data-block-id": block.id,
|
|
1283
1353
|
"data-ncm-latex-display": "",
|
|
1284
|
-
className: cn("overflow-x-auto", className),
|
|
1354
|
+
className: cn("overflow-x-auto overflow-y-hidden", className),
|
|
1285
1355
|
dangerouslySetInnerHTML: { __html: html }
|
|
1286
1356
|
}
|
|
1287
1357
|
);
|
|
@@ -1296,7 +1366,7 @@ function LatexDisplayBlock({ block, className }) {
|
|
|
1296
1366
|
"data-ncm-type": block.type,
|
|
1297
1367
|
"data-block-id": block.id,
|
|
1298
1368
|
"data-ncm-latex-display": "",
|
|
1299
|
-
className: cn("overflow-x-auto rounded-lg border border-border bg-muted p-4 font-mono text-sm", className),
|
|
1369
|
+
className: cn("overflow-x-auto overflow-y-hidden rounded-lg border border-border bg-muted p-4 font-mono text-sm", className),
|
|
1300
1370
|
children: /* @__PURE__ */ jsx("code", { children: block.content })
|
|
1301
1371
|
}
|
|
1302
1372
|
);
|
|
@@ -1416,7 +1486,7 @@ function MathBlock({ block, className }) {
|
|
|
1416
1486
|
"data-ncm-type": block.type,
|
|
1417
1487
|
"data-block-id": block.id,
|
|
1418
1488
|
"data-ncm-math": "",
|
|
1419
|
-
className: cn("overflow-x-auto", className),
|
|
1489
|
+
className: cn("overflow-x-auto overflow-y-hidden", className),
|
|
1420
1490
|
dangerouslySetInnerHTML: { __html: html }
|
|
1421
1491
|
}
|
|
1422
1492
|
);
|
|
@@ -1432,7 +1502,8 @@ function MathBlock({ block, className }) {
|
|
|
1432
1502
|
"data-block-id": block.id,
|
|
1433
1503
|
"data-ncm-math": "",
|
|
1434
1504
|
className: cn(
|
|
1435
|
-
|
|
1505
|
+
// `overflow-y-hidden` pairs with `overflow-x-auto` on purpose — see the note in `lib/defaults.ts`.
|
|
1506
|
+
"overflow-x-auto overflow-y-hidden rounded-lg border border-border bg-muted p-4 font-mono text-sm",
|
|
1436
1507
|
className
|
|
1437
1508
|
),
|
|
1438
1509
|
children: /* @__PURE__ */ jsx("code", { children: block.content })
|
|
@@ -1450,7 +1521,8 @@ function MermaidBlock({ block, className }) {
|
|
|
1450
1521
|
"data-ncm-mermaid": "",
|
|
1451
1522
|
"data-ncm-diagram-type": block.diagramType,
|
|
1452
1523
|
className: cn(
|
|
1453
|
-
|
|
1524
|
+
// `overflow-y-hidden` pairs with `overflow-x-auto` on purpose — see the note in `lib/defaults.ts`.
|
|
1525
|
+
"overflow-x-auto overflow-y-hidden rounded-lg border border-border bg-muted p-4 font-mono text-sm",
|
|
1454
1526
|
className
|
|
1455
1527
|
),
|
|
1456
1528
|
children: /* @__PURE__ */ jsx("code", { children: block.content })
|
|
@@ -1511,7 +1583,7 @@ function TableBlock({ block, className }) {
|
|
|
1511
1583
|
"data-ncm-type": block.type,
|
|
1512
1584
|
"data-block-id": block.id,
|
|
1513
1585
|
"data-ncm-table": "",
|
|
1514
|
-
className: cn("w-full overflow-x-auto", className),
|
|
1586
|
+
className: cn("w-full overflow-x-auto overflow-y-hidden", className),
|
|
1515
1587
|
children: /* @__PURE__ */ jsxs("table", { role: "table", "data-ncm-table-element": "", children: [
|
|
1516
1588
|
/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsx("tr", { "data-ncm-table-row": "", children: block.headers.map((header, index) => /* @__PURE__ */ jsx("th", { "data-ncm-table-header": "", children: /* @__PURE__ */ jsx(InlineContent, { content: header }) }, index)) }) }),
|
|
1517
1589
|
/* @__PURE__ */ jsx("tbody", { children: block.rows.map((row, rowIndex) => {
|
|
@@ -1597,7 +1669,7 @@ function FallbackBlock({ block, className }) {
|
|
|
1597
1669
|
"data-block-id": block.id,
|
|
1598
1670
|
"data-ncm-fallback": "",
|
|
1599
1671
|
className: cn(
|
|
1600
|
-
"overflow-x-auto rounded-lg border border-border bg-muted p-4 font-mono text-sm",
|
|
1672
|
+
"overflow-x-auto overflow-y-hidden rounded-lg border border-border bg-muted p-4 font-mono text-sm",
|
|
1601
1673
|
className
|
|
1602
1674
|
)
|
|
1603
1675
|
},
|
|
@@ -1653,7 +1725,7 @@ function CustomCodeBlock({ block, className }) {
|
|
|
1653
1725
|
"data-block-id": block.id,
|
|
1654
1726
|
"data-ncm-custom-code": "",
|
|
1655
1727
|
"data-ncm-language": block.language,
|
|
1656
|
-
className: cn("overflow-x-auto", className),
|
|
1728
|
+
className: cn("overflow-x-auto overflow-y-hidden", className),
|
|
1657
1729
|
children: [
|
|
1658
1730
|
/* @__PURE__ */ jsx("div", { className: "mb-2 text-xs font-medium text-muted-foreground", children: block.language }),
|
|
1659
1731
|
/* @__PURE__ */ jsx("pre", { children: /* @__PURE__ */ jsx("code", { children: block.content }) })
|
|
@@ -4,12 +4,14 @@ import { a as BlockRendererProps } from '../../renderers-C5f41FCy.js';
|
|
|
4
4
|
|
|
5
5
|
type BlockquoteBlockProps = BlockRendererProps<BlockquoteBlock$1>;
|
|
6
6
|
/**
|
|
7
|
-
* Blockquote block renderer with
|
|
7
|
+
* Blockquote block renderer with nested-block support.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* source
|
|
12
|
-
*
|
|
9
|
+
* A single-line quote renders its inline content directly. A multi-line quote
|
|
10
|
+
* renders the blocks its content parses to: a quoted paragraph keeps one `<p>`
|
|
11
|
+
* per source line (an empty line renders one non-breaking space, so it keeps a
|
|
12
|
+
* full text line of height — the same guard the list renderers use), and every
|
|
13
|
+
* other block — a nested quote, a list, a code fence, a heading, a table —
|
|
14
|
+
* renders through `NcmBlock` exactly as it would at the top level.
|
|
13
15
|
*/
|
|
14
16
|
declare function BlockquoteBlock({ block, className }: BlockquoteBlockProps): react.JSX.Element;
|
|
15
17
|
|