Skip to content

Commit 12984e2

Browse files
committed
Reusing serialize methods
1 parent cf990c2 commit 12984e2

File tree

1 file changed

+3
-27
lines changed

1 file changed

+3
-27
lines changed

src/components/SlateEditor/plugins/framedContent/SlateFramedContent.tsx

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*
77
*/
88

9-
import escapeHtml from "escape-html";
109
import { useMemo, useState } from "react";
1110
import { useTranslation } from "react-i18next";
1211
import { Editor, Element, NodeEntry, Text, Transforms } from "slate";
@@ -18,9 +17,10 @@ import { IconButton } from "@ndla/primitives";
1817
import { ContentTypeFramedContent, EmbedWrapper } from "@ndla/ui";
1918
import { FramedContentElement } from ".";
2019
import { TYPE_FRAMED_CONTENT } from "./types";
20+
import { editorValueToPlainText } from "../../../../util/articleContentConverter";
2121
import { useArticleContentType } from "../../../ContentTypeProvider";
2222
import DeleteButton from "../../../DeleteButton";
23-
import { claudeHaikuDefaults, getTextFromHTML, invokeModel } from "../../../LLM/helpers";
23+
import { claudeHaikuDefaults, invokeModel } from "../../../LLM/helpers";
2424
import MoveContentButton from "../../../MoveContentButton";
2525
import { useArticleLanguage } from "../../ArticleLanguageProvider";
2626
import { TYPE_COPYRIGHT } from "../copyright/types";
@@ -88,32 +88,8 @@ const SlateFramedContent = (props: Props) => {
8888
Transforms.insertNodes(editor, defaultCopyrightBlock(), { at: path.concat(node.children.length) });
8989
};
9090

91-
const serialize = (node: any) => {
92-
if (Text.isText(node)) {
93-
let string = escapeHtml(node.text);
94-
if (node.bold) {
95-
string = `<strong>${string}</strong>`;
96-
}
97-
return string;
98-
}
99-
100-
const children = node.children.map((n: any) => serialize(n)).join("");
101-
102-
switch (node.type) {
103-
case "quote":
104-
return `<blockquote><p>${children}</p></blockquote>`;
105-
case "paragraph":
106-
return `<p>${children}</p>`;
107-
case "link":
108-
return `<a href="${escapeHtml(node.url)}">${children}</a>`;
109-
default:
110-
return children;
111-
}
112-
};
113-
11491
const generateQuestions = async () => {
115-
const articleHTML = await serialize(editor.children[0]);
116-
const articleText = getTextFromHTML(articleHTML);
92+
const articleText = editorValueToPlainText(editor.children);
11793
if (!articleText) {
11894
console.error("No article content provided to generate meta description");
11995
return;

0 commit comments

Comments
 (0)