diff --git a/app/components/Editor.tsx b/app/components/Editor.tsx index c80702d38f..c4d7ab92d6 100644 --- a/app/components/Editor.tsx +++ b/app/components/Editor.tsx @@ -6,7 +6,9 @@ import * as React from "react"; import { mergeRefs } from "react-merge-refs"; import { Optional } from "utility-types"; import insertFiles from "@shared/editor/commands/insertFiles"; +import EditorContainer from "@shared/editor/components/Styles"; import { AttachmentPreset } from "@shared/types"; +import { ProsemirrorHelper } from "@shared/utils/ProsemirrorHelper"; import { getDataTransferFiles } from "@shared/utils/files"; import { AttachmentValidation } from "@shared/validations"; import ClickablePadding from "~/components/ClickablePadding"; @@ -183,6 +185,23 @@ function Editor(props: Props, ref: React.RefObject | null) { [updateComments] ); + const paragraphs = + props.readOnly && typeof props.value === "object" + ? ProsemirrorHelper.getPlainParagrahs(props.value) + : undefined; + + console.log({ paragraphs }); + + if (paragraphs) { + return ( + + {paragraphs.map((paragraph, index) => ( +

{paragraph.content.map((content) => content.text)}

+ ))} +
+ ); + } + return ( <> diff --git a/shared/utils/ProsemirrorHelper.ts b/shared/utils/ProsemirrorHelper.ts index ea2e2c554d..a731127cc5 100644 --- a/shared/utils/ProsemirrorHelper.ts +++ b/shared/utils/ProsemirrorHelper.ts @@ -346,4 +346,26 @@ export class ProsemirrorHelper { return replace(data); } + + /** + * Returns the paragraphs from the data if there are only plain paragraphs + * without any formatting. Otherwise returns undefined. + * + * @param data The ProsemirrorData object + * @returns An array of paragraph nodes or undefined + */ + static getPlainParagrahs(data: ProsemirrorData) { + const paragraphs = []; + for (const node of data.content) { + if ( + node.type === "paragraph" && + !node.content.some((item) => item.marks) + ) { + paragraphs.push(node); + } else { + return undefined; + } + } + return paragraphs; + } }