Skip to content

Commit 1ad4c04

Browse files
bgreenleenperez0111
authored andcommitted
fix: blockquote HTML parsing #1762 (#1877)
1 parent b9c64ee commit 1ad4c04

File tree

8 files changed

+398
-1
lines changed

8 files changed

+398
-1
lines changed

packages/core/src/blocks/QuoteBlockContent/QuoteBlockContent.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@ import {
22
createBlockSpecFromStronglyTypedTiptapNode,
33
createStronglyTypedTiptapNode,
44
} from "../../schema/index.js";
5-
import { createDefaultBlockDOMOutputSpec } from "../defaultBlockHelpers.js";
5+
import {
6+
createDefaultBlockDOMOutputSpec,
7+
mergeParagraphs,
8+
} from "../defaultBlockHelpers.js";
69
import { defaultProps } from "../defaultProps.js";
710
import { getBlockInfoFromSelection } from "../../api/getBlockInfoFromPos.js";
811
import { updateBlockCommand } from "../../api/blockManipulation/commands/updateBlock/updateBlock.js";
912
import { InputRule } from "@tiptap/core";
13+
import { DOMParser } from "prosemirror-model";
1014

1115
export const quotePropSchema = {
1216
...defaultProps,
@@ -76,6 +80,24 @@ export const QuoteBlockContent = createStronglyTypedTiptapNode({
7680
{
7781
tag: "blockquote",
7882
node: "quote",
83+
getContent: (node, schema) => {
84+
// Parse the blockquote content as inline content
85+
const element = node as HTMLElement;
86+
87+
// Clone to avoid modifying the original
88+
const clone = element.cloneNode(true) as HTMLElement;
89+
90+
// Merge multiple paragraphs into one with line breaks
91+
mergeParagraphs(clone);
92+
93+
// Parse the content directly as a paragraph to extract inline content
94+
const parser = DOMParser.fromSchema(schema);
95+
const parsed = parser.parse(clone, {
96+
topNode: schema.nodes.paragraph.create(),
97+
});
98+
99+
return parsed.content;
100+
},
79101
},
80102
];
81103
},
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
[
2+
{
3+
"children": [],
4+
"content": [
5+
{
6+
"styles": {},
7+
"text": "This is a blockquote",
8+
"type": "text",
9+
},
10+
],
11+
"id": "1",
12+
"props": {
13+
"backgroundColor": "default",
14+
"textColor": "default",
15+
},
16+
"type": "quote",
17+
},
18+
{
19+
"children": [],
20+
"content": [
21+
{
22+
"styles": {},
23+
"text": "This is not a blockquote",
24+
"type": "text",
25+
},
26+
],
27+
"id": "2",
28+
"props": {
29+
"backgroundColor": "default",
30+
"textAlignment": "left",
31+
"textColor": "default",
32+
},
33+
"type": "paragraph",
34+
},
35+
]
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
[
2+
{
3+
"children": [],
4+
"content": [
5+
{
6+
"styles": {
7+
"bold": true,
8+
},
9+
"text": "Bold",
10+
"type": "text",
11+
},
12+
{
13+
"styles": {},
14+
"text": " ",
15+
"type": "text",
16+
},
17+
{
18+
"styles": {
19+
"italic": true,
20+
},
21+
"text": "Italic",
22+
"type": "text",
23+
},
24+
{
25+
"styles": {},
26+
"text": " ",
27+
"type": "text",
28+
},
29+
{
30+
"styles": {
31+
"strike": true,
32+
},
33+
"text": "Strikethrough",
34+
"type": "text",
35+
},
36+
{
37+
"styles": {},
38+
"text": " ",
39+
"type": "text",
40+
},
41+
{
42+
"styles": {
43+
"bold": true,
44+
"italic": true,
45+
},
46+
"text": "Multiple",
47+
"type": "text",
48+
},
49+
],
50+
"id": "1",
51+
"props": {
52+
"backgroundColor": "default",
53+
"textColor": "default",
54+
},
55+
"type": "quote",
56+
},
57+
{
58+
"children": [],
59+
"content": [
60+
{
61+
"styles": {},
62+
"text": "Regular paragraph",
63+
"type": "text",
64+
},
65+
],
66+
"id": "2",
67+
"props": {
68+
"backgroundColor": "default",
69+
"textAlignment": "left",
70+
"textColor": "default",
71+
},
72+
"type": "paragraph",
73+
},
74+
]
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
[
2+
{
3+
"children": [],
4+
"content": [
5+
{
6+
"styles": {},
7+
"text": "First quote",
8+
"type": "text",
9+
},
10+
],
11+
"id": "1",
12+
"props": {
13+
"backgroundColor": "default",
14+
"textColor": "default",
15+
},
16+
"type": "quote",
17+
},
18+
{
19+
"children": [],
20+
"content": [
21+
{
22+
"styles": {},
23+
"text": "Second quote",
24+
"type": "text",
25+
},
26+
],
27+
"id": "2",
28+
"props": {
29+
"backgroundColor": "default",
30+
"textColor": "default",
31+
},
32+
"type": "quote",
33+
},
34+
{
35+
"children": [],
36+
"content": [
37+
{
38+
"styles": {},
39+
"text": "Regular paragraph",
40+
"type": "text",
41+
},
42+
],
43+
"id": "3",
44+
"props": {
45+
"backgroundColor": "default",
46+
"textAlignment": "left",
47+
"textColor": "default",
48+
},
49+
"type": "paragraph",
50+
},
51+
]
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
[
2+
{
3+
"children": [],
4+
"content": [
5+
{
6+
"styles": {},
7+
"text": "This is a blockquote",
8+
"type": "text",
9+
},
10+
],
11+
"id": "1",
12+
"props": {
13+
"backgroundColor": "default",
14+
"textColor": "default",
15+
},
16+
"type": "quote",
17+
},
18+
{
19+
"children": [],
20+
"content": [
21+
{
22+
"styles": {},
23+
"text": "This is not a blockquote",
24+
"type": "text",
25+
},
26+
],
27+
"id": "2",
28+
"props": {
29+
"backgroundColor": "default",
30+
"textAlignment": "left",
31+
"textColor": "default",
32+
},
33+
"type": "paragraph",
34+
},
35+
]
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
[
2+
{
3+
"children": [],
4+
"content": [
5+
{
6+
"styles": {
7+
"bold": true,
8+
},
9+
"text": "Bold",
10+
"type": "text",
11+
},
12+
{
13+
"styles": {},
14+
"text": " ",
15+
"type": "text",
16+
},
17+
{
18+
"styles": {
19+
"italic": true,
20+
},
21+
"text": "Italic",
22+
"type": "text",
23+
},
24+
{
25+
"styles": {},
26+
"text": " ",
27+
"type": "text",
28+
},
29+
{
30+
"styles": {
31+
"strike": true,
32+
},
33+
"text": "Strikethrough",
34+
"type": "text",
35+
},
36+
{
37+
"styles": {},
38+
"text": " ",
39+
"type": "text",
40+
},
41+
{
42+
"styles": {
43+
"bold": true,
44+
"italic": true,
45+
},
46+
"text": "Multiple",
47+
"type": "text",
48+
},
49+
],
50+
"id": "1",
51+
"props": {
52+
"backgroundColor": "default",
53+
"textColor": "default",
54+
},
55+
"type": "quote",
56+
},
57+
{
58+
"children": [],
59+
"content": [
60+
{
61+
"styles": {},
62+
"text": "Regular paragraph",
63+
"type": "text",
64+
},
65+
],
66+
"id": "2",
67+
"props": {
68+
"backgroundColor": "default",
69+
"textAlignment": "left",
70+
"textColor": "default",
71+
},
72+
"type": "paragraph",
73+
},
74+
]
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
[
2+
{
3+
"children": [],
4+
"content": [
5+
{
6+
"styles": {},
7+
"text": "First quote",
8+
"type": "text",
9+
},
10+
],
11+
"id": "1",
12+
"props": {
13+
"backgroundColor": "default",
14+
"textColor": "default",
15+
},
16+
"type": "quote",
17+
},
18+
{
19+
"children": [],
20+
"content": [
21+
{
22+
"styles": {},
23+
"text": "Second quote",
24+
"type": "text",
25+
},
26+
],
27+
"id": "2",
28+
"props": {
29+
"backgroundColor": "default",
30+
"textColor": "default",
31+
},
32+
"type": "quote",
33+
},
34+
{
35+
"children": [],
36+
"content": [
37+
{
38+
"styles": {},
39+
"text": "Regular paragraph",
40+
"type": "text",
41+
},
42+
],
43+
"id": "3",
44+
"props": {
45+
"backgroundColor": "default",
46+
"textAlignment": "left",
47+
"textColor": "default",
48+
},
49+
"type": "paragraph",
50+
},
51+
]

0 commit comments

Comments
 (0)