This commit is contained in:
Tom Moor committed 2025-03-16 09:31:24 -04:00
1 parent f2362cddba
commit d7565ffc1c
4 files changed
+168 -35

No files matched your search

+128
View File
@@ -1,3 +1,4 @@
import { ProsemirrorData } from "../types";
import { CommentMark, ProsemirrorHelper } from "./ProsemirrorHelper";
describe("ProsemirrorHelper", () => {
@@ -87,4 +88,131 @@ describe("ProsemirrorHelper", () => {
expect(returnedAnchorText).toBeUndefined();
});
});
describe("getPlainParagrahs", () => {
it("should return an array of plain paragraphs", async () => {
const data = {
type: "doc",
content: [
{
type: "paragraph",
content: [
{
type: "text",
text: "some content in a paragraph",
},
],
},
{
type: "paragraph",
content: [
{
type: "text",
text: "some content in another paragraph",
},
],
},
],
} as ProsemirrorData;
const paragraphs = ProsemirrorHelper.getPlainParagrahs(data);
expect(paragraphs).toEqual([
{
type: "paragraph",
content: [
{
type: "text",
text: "some content in a paragraph",
},
],
},
{
type: "paragraph",
content: [
{
type: "text",
text: "some content in another paragraph",
},
],
},
]);
});
it("should return undefined when data contains inline nodes", async () => {
const data = {
type: "doc",
content: [
{
type: "paragraph",
content: [
{
type: "text",
text: "some content in a paragraph",
},
{
type: "emoji",
attrs: {
"data-name": "😆",
},
},
],
},
],
} as ProsemirrorData;
const paragraphs = ProsemirrorHelper.getPlainParagrahs(data);
expect(paragraphs).toBeUndefined();
});
it("should return undefined when data contains block nodes", async () => {
const data = {
type: "doc",
content: [
{
type: "blockquote",
content: [
{
type: "paragraph",
content: [
{
type: "text",
text: "some content in a paragraph",
},
],
},
],
},
],
} as ProsemirrorData;
const paragraphs = ProsemirrorHelper.getPlainParagrahs(data);
expect(paragraphs).toBeUndefined();
});
it("should return undefined when data contains marks", async () => {
const data = {
type: "doc",
content: [
{
type: "paragraph",
content: [
{
type: "text",
text: "some content in a paragraph",
marks: [
{
type: "bold",
},
],
},
],
},
],
} as ProsemirrorData;
const paragraphs = ProsemirrorHelper.getPlainParagrahs(data);
expect(paragraphs).toBeUndefined();
});
});
});
+4 -1
View File
@@ -359,7 +359,10 @@ export class ProsemirrorHelper {
for (const node of data.content) {
if (
node.type === "paragraph" &&
!node.content.some((item) => item.marks)
!node.content.some(
(item) =>
item.type !== "text" || (item.marks && item.marks.length > 0)
)
) {
paragraphs.push(node);
} else {