diff --git a/packages/core/src/api/parsers/html/__snapshots__/paste/parse-image-in-paragraph.json b/packages/core/src/api/parsers/html/__snapshots__/paste/parse-image-in-paragraph.json new file mode 100644 index 0000000000..1a581a00c3 --- /dev/null +++ b/packages/core/src/api/parsers/html/__snapshots__/paste/parse-image-in-paragraph.json @@ -0,0 +1,16 @@ +[ + { + "id": "1", + "type": "image", + "props": { + "backgroundColor": "default", + "textAlignment": "left", + "name": "", + "url": "exampleURL", + "caption": "", + "showPreview": true, + "previewWidth": 512 + }, + "children": [] + } +] \ No newline at end of file diff --git a/packages/core/src/api/parsers/html/parseHTML.test.ts b/packages/core/src/api/parsers/html/parseHTML.test.ts index 36be3e30ea..3f1c84bcf1 100644 --- a/packages/core/src/api/parsers/html/parseHTML.test.ts +++ b/packages/core/src/api/parsers/html/parseHTML.test.ts @@ -295,6 +295,14 @@ describe("Parse HTML", () => { await parseHTMLAndCompareSnapshots(html, "parse-two-divs"); }); + it("Parse image in paragraph", async () => { + const html = `

+ +

`; + + await parseHTMLAndCompareSnapshots(html, "parse-image-in-paragraph"); + }); + it("Parse fake image caption", async () => { const html = `
diff --git a/packages/core/src/blocks/ParagraphBlockContent/ParagraphBlockContent.ts b/packages/core/src/blocks/ParagraphBlockContent/ParagraphBlockContent.ts index d9186f8e1c..1e401b2dce 100644 --- a/packages/core/src/blocks/ParagraphBlockContent/ParagraphBlockContent.ts +++ b/packages/core/src/blocks/ParagraphBlockContent/ParagraphBlockContent.ts @@ -41,6 +41,13 @@ export const ParagraphBlockContent = createStronglyTypedTiptapNode({ { tag: "p", priority: 200, + getAttrs: (element) => { + if (typeof element === "string" || !element.textContent?.trim()) { + return false; + } + + return {}; + }, node: "paragraph", }, ]; diff --git a/packages/core/src/blocks/TableBlockContent/TableBlockContent.ts b/packages/core/src/blocks/TableBlockContent/TableBlockContent.ts index d2bb8c0217..e47a62b2d4 100644 --- a/packages/core/src/blocks/TableBlockContent/TableBlockContent.ts +++ b/packages/core/src/blocks/TableBlockContent/TableBlockContent.ts @@ -45,7 +45,29 @@ const TableParagraph = Node.create({ content: "inline*", parseHTML() { - return [{ tag: "p" }]; + return [ + { tag: "td" }, + { + tag: "p", + getAttrs: (element) => { + if (typeof element === "string" || !element.textContent) { + return false; + } + + const parent = element.parentElement; + + if (parent === null) { + return false; + } + + if (parent.tagName === "TD") { + return {}; + } + + return false; + }, + }, + ]; }, renderHTML({ HTMLAttributes }) {