Skip to content

Commit bc38a3b

Browse files
YousefEDnperez0111
andauthored
fix: html diff error with whitespace (#2230)
* fix html diff error with whitespace * improve logging * fix: only preserveWhitespace on node content See [this description for more details](#2230 (comment)) * add test * fix: preserveWhitespace for our parse rule * test: add prefix test --------- Co-authored-by: Nick the Sick <computers@nickthesick.com>
1 parent 8d1916a commit bc38a3b

File tree

11 files changed

+90
-10
lines changed

11 files changed

+90
-10
lines changed

examples/09-ai/02-playground/src/data/aimodels.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ export const AI_MODELS = [
1111
"mistral.chat/mistral-medium-latest",
1212
"mistral.chat/ministral-3b-latest",
1313
"mistral.chat/ministral-8b-latest",
14-
"anthropic.chat/claude-opus-4-1",
15-
"anthropic.chat/claude-sonnet-4-0",
14+
"anthropic.chat/claude-opus-4-5",
15+
"anthropic.chat/claude-sonnet-4-5",
1616
"anthropic.chat/claude-3-7-sonnet-latest",
1717
"anthropic.chat/claude-3-5-haiku-latest",
1818
"albert-etalab.chat/albert-large",

packages/core/src/api/parsers/markdown/parseMarkdown.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,17 @@ export function markdownToHTML(markdown: string): string {
9393
}
9494
},
9595
code,
96+
blockquote: (state: any, node: any) => {
97+
const result = {
98+
type: "element",
99+
tagName: "blockquote",
100+
properties: {},
101+
// The only difference from the original is that we don't wrap the children with line endings
102+
children: state.wrap(state.all(node), false),
103+
};
104+
state.patch(node, result);
105+
return state.applyData(node, result);
106+
},
96107
},
97108
})
98109
.use(rehypeStringify)

packages/core/src/schema/blocks/createSpec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ export function getParseRules<
7070

7171
return props;
7272
},
73+
// Because we do the parsing ourselves, we want to preserve whitespace for content we've parsed
74+
preserveWhitespace: true,
7375
getContent:
7476
config.content === "inline" || config.content === "none"
7577
? (node, schema) => {
@@ -97,6 +99,7 @@ export function getParseRules<
9799
const parser = DOMParser.fromSchema(schema);
98100
const parsed = parser.parse(clone, {
99101
topNode: schema.nodes.paragraph.create(),
102+
preserveWhitespace: true,
100103
});
101104

102105
return parsed.content;

packages/xl-ai/src/api/formats/base-tools/createUpdateBlockTool.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,13 @@ export function createUpdateBlockTool<T>(config: {
143143
const block = editor.getBlock(id);
144144

145145
if (!block) {
146-
// eslint-disable-next-line no-console
147-
console.error("BLOCK NOT FOUND", id);
148146
return {
149147
ok: false,
150-
error: "block not found",
148+
error: new Error("Block not found (update)", {
149+
cause: {
150+
blockId: id,
151+
},
152+
}),
151153
};
152154
}
153155

packages/xl-ai/src/api/formats/base-tools/delete.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,11 @@ export const deleteBlockTool = (
6262
if (!block) {
6363
return {
6464
ok: false,
65-
error: "block not found",
65+
error: new Error("Block not found (delete)", {
66+
cause: {
67+
blockId: id,
68+
},
69+
}),
6670
};
6771
}
6872

packages/xl-ai/src/api/formats/html-blocks/tools/rebaseTool.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,12 @@ export async function createHTMLRebaseTool(
4848
);
4949

5050
if (steps.length) {
51-
// console.error("html diff", steps);
52-
throw new Error("html diff");
51+
throw new Error("html diff", {
52+
cause: {
53+
html,
54+
htmlBlock
55+
}
56+
});
5357
}
5458

5559
return rebaseTool(editor, tr);

tests/src/unit/core/formatConversion/parse/__snapshots__/html/mixedTextTableCell.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
{
1616
"styles": {},
1717
"text": "Table Cell
18-
Table Cell Table Cell",
18+
Table Cell
19+
20+
Table Cell
21+
",
1922
"type": "text",
2023
},
2124
],

tests/src/unit/core/formatConversion/parse/__snapshots__/html/notion.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@
169169
"content": [
170170
{
171171
"styles": {},
172-
"text": "Paragraph With Hard Break",
172+
"text": "Paragraph
173+
With Hard Break",
173174
"type": "text",
174175
},
175176
],
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[
2+
{
3+
"children": [],
4+
"content": [
5+
{
6+
"styles": {},
7+
"text": "hello, ",
8+
"type": "text",
9+
},
10+
],
11+
"id": "1",
12+
"props": {
13+
"backgroundColor": "default",
14+
"textAlignment": "left",
15+
"textColor": "default",
16+
},
17+
"type": "paragraph",
18+
},
19+
]
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[
2+
{
3+
"children": [],
4+
"content": [
5+
{
6+
"styles": {},
7+
"text": " hello,",
8+
"type": "text",
9+
},
10+
],
11+
"id": "1",
12+
"props": {
13+
"backgroundColor": "default",
14+
"textAlignment": "left",
15+
"textColor": "default",
16+
},
17+
"type": "paragraph",
18+
},
19+
]

0 commit comments

Comments
 (0)