Skip to content

Commit 80f10c4

Browse files
committed
Reusing serialize methods
1 parent cf990c2 commit 80f10c4

File tree

1 file changed

+3
-26
lines changed

1 file changed

+3
-26
lines changed

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

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ import { IconButton } from "@ndla/primitives";
1818
import { ContentTypeFramedContent, EmbedWrapper } from "@ndla/ui";
1919
import { FramedContentElement } from ".";
2020
import { TYPE_FRAMED_CONTENT } from "./types";
21+
import { editorValueToPlainText } from "../../../../util/articleContentConverter";
2122
import { useArticleContentType } from "../../../ContentTypeProvider";
2223
import DeleteButton from "../../../DeleteButton";
23-
import { claudeHaikuDefaults, getTextFromHTML, invokeModel } from "../../../LLM/helpers";
24+
import { claudeHaikuDefaults, invokeModel } from "../../../LLM/helpers";
2425
import MoveContentButton from "../../../MoveContentButton";
2526
import { useArticleLanguage } from "../../ArticleLanguageProvider";
2627
import { TYPE_COPYRIGHT } from "../copyright/types";
@@ -88,32 +89,8 @@ const SlateFramedContent = (props: Props) => {
8889
Transforms.insertNodes(editor, defaultCopyrightBlock(), { at: path.concat(node.children.length) });
8990
};
9091

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-
11492
const generateQuestions = async () => {
115-
const articleHTML = await serialize(editor.children[0]);
116-
const articleText = getTextFromHTML(articleHTML);
93+
const articleText = editorValueToPlainText(editor.children);
11794
if (!articleText) {
11895
console.error("No article content provided to generate meta description");
11996
return;

0 commit comments

Comments
 (0)