@tiptap/core 3.20.0 → 3.20.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/index.cjs +73 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +73 -18
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/types.ts +6 -0
- package/src/utilities/markdown/renderNestedMarkdownContent.ts +9 -7
- package/src/utilities/mergeAttributes.ts +74 -26
package/dist/index.d.cts
CHANGED
|
@@ -1729,6 +1729,8 @@ type MarkdownParseHelpers = {
|
|
|
1729
1729
|
parseInline: (tokens: MarkdownToken[]) => JSONContent[];
|
|
1730
1730
|
/** Parse an array of block-level tokens */
|
|
1731
1731
|
parseChildren: (tokens: MarkdownToken[]) => JSONContent[];
|
|
1732
|
+
/** Parse block-level tokens while preserving implicit empty paragraphs from blank lines */
|
|
1733
|
+
parseBlockChildren?: (tokens: MarkdownToken[]) => JSONContent[];
|
|
1732
1734
|
/** Create a text node with optional marks */
|
|
1733
1735
|
createTextNode: (text: string, marks?: Array<{
|
|
1734
1736
|
type: string;
|
|
@@ -1776,6 +1778,7 @@ type RenderContext = {
|
|
|
1776
1778
|
level: number;
|
|
1777
1779
|
meta?: Record<string, any>;
|
|
1778
1780
|
parentType?: string | null;
|
|
1781
|
+
previousNode?: JSONContent | null;
|
|
1779
1782
|
};
|
|
1780
1783
|
/** Extension contract for markdown parsing/serialization. */
|
|
1781
1784
|
interface MarkdownExtensionSpec {
|
|
@@ -1825,6 +1828,8 @@ type MarkdownRendererHelpers = {
|
|
|
1825
1828
|
* @returns The rendered markdown string
|
|
1826
1829
|
*/
|
|
1827
1830
|
renderChildren: (nodes: JSONContent | JSONContent[], separator?: string) => string;
|
|
1831
|
+
/** Render a single child node with its sibling index preserved */
|
|
1832
|
+
renderChild?: (node: JSONContent, index: number) => string;
|
|
1828
1833
|
/**
|
|
1829
1834
|
* Render a text token to a markdown string
|
|
1830
1835
|
* @param prefix The prefix to add before the content
|
|
@@ -4864,6 +4869,7 @@ declare function parseIndentedBlocks(src: string, config: BlockParserConfig, lex
|
|
|
4864
4869
|
*/
|
|
4865
4870
|
declare function renderNestedMarkdownContent(node: JSONContent, h: {
|
|
4866
4871
|
renderChildren: (nodes: JSONContent[]) => string;
|
|
4872
|
+
renderChild?: (node: JSONContent, index: number) => string;
|
|
4867
4873
|
indent: (text: string) => string;
|
|
4868
4874
|
}, prefixOrGenerator: string | ((ctx: any) => string), ctx?: any): string;
|
|
4869
4875
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1729,6 +1729,8 @@ type MarkdownParseHelpers = {
|
|
|
1729
1729
|
parseInline: (tokens: MarkdownToken[]) => JSONContent[];
|
|
1730
1730
|
/** Parse an array of block-level tokens */
|
|
1731
1731
|
parseChildren: (tokens: MarkdownToken[]) => JSONContent[];
|
|
1732
|
+
/** Parse block-level tokens while preserving implicit empty paragraphs from blank lines */
|
|
1733
|
+
parseBlockChildren?: (tokens: MarkdownToken[]) => JSONContent[];
|
|
1732
1734
|
/** Create a text node with optional marks */
|
|
1733
1735
|
createTextNode: (text: string, marks?: Array<{
|
|
1734
1736
|
type: string;
|
|
@@ -1776,6 +1778,7 @@ type RenderContext = {
|
|
|
1776
1778
|
level: number;
|
|
1777
1779
|
meta?: Record<string, any>;
|
|
1778
1780
|
parentType?: string | null;
|
|
1781
|
+
previousNode?: JSONContent | null;
|
|
1779
1782
|
};
|
|
1780
1783
|
/** Extension contract for markdown parsing/serialization. */
|
|
1781
1784
|
interface MarkdownExtensionSpec {
|
|
@@ -1825,6 +1828,8 @@ type MarkdownRendererHelpers = {
|
|
|
1825
1828
|
* @returns The rendered markdown string
|
|
1826
1829
|
*/
|
|
1827
1830
|
renderChildren: (nodes: JSONContent | JSONContent[], separator?: string) => string;
|
|
1831
|
+
/** Render a single child node with its sibling index preserved */
|
|
1832
|
+
renderChild?: (node: JSONContent, index: number) => string;
|
|
1828
1833
|
/**
|
|
1829
1834
|
* Render a text token to a markdown string
|
|
1830
1835
|
* @param prefix The prefix to add before the content
|
|
@@ -4864,6 +4869,7 @@ declare function parseIndentedBlocks(src: string, config: BlockParserConfig, lex
|
|
|
4864
4869
|
*/
|
|
4865
4870
|
declare function renderNestedMarkdownContent(node: JSONContent, h: {
|
|
4866
4871
|
renderChildren: (nodes: JSONContent[]) => string;
|
|
4872
|
+
renderChild?: (node: JSONContent, index: number) => string;
|
|
4867
4873
|
indent: (text: string) => string;
|
|
4868
4874
|
}, prefixOrGenerator: string | ((ctx: any) => string), ctx?: any): string;
|
|
4869
4875
|
|
package/dist/index.js
CHANGED
|
@@ -1431,6 +1431,67 @@ function getAttributesFromExtensions(extensions) {
|
|
|
1431
1431
|
}
|
|
1432
1432
|
|
|
1433
1433
|
// src/utilities/mergeAttributes.ts
|
|
1434
|
+
function splitStyleDeclarations(styles) {
|
|
1435
|
+
const result = [];
|
|
1436
|
+
let current = "";
|
|
1437
|
+
let inSingleQuote = false;
|
|
1438
|
+
let inDoubleQuote = false;
|
|
1439
|
+
let parenDepth = 0;
|
|
1440
|
+
const length = styles.length;
|
|
1441
|
+
for (let i = 0; i < length; i += 1) {
|
|
1442
|
+
const char = styles[i];
|
|
1443
|
+
if (char === "'" && !inDoubleQuote) {
|
|
1444
|
+
inSingleQuote = !inSingleQuote;
|
|
1445
|
+
current += char;
|
|
1446
|
+
continue;
|
|
1447
|
+
}
|
|
1448
|
+
if (char === '"' && !inSingleQuote) {
|
|
1449
|
+
inDoubleQuote = !inDoubleQuote;
|
|
1450
|
+
current += char;
|
|
1451
|
+
continue;
|
|
1452
|
+
}
|
|
1453
|
+
if (!inSingleQuote && !inDoubleQuote) {
|
|
1454
|
+
if (char === "(") {
|
|
1455
|
+
parenDepth += 1;
|
|
1456
|
+
current += char;
|
|
1457
|
+
continue;
|
|
1458
|
+
}
|
|
1459
|
+
if (char === ")" && parenDepth > 0) {
|
|
1460
|
+
parenDepth -= 1;
|
|
1461
|
+
current += char;
|
|
1462
|
+
continue;
|
|
1463
|
+
}
|
|
1464
|
+
if (char === ";" && parenDepth === 0) {
|
|
1465
|
+
result.push(current);
|
|
1466
|
+
current = "";
|
|
1467
|
+
continue;
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
current += char;
|
|
1471
|
+
}
|
|
1472
|
+
if (current) {
|
|
1473
|
+
result.push(current);
|
|
1474
|
+
}
|
|
1475
|
+
return result;
|
|
1476
|
+
}
|
|
1477
|
+
function parseStyleEntries(styles) {
|
|
1478
|
+
const pairs = [];
|
|
1479
|
+
const declarations = splitStyleDeclarations(styles || "");
|
|
1480
|
+
const numDeclarations = declarations.length;
|
|
1481
|
+
for (let i = 0; i < numDeclarations; i += 1) {
|
|
1482
|
+
const declaration = declarations[i];
|
|
1483
|
+
const firstColonIndex = declaration.indexOf(":");
|
|
1484
|
+
if (firstColonIndex === -1) {
|
|
1485
|
+
continue;
|
|
1486
|
+
}
|
|
1487
|
+
const property = declaration.slice(0, firstColonIndex).trim();
|
|
1488
|
+
const value = declaration.slice(firstColonIndex + 1).trim();
|
|
1489
|
+
if (property && value) {
|
|
1490
|
+
pairs.push([property, value]);
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
1493
|
+
return pairs;
|
|
1494
|
+
}
|
|
1434
1495
|
function mergeAttributes(...objects) {
|
|
1435
1496
|
return objects.filter((item) => !!item).reduce((items, item) => {
|
|
1436
1497
|
const mergedAttributes = { ...items };
|
|
@@ -1446,17 +1507,7 @@ function mergeAttributes(...objects) {
|
|
|
1446
1507
|
const insertClasses = valueClasses.filter((valueClass) => !existingClasses.includes(valueClass));
|
|
1447
1508
|
mergedAttributes[key] = [...existingClasses, ...insertClasses].join(" ");
|
|
1448
1509
|
} else if (key === "style") {
|
|
1449
|
-
const
|
|
1450
|
-
const existingStyles = mergedAttributes[key] ? mergedAttributes[key].split(";").map((style2) => style2.trim()).filter(Boolean) : [];
|
|
1451
|
-
const styleMap = /* @__PURE__ */ new Map();
|
|
1452
|
-
existingStyles.forEach((style2) => {
|
|
1453
|
-
const [property, val] = style2.split(":").map((part) => part.trim());
|
|
1454
|
-
styleMap.set(property, val);
|
|
1455
|
-
});
|
|
1456
|
-
newStyles.forEach((style2) => {
|
|
1457
|
-
const [property, val] = style2.split(":").map((part) => part.trim());
|
|
1458
|
-
styleMap.set(property, val);
|
|
1459
|
-
});
|
|
1510
|
+
const styleMap = new Map([...parseStyleEntries(mergedAttributes[key]), ...parseStyleEntries(value)]);
|
|
1460
1511
|
mergedAttributes[key] = Array.from(styleMap.entries()).map(([property, val]) => `${property}: ${val}`).join("; ");
|
|
1461
1512
|
} else {
|
|
1462
1513
|
mergedAttributes[key] = value;
|
|
@@ -6377,17 +6428,21 @@ function renderNestedMarkdownContent(node, h2, prefixOrGenerator, ctx) {
|
|
|
6377
6428
|
const prefix = typeof prefixOrGenerator === "function" ? prefixOrGenerator(ctx) : prefixOrGenerator;
|
|
6378
6429
|
const [content, ...children] = node.content;
|
|
6379
6430
|
const mainContent = h2.renderChildren([content]);
|
|
6380
|
-
|
|
6431
|
+
let output = `${prefix}${mainContent}`;
|
|
6381
6432
|
if (children && children.length > 0) {
|
|
6382
|
-
children.forEach((child) => {
|
|
6383
|
-
|
|
6384
|
-
|
|
6385
|
-
|
|
6386
|
-
|
|
6433
|
+
children.forEach((child, index) => {
|
|
6434
|
+
var _a, _b;
|
|
6435
|
+
const childContent = (_b = (_a = h2.renderChild) == null ? void 0 : _a.call(h2, child, index + 1)) != null ? _b : h2.renderChildren([child]);
|
|
6436
|
+
if (childContent !== void 0 && childContent !== null) {
|
|
6437
|
+
const indentedChild = childContent.split("\n").map((line) => line ? h2.indent(line) : h2.indent("")).join("\n");
|
|
6438
|
+
output += child.type === "paragraph" ? `
|
|
6439
|
+
|
|
6440
|
+
${indentedChild}` : `
|
|
6441
|
+
${indentedChild}`;
|
|
6387
6442
|
}
|
|
6388
6443
|
});
|
|
6389
6444
|
}
|
|
6390
|
-
return output
|
|
6445
|
+
return output;
|
|
6391
6446
|
}
|
|
6392
6447
|
|
|
6393
6448
|
// src/MarkView.ts
|