Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[
{
"id": "1",
"type": "image",
"props": {
"backgroundColor": "default",
"textAlignment": "left",
"name": "",
"url": "exampleURL",
"caption": "",
"showPreview": true,
"previewWidth": 512
},
"children": []
}
]
8 changes: 8 additions & 0 deletions packages/core/src/api/parsers/html/parseHTML.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,14 @@ describe("Parse HTML", () => {
await parseHTMLAndCompareSnapshots(html, "parse-two-divs");
});

it("Parse image in paragraph", async () => {
const html = `<p>
<img src="exampleURL">
</p>`;

await parseHTMLAndCompareSnapshots(html, "parse-image-in-paragraph");
});

it("Parse fake image caption", async () => {
const html = `<div>
<img src="exampleURL">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
];
Expand Down
24 changes: 23 additions & 1 deletion packages/core/src/blocks/TableBlockContent/TableBlockContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) {
Expand Down