@owomark/processor 0.1.7 → 0.1.9
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/.build-manifest.json +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +238 -140
- package/package.json +2 -2
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"schemaVersion": 1,
|
|
3
3
|
"packageName": "@owomark/processor",
|
|
4
4
|
"packagePath": "owomark/packages/owomark-processor",
|
|
5
|
-
"packageFingerprint": "
|
|
6
|
-
"workspaceFingerprint": "
|
|
7
|
-
"builtAt": "2026-04-
|
|
5
|
+
"packageFingerprint": "7da289c40f30c980810832219951ddd7623f621d0defd2f6eb3fa8e03d20f211",
|
|
6
|
+
"workspaceFingerprint": "947c542dce3fedf4a242f46f580a35ff336c5a64ac6448d24339650ad9dac6a1",
|
|
7
|
+
"builtAt": "2026-04-23T10:30:21.564Z",
|
|
8
8
|
"builderVersion": "2026-04-22-industrialization-v1",
|
|
9
9
|
"inputFiles": [
|
|
10
10
|
"owomark/package.json",
|
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { ComponentPropsWithoutRef, ReactNode } from 'react';
|
|
|
7
7
|
import { BlockContent, Root } from 'mdast';
|
|
8
8
|
import { Root as Root$1 } from 'hast';
|
|
9
9
|
|
|
10
|
-
type SourceRewriteKind = 'indented-code' | 'math-fence';
|
|
10
|
+
type SourceRewriteKind = 'indented-code' | 'math-fence' | 'fence-upgrade';
|
|
11
11
|
type SourceRewriteSegment = {
|
|
12
12
|
kind: SourceRewriteKind;
|
|
13
13
|
normalizedStartLine: number;
|
|
@@ -289,10 +289,10 @@ type InternalProcessorOptions = OwoMarkProcessorOptions & {
|
|
|
289
289
|
* `process(source) → HTML string` contract.
|
|
290
290
|
*/
|
|
291
291
|
declare function createOwoMarkProcessor(options?: OwoMarkProcessorOptions): OwoMarkProcessor;
|
|
292
|
-
declare function getOwoMarkPlugins(options?: InternalProcessorOptions): {
|
|
292
|
+
declare function getOwoMarkPlugins(options?: InternalProcessorOptions): Promise<{
|
|
293
293
|
remarkPlugins: PluginEntry[];
|
|
294
294
|
rehypePlugins: PluginEntry[];
|
|
295
|
-
}
|
|
295
|
+
}>;
|
|
296
296
|
|
|
297
297
|
type DivDomProps = ComponentPropsWithoutRef<'div'>;
|
|
298
298
|
type AsideDomProps = ComponentPropsWithoutRef<'aside'>;
|
package/dist/index.js
CHANGED
|
@@ -7,7 +7,6 @@ import remarkMdx2 from "remark-mdx";
|
|
|
7
7
|
import remarkRehype from "remark-rehype";
|
|
8
8
|
import rehypeKatex from "rehype-katex";
|
|
9
9
|
import rehypeSlug from "rehype-slug";
|
|
10
|
-
import rehypePrettyCode from "rehype-pretty-code";
|
|
11
10
|
import rehypeStringify from "rehype-stringify";
|
|
12
11
|
import remarkDirective2 from "remark-directive";
|
|
13
12
|
|
|
@@ -1348,30 +1347,41 @@ function markdownSandboxHandler(_state, node) {
|
|
|
1348
1347
|
};
|
|
1349
1348
|
}
|
|
1350
1349
|
|
|
1351
|
-
//
|
|
1350
|
+
// ../../../node_modules/unist-util-is/lib/index.js
|
|
1352
1351
|
var convert = (
|
|
1352
|
+
// Note: overloads in JSDoc can’t yet use different `@template`s.
|
|
1353
1353
|
/**
|
|
1354
1354
|
* @type {(
|
|
1355
|
-
* (<
|
|
1356
|
-
* ((test?:
|
|
1355
|
+
* (<Condition extends string>(test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & {type: Condition}) &
|
|
1356
|
+
* (<Condition extends Props>(test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & Condition) &
|
|
1357
|
+
* (<Condition extends TestFunction>(test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & Predicate<Condition, Node>) &
|
|
1358
|
+
* ((test?: null | undefined) => (node?: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node) &
|
|
1359
|
+
* ((test?: Test) => Check)
|
|
1357
1360
|
* )}
|
|
1358
1361
|
*/
|
|
1359
1362
|
/**
|
|
1360
1363
|
* @param {Test} [test]
|
|
1361
|
-
* @returns {
|
|
1364
|
+
* @returns {Check}
|
|
1362
1365
|
*/
|
|
1363
1366
|
(function(test) {
|
|
1364
|
-
if (test ===
|
|
1367
|
+
if (test === null || test === void 0) {
|
|
1365
1368
|
return ok;
|
|
1366
1369
|
}
|
|
1367
|
-
if (typeof test === "
|
|
1368
|
-
return
|
|
1370
|
+
if (typeof test === "function") {
|
|
1371
|
+
return castFactory(test);
|
|
1369
1372
|
}
|
|
1370
1373
|
if (typeof test === "object") {
|
|
1371
|
-
return Array.isArray(test) ? anyFactory(test) :
|
|
1374
|
+
return Array.isArray(test) ? anyFactory(test) : (
|
|
1375
|
+
// Cast because `ReadonlyArray` goes into the above but `isArray`
|
|
1376
|
+
// narrows to `Array`.
|
|
1377
|
+
propertiesFactory(
|
|
1378
|
+
/** @type {Props} */
|
|
1379
|
+
test
|
|
1380
|
+
)
|
|
1381
|
+
);
|
|
1372
1382
|
}
|
|
1373
|
-
if (typeof test === "
|
|
1374
|
-
return
|
|
1383
|
+
if (typeof test === "string") {
|
|
1384
|
+
return typeFactory(test);
|
|
1375
1385
|
}
|
|
1376
1386
|
throw new Error("Expected function, string, or object as test");
|
|
1377
1387
|
})
|
|
@@ -1386,17 +1396,26 @@ function anyFactory(tests) {
|
|
|
1386
1396
|
function any(...parameters) {
|
|
1387
1397
|
let index2 = -1;
|
|
1388
1398
|
while (++index2 < checks.length) {
|
|
1389
|
-
if (checks[index2].
|
|
1399
|
+
if (checks[index2].apply(this, parameters)) return true;
|
|
1390
1400
|
}
|
|
1391
1401
|
return false;
|
|
1392
1402
|
}
|
|
1393
1403
|
}
|
|
1394
|
-
function
|
|
1404
|
+
function propertiesFactory(check) {
|
|
1405
|
+
const checkAsRecord = (
|
|
1406
|
+
/** @type {Record<string, unknown>} */
|
|
1407
|
+
check
|
|
1408
|
+
);
|
|
1395
1409
|
return castFactory(all);
|
|
1396
1410
|
function all(node) {
|
|
1411
|
+
const nodeAsRecord = (
|
|
1412
|
+
/** @type {Record<string, unknown>} */
|
|
1413
|
+
/** @type {unknown} */
|
|
1414
|
+
node
|
|
1415
|
+
);
|
|
1397
1416
|
let key;
|
|
1398
1417
|
for (key in check) {
|
|
1399
|
-
if (
|
|
1418
|
+
if (nodeAsRecord[key] !== checkAsRecord[key]) return false;
|
|
1400
1419
|
}
|
|
1401
1420
|
return true;
|
|
1402
1421
|
}
|
|
@@ -1407,93 +1426,98 @@ function typeFactory(check) {
|
|
|
1407
1426
|
return node && node.type === check;
|
|
1408
1427
|
}
|
|
1409
1428
|
}
|
|
1410
|
-
function castFactory(
|
|
1411
|
-
return
|
|
1412
|
-
function
|
|
1429
|
+
function castFactory(testFunction) {
|
|
1430
|
+
return check;
|
|
1431
|
+
function check(value, index, parent) {
|
|
1413
1432
|
return Boolean(
|
|
1414
|
-
|
|
1415
|
-
|
|
1433
|
+
looksLikeANode(value) && testFunction.call(
|
|
1434
|
+
this,
|
|
1435
|
+
value,
|
|
1436
|
+
typeof index === "number" ? index : void 0,
|
|
1437
|
+
parent || void 0
|
|
1438
|
+
)
|
|
1416
1439
|
);
|
|
1417
1440
|
}
|
|
1418
1441
|
}
|
|
1419
1442
|
function ok() {
|
|
1420
1443
|
return true;
|
|
1421
1444
|
}
|
|
1445
|
+
function looksLikeANode(value) {
|
|
1446
|
+
return value !== null && typeof value === "object" && "type" in value;
|
|
1447
|
+
}
|
|
1422
1448
|
|
|
1423
|
-
//
|
|
1449
|
+
// ../../../node_modules/unist-util-visit-parents/lib/color.node.js
|
|
1424
1450
|
function color(d) {
|
|
1425
1451
|
return "\x1B[33m" + d + "\x1B[39m";
|
|
1426
1452
|
}
|
|
1427
1453
|
|
|
1428
|
-
//
|
|
1454
|
+
// ../../../node_modules/unist-util-visit-parents/lib/index.js
|
|
1455
|
+
var empty = [];
|
|
1429
1456
|
var CONTINUE = true;
|
|
1430
1457
|
var EXIT = false;
|
|
1431
1458
|
var SKIP = "skip";
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
function visit4() {
|
|
1471
|
-
let result = [];
|
|
1472
|
-
let subresult;
|
|
1473
|
-
let offset;
|
|
1474
|
-
let grandparents;
|
|
1475
|
-
if (!test || is2(node, index, parents[parents.length - 1] || null)) {
|
|
1476
|
-
result = toResult(visitor(node, parents));
|
|
1477
|
-
if (result[0] === EXIT) {
|
|
1478
|
-
return result;
|
|
1479
|
-
}
|
|
1459
|
+
function visitParents(tree, test, visitor, reverse) {
|
|
1460
|
+
let check;
|
|
1461
|
+
if (typeof test === "function" && typeof visitor !== "function") {
|
|
1462
|
+
reverse = visitor;
|
|
1463
|
+
visitor = test;
|
|
1464
|
+
} else {
|
|
1465
|
+
check = test;
|
|
1466
|
+
}
|
|
1467
|
+
const is2 = convert(check);
|
|
1468
|
+
const step = reverse ? -1 : 1;
|
|
1469
|
+
factory(tree, void 0, [])();
|
|
1470
|
+
function factory(node, index, parents) {
|
|
1471
|
+
const value = (
|
|
1472
|
+
/** @type {Record<string, unknown>} */
|
|
1473
|
+
node && typeof node === "object" ? node : {}
|
|
1474
|
+
);
|
|
1475
|
+
if (typeof value.type === "string") {
|
|
1476
|
+
const name = (
|
|
1477
|
+
// `hast`
|
|
1478
|
+
typeof value.tagName === "string" ? value.tagName : (
|
|
1479
|
+
// `xast`
|
|
1480
|
+
typeof value.name === "string" ? value.name : void 0
|
|
1481
|
+
)
|
|
1482
|
+
);
|
|
1483
|
+
Object.defineProperty(visit4, "name", {
|
|
1484
|
+
value: "node (" + color(node.type + (name ? "<" + name + ">" : "")) + ")"
|
|
1485
|
+
});
|
|
1486
|
+
}
|
|
1487
|
+
return visit4;
|
|
1488
|
+
function visit4() {
|
|
1489
|
+
let result = empty;
|
|
1490
|
+
let subresult;
|
|
1491
|
+
let offset;
|
|
1492
|
+
let grandparents;
|
|
1493
|
+
if (!test || is2(node, index, parents[parents.length - 1] || void 0)) {
|
|
1494
|
+
result = toResult(visitor(node, parents));
|
|
1495
|
+
if (result[0] === EXIT) {
|
|
1496
|
+
return result;
|
|
1480
1497
|
}
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1498
|
+
}
|
|
1499
|
+
if ("children" in node && node.children) {
|
|
1500
|
+
const nodeAsParent = (
|
|
1501
|
+
/** @type {UnistParent} */
|
|
1502
|
+
node
|
|
1503
|
+
);
|
|
1504
|
+
if (nodeAsParent.children && result[0] !== SKIP) {
|
|
1505
|
+
offset = (reverse ? nodeAsParent.children.length : -1) + step;
|
|
1506
|
+
grandparents = parents.concat(nodeAsParent);
|
|
1507
|
+
while (offset > -1 && offset < nodeAsParent.children.length) {
|
|
1508
|
+
const child = nodeAsParent.children[offset];
|
|
1509
|
+
subresult = factory(child, offset, grandparents)();
|
|
1486
1510
|
if (subresult[0] === EXIT) {
|
|
1487
1511
|
return subresult;
|
|
1488
1512
|
}
|
|
1489
1513
|
offset = typeof subresult[1] === "number" ? subresult[1] : offset + step;
|
|
1490
1514
|
}
|
|
1491
1515
|
}
|
|
1492
|
-
return result;
|
|
1493
1516
|
}
|
|
1517
|
+
return result;
|
|
1494
1518
|
}
|
|
1495
|
-
}
|
|
1496
|
-
|
|
1519
|
+
}
|
|
1520
|
+
}
|
|
1497
1521
|
function toResult(value) {
|
|
1498
1522
|
if (Array.isArray(value)) {
|
|
1499
1523
|
return value;
|
|
@@ -1501,41 +1525,30 @@ function toResult(value) {
|
|
|
1501
1525
|
if (typeof value === "number") {
|
|
1502
1526
|
return [CONTINUE, value];
|
|
1503
1527
|
}
|
|
1504
|
-
return [value];
|
|
1528
|
+
return value === null || value === void 0 ? empty : [value];
|
|
1505
1529
|
}
|
|
1506
1530
|
|
|
1507
|
-
//
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
visitParents(tree, test, overload, reverse);
|
|
1529
|
-
function overload(node, parents) {
|
|
1530
|
-
const parent = parents[parents.length - 1];
|
|
1531
|
-
return visitor(
|
|
1532
|
-
node,
|
|
1533
|
-
parent ? parent.children.indexOf(node) : null,
|
|
1534
|
-
parent
|
|
1535
|
-
);
|
|
1536
|
-
}
|
|
1537
|
-
})
|
|
1538
|
-
);
|
|
1531
|
+
// ../../../node_modules/unist-util-visit/lib/index.js
|
|
1532
|
+
function visit3(tree, testOrVisitor, visitorOrReverse, maybeReverse) {
|
|
1533
|
+
let reverse;
|
|
1534
|
+
let test;
|
|
1535
|
+
let visitor;
|
|
1536
|
+
if (typeof testOrVisitor === "function" && typeof visitorOrReverse !== "function") {
|
|
1537
|
+
test = void 0;
|
|
1538
|
+
visitor = testOrVisitor;
|
|
1539
|
+
reverse = visitorOrReverse;
|
|
1540
|
+
} else {
|
|
1541
|
+
test = testOrVisitor;
|
|
1542
|
+
visitor = visitorOrReverse;
|
|
1543
|
+
reverse = maybeReverse;
|
|
1544
|
+
}
|
|
1545
|
+
visitParents(tree, test, overload, reverse);
|
|
1546
|
+
function overload(node, parents) {
|
|
1547
|
+
const parent = parents[parents.length - 1];
|
|
1548
|
+
const index = parent ? parent.children.indexOf(node) : void 0;
|
|
1549
|
+
return visitor(node, index, parent);
|
|
1550
|
+
}
|
|
1551
|
+
}
|
|
1539
1552
|
|
|
1540
1553
|
// src/processor/owo-component-registry.ts
|
|
1541
1554
|
import {
|
|
@@ -2684,6 +2697,75 @@ function getFence(lines) {
|
|
|
2684
2697
|
}
|
|
2685
2698
|
return "~".repeat(longestRun + 1);
|
|
2686
2699
|
}
|
|
2700
|
+
function collectFencedCodeFenceUpgradeRewrites(source, root) {
|
|
2701
|
+
const sourceLines = source.split("\n");
|
|
2702
|
+
const stack = [root];
|
|
2703
|
+
const rewrites = [];
|
|
2704
|
+
while (stack.length > 0) {
|
|
2705
|
+
const node = stack.pop();
|
|
2706
|
+
if (!node) continue;
|
|
2707
|
+
if (node.type === "code") {
|
|
2708
|
+
const startLine = node.position?.start?.line;
|
|
2709
|
+
const endLine = node.position?.end?.line;
|
|
2710
|
+
if (typeof startLine === "number" && typeof endLine === "number" && startLine >= 1 && endLine >= startLine) {
|
|
2711
|
+
const firstLine = sourceLines[startLine - 1] ?? "";
|
|
2712
|
+
const trimmed = firstLine.trimStart();
|
|
2713
|
+
const indent = firstLine.length - trimmed.length;
|
|
2714
|
+
const backtickMatch = trimmed.match(/^(`{3,})/);
|
|
2715
|
+
const tildeMatch = !backtickMatch ? trimmed.match(/^(~{3,})/) : null;
|
|
2716
|
+
const fenceMatch = backtickMatch ?? tildeMatch;
|
|
2717
|
+
if (!fenceMatch) {
|
|
2718
|
+
const children2 = Array.isArray(node.children) ? node.children : [];
|
|
2719
|
+
for (let i = children2.length - 1; i >= 0; i--) stack.push(children2[i]);
|
|
2720
|
+
continue;
|
|
2721
|
+
}
|
|
2722
|
+
const fenceChar = fenceMatch[1][0];
|
|
2723
|
+
const fenceLen = fenceMatch[1].length;
|
|
2724
|
+
let maxInternalFenceLen = 0;
|
|
2725
|
+
for (let i = startLine; i < endLine - 1; i++) {
|
|
2726
|
+
const line = sourceLines[i] ?? "";
|
|
2727
|
+
const contentPart = line.trimStart();
|
|
2728
|
+
const run = fenceChar === "`" ? contentPart.match(/^`{3,}/) : contentPart.match(/^~{3,}/);
|
|
2729
|
+
if (run && run[0].length > maxInternalFenceLen) {
|
|
2730
|
+
maxInternalFenceLen = run[0].length;
|
|
2731
|
+
}
|
|
2732
|
+
}
|
|
2733
|
+
if (maxInternalFenceLen < fenceLen) {
|
|
2734
|
+
const children2 = Array.isArray(node.children) ? node.children : [];
|
|
2735
|
+
for (let i = children2.length - 1; i >= 0; i--) stack.push(children2[i]);
|
|
2736
|
+
continue;
|
|
2737
|
+
}
|
|
2738
|
+
const newFenceLen = maxInternalFenceLen + 1;
|
|
2739
|
+
const newFence = fenceChar.repeat(newFenceLen);
|
|
2740
|
+
const originalLines = sourceLines.slice(startLine - 1, endLine);
|
|
2741
|
+
const lastLine = originalLines[originalLines.length - 1];
|
|
2742
|
+
const lastTrimmed = lastLine.trimStart();
|
|
2743
|
+
const lastIndent = lastLine.length - lastTrimmed.length;
|
|
2744
|
+
const replacementLines = [...originalLines];
|
|
2745
|
+
const infoString = trimmed.slice(fenceLen);
|
|
2746
|
+
replacementLines[0] = " ".repeat(indent) + newFence + infoString;
|
|
2747
|
+
replacementLines[replacementLines.length - 1] = " ".repeat(lastIndent) + newFence;
|
|
2748
|
+
const lineMappings = replacementLines.map((_, offset) => ({
|
|
2749
|
+
sourceLine: startLine + offset,
|
|
2750
|
+
sourceColumn: 1
|
|
2751
|
+
}));
|
|
2752
|
+
rewrites.push({
|
|
2753
|
+
kind: "fence-upgrade",
|
|
2754
|
+
startLine,
|
|
2755
|
+
endLine,
|
|
2756
|
+
replacementLines,
|
|
2757
|
+
lineMappings
|
|
2758
|
+
});
|
|
2759
|
+
}
|
|
2760
|
+
}
|
|
2761
|
+
const children = Array.isArray(node.children) ? node.children : [];
|
|
2762
|
+
for (let index = children.length - 1; index >= 0; index -= 1) {
|
|
2763
|
+
stack.push(children[index]);
|
|
2764
|
+
}
|
|
2765
|
+
}
|
|
2766
|
+
rewrites.sort((left, right) => left.startLine - right.startLine);
|
|
2767
|
+
return rewrites;
|
|
2768
|
+
}
|
|
2687
2769
|
function collectIndentedCodeRewrites(source, root) {
|
|
2688
2770
|
const sourceLines = source.split("\n");
|
|
2689
2771
|
const stack = [root];
|
|
@@ -2765,7 +2847,11 @@ function inspectMdxSource(source, options) {
|
|
|
2765
2847
|
try {
|
|
2766
2848
|
const normalized = normalizeOwoMarkSource(source, { enableMath: options?.enableMath });
|
|
2767
2849
|
const markdownTree = parseMarkdownTree(normalized.source, options);
|
|
2768
|
-
const
|
|
2850
|
+
const indentedRewrites = collectIndentedCodeRewrites(normalized.source, markdownTree);
|
|
2851
|
+
const fenceUpgradeRewrites = collectFencedCodeFenceUpgradeRewrites(normalized.source, markdownTree);
|
|
2852
|
+
const rewrites = [...indentedRewrites, ...fenceUpgradeRewrites].sort(
|
|
2853
|
+
(a, b) => a.startLine - b.startLine
|
|
2854
|
+
);
|
|
2769
2855
|
const compilePlan = applySourceRewrites(normalized.source, normalized.sourceMap, rewrites);
|
|
2770
2856
|
const mdxProbeSource = buildMaskedSource(
|
|
2771
2857
|
compilePlan.source,
|
|
@@ -2858,23 +2944,6 @@ function createInlineMathNode(value) {
|
|
|
2858
2944
|
}
|
|
2859
2945
|
};
|
|
2860
2946
|
}
|
|
2861
|
-
function splitMixedDoubleDollarText(value) {
|
|
2862
|
-
const nodes = [];
|
|
2863
|
-
let cursor = 0;
|
|
2864
|
-
const re = /\$\$([^$\n]+)\$\$/g;
|
|
2865
|
-
let match;
|
|
2866
|
-
while ((match = re.exec(value)) != null) {
|
|
2867
|
-
if (match.index > cursor) {
|
|
2868
|
-
nodes.push({ type: "text", value: value.slice(cursor, match.index) });
|
|
2869
|
-
}
|
|
2870
|
-
nodes.push(createInlineMathNode(match[1]));
|
|
2871
|
-
cursor = match.index + match[0].length;
|
|
2872
|
-
}
|
|
2873
|
-
if (cursor < value.length) {
|
|
2874
|
-
nodes.push({ type: "text", value: value.slice(cursor) });
|
|
2875
|
-
}
|
|
2876
|
-
return nodes.length > 0 ? nodes : [{ type: "text", value }];
|
|
2877
|
-
}
|
|
2878
2947
|
function countLines(raw) {
|
|
2879
2948
|
return raw === "" ? 1 : raw.split("\n").length;
|
|
2880
2949
|
}
|
|
@@ -2959,7 +3028,9 @@ function inlineToMdast(nodes, options) {
|
|
|
2959
3028
|
return nodes.flatMap((node) => {
|
|
2960
3029
|
switch (node.kind) {
|
|
2961
3030
|
case "text":
|
|
2962
|
-
return
|
|
3031
|
+
return [{ type: "text", value: node.text }];
|
|
3032
|
+
case "softBreak":
|
|
3033
|
+
return options.preserveSoftLineBreaks === false ? [{ type: "break" }] : [{ type: "text", value: "\n" }];
|
|
2963
3034
|
case "strong":
|
|
2964
3035
|
return [{ type: "strong", children: inlineToMdast(node.children, options) }];
|
|
2965
3036
|
case "emphasis":
|
|
@@ -3312,16 +3383,26 @@ function buildRootFromBlocks(blocks, options) {
|
|
|
3312
3383
|
function buildRootFromDocument(document, options = {}) {
|
|
3313
3384
|
const conformanceBlocks = [...document.conformance.blocks];
|
|
3314
3385
|
function shiftConformanceForBlock(block) {
|
|
3315
|
-
if (block.type === "side-annotation" || block.type === "side-note-definition" || block.type === "directive-container" || block.type === "custom-block" || block.type === "reference-definition") {
|
|
3386
|
+
if (block.type === "side-annotation" || block.type === "side-note-definition" || block.type === "directive-container" || block.type === "custom-block" || block.type === "reference-definition" || block.type === "paragraph" && block.raw.trim() === "") {
|
|
3316
3387
|
return null;
|
|
3317
3388
|
}
|
|
3318
3389
|
return conformanceBlocks.shift() ?? null;
|
|
3319
3390
|
}
|
|
3320
|
-
const enrichedBlocks =
|
|
3391
|
+
const enrichedBlocks = [];
|
|
3392
|
+
for (let index = 0; index < document.blocks.length; index += 1) {
|
|
3393
|
+
const block = document.blocks[index];
|
|
3321
3394
|
const conformance = shiftConformanceForBlock(block);
|
|
3322
|
-
|
|
3395
|
+
const sourceBlockCount = conformance?.kind === "paragraph" || conformance?.kind === "blockquote" ? conformance.sourceBlockCount ?? 1 : 1;
|
|
3396
|
+
const sourceBlocks = document.blocks.slice(index, index + sourceBlockCount);
|
|
3397
|
+
const mergedRaw = sourceBlocks.map((entry) => entry.raw).join("\n");
|
|
3398
|
+
const mergedSyntaxRaw = sourceBlocks.map((entry) => entry.syntaxRaw).join("\n");
|
|
3399
|
+
const mergedEndLine = sourceBlocks[sourceBlocks.length - 1]?.endLine ?? block.endLine;
|
|
3400
|
+
enrichedBlocks.push({
|
|
3323
3401
|
...block,
|
|
3324
|
-
|
|
3402
|
+
raw: mergedRaw,
|
|
3403
|
+
syntaxRaw: mergedSyntaxRaw,
|
|
3404
|
+
endLine: mergedEndLine,
|
|
3405
|
+
conformanceInline: conformance?.kind === "paragraph" || conformance?.kind === "heading" || conformance?.kind === "blockquote" || conformance?.kind === "listItem" ? conformance.inline : void 0,
|
|
3325
3406
|
conformanceTableNode: conformance?.kind === "table" ? (position) => ({
|
|
3326
3407
|
type: "table",
|
|
3327
3408
|
children: conformance.rows.map((row) => ({
|
|
@@ -3333,8 +3414,9 @@ function buildRootFromDocument(document, options = {}) {
|
|
|
3333
3414
|
})),
|
|
3334
3415
|
position
|
|
3335
3416
|
}) : null
|
|
3336
|
-
};
|
|
3337
|
-
|
|
3417
|
+
});
|
|
3418
|
+
index += sourceBlockCount - 1;
|
|
3419
|
+
}
|
|
3338
3420
|
return buildRootFromBlocks(enrichedBlocks, options);
|
|
3339
3421
|
}
|
|
3340
3422
|
|
|
@@ -3377,6 +3459,14 @@ function planMdxCompileExecution(options) {
|
|
|
3377
3459
|
}
|
|
3378
3460
|
|
|
3379
3461
|
// src/processor/index.ts
|
|
3462
|
+
var _rehypePrettyCode = null;
|
|
3463
|
+
async function loadRehypePrettyCode() {
|
|
3464
|
+
if (!_rehypePrettyCode) {
|
|
3465
|
+
const mod = await import("rehype-pretty-code");
|
|
3466
|
+
_rehypePrettyCode = mod.default;
|
|
3467
|
+
}
|
|
3468
|
+
return _rehypePrettyCode;
|
|
3469
|
+
}
|
|
3380
3470
|
var DEFAULT_CODE_THEME = "vitesse-light";
|
|
3381
3471
|
function buildRemarkPlugins(options) {
|
|
3382
3472
|
const enableMath = options.enableMath !== false;
|
|
@@ -3436,7 +3526,7 @@ function createCanonicalDocumentParser(document, options) {
|
|
|
3436
3526
|
});
|
|
3437
3527
|
};
|
|
3438
3528
|
}
|
|
3439
|
-
function buildRehypePlugins(options) {
|
|
3529
|
+
async function buildRehypePlugins(options) {
|
|
3440
3530
|
const enableMath = options.enableMath !== false;
|
|
3441
3531
|
const enableSideAnnotation = options.enableSideAnnotation !== false;
|
|
3442
3532
|
const theme = options.codeTheme ?? DEFAULT_CODE_THEME;
|
|
@@ -3446,6 +3536,7 @@ function buildRehypePlugins(options) {
|
|
|
3446
3536
|
}
|
|
3447
3537
|
plugins.push(rehypeSlug);
|
|
3448
3538
|
if (options.enableCodeHighlight !== false) {
|
|
3539
|
+
const rehypePrettyCode = await loadRehypePrettyCode();
|
|
3449
3540
|
plugins.push([rehypePrettyCode, { theme }]);
|
|
3450
3541
|
}
|
|
3451
3542
|
if (enableSideAnnotation) {
|
|
@@ -3474,9 +3565,16 @@ function createOwoMarkProcessor(options) {
|
|
|
3474
3565
|
return createUnifiedProcessor(opts);
|
|
3475
3566
|
}
|
|
3476
3567
|
function createUnifiedProcessor(opts) {
|
|
3477
|
-
|
|
3568
|
+
let rehypePluginsPromise = null;
|
|
3569
|
+
function getRehypePlugins() {
|
|
3570
|
+
if (!rehypePluginsPromise) {
|
|
3571
|
+
rehypePluginsPromise = buildRehypePlugins(opts);
|
|
3572
|
+
}
|
|
3573
|
+
return rehypePluginsPromise;
|
|
3574
|
+
}
|
|
3478
3575
|
return {
|
|
3479
3576
|
async process(source) {
|
|
3577
|
+
const rehypePlugins = await getRehypePlugins();
|
|
3480
3578
|
const normalized = normalizeOwoMarkSource(source, { enableMath: opts.enableMath });
|
|
3481
3579
|
const canonicalDocument = opts.canonicalDocument ?? parseMarkdownToDocument2(normalized.source);
|
|
3482
3580
|
const remarkPlugins = buildRemarkPlugins({
|
|
@@ -3564,7 +3662,7 @@ function createMdxProcessor(opts) {
|
|
|
3564
3662
|
extraRemarkDescriptors: opts.extraRemarkDescriptors,
|
|
3565
3663
|
extraRemarkPlugins: opts.extraRemarkPlugins
|
|
3566
3664
|
});
|
|
3567
|
-
const { remarkPlugins, rehypePlugins } = getOwoMarkPlugins({
|
|
3665
|
+
const { remarkPlugins, rehypePlugins } = await getOwoMarkPlugins({
|
|
3568
3666
|
...opts,
|
|
3569
3667
|
mode: "production",
|
|
3570
3668
|
mdxSourceMap: inspection.sourceMap
|
|
@@ -3600,7 +3698,7 @@ function applyPlugin2(proc, entry) {
|
|
|
3600
3698
|
return proc.use(entry);
|
|
3601
3699
|
}
|
|
3602
3700
|
var MDX_MANAGED_REMARK_PLUGINS = /* @__PURE__ */ new Set([remarkParse2, remarkMdx2]);
|
|
3603
|
-
function getOwoMarkPlugins(options) {
|
|
3701
|
+
async function getOwoMarkPlugins(options) {
|
|
3604
3702
|
const opts = {
|
|
3605
3703
|
mode: "production",
|
|
3606
3704
|
preserveSoftLineBreaks: false,
|
|
@@ -3609,7 +3707,7 @@ function getOwoMarkPlugins(options) {
|
|
|
3609
3707
|
const remarkPlugins = buildRemarkPlugins(opts).filter(
|
|
3610
3708
|
(entry) => !MDX_MANAGED_REMARK_PLUGINS.has(entry)
|
|
3611
3709
|
);
|
|
3612
|
-
const rehypePlugins = buildRehypePlugins(opts);
|
|
3710
|
+
const rehypePlugins = await buildRehypePlugins(opts);
|
|
3613
3711
|
return { remarkPlugins, rehypePlugins };
|
|
3614
3712
|
}
|
|
3615
3713
|
export {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@owomark/processor",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
4
4
|
"description": "Node-safe Markdown and MDX processor, plugins, and built-in MDX components for OwoMark.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"access": "public"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@owomark/core": "^0.1.
|
|
41
|
+
"@owomark/core": "^0.1.8",
|
|
42
42
|
"rehype-katex": "^6.0.3",
|
|
43
43
|
"rehype-pretty-code": "^0.14.1",
|
|
44
44
|
"rehype-slug": "^6.0.0",
|