@@ -18,9 +18,10 @@ import { IconButton } from "@ndla/primitives";
18
18
import { ContentTypeFramedContent , EmbedWrapper } from "@ndla/ui" ;
19
19
import { FramedContentElement } from "." ;
20
20
import { TYPE_FRAMED_CONTENT } from "./types" ;
21
+ import { editorValueToPlainText } from "../../../../util/articleContentConverter" ;
21
22
import { useArticleContentType } from "../../../ContentTypeProvider" ;
22
23
import DeleteButton from "../../../DeleteButton" ;
23
- import { claudeHaikuDefaults , getTextFromHTML , invokeModel } from "../../../LLM/helpers" ;
24
+ import { claudeHaikuDefaults , invokeModel } from "../../../LLM/helpers" ;
24
25
import MoveContentButton from "../../../MoveContentButton" ;
25
26
import { useArticleLanguage } from "../../ArticleLanguageProvider" ;
26
27
import { TYPE_COPYRIGHT } from "../copyright/types" ;
@@ -88,32 +89,8 @@ const SlateFramedContent = (props: Props) => {
88
89
Transforms . insertNodes ( editor , defaultCopyrightBlock ( ) , { at : path . concat ( node . children . length ) } ) ;
89
90
} ;
90
91
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
-
114
92
const generateQuestions = async ( ) => {
115
- const articleHTML = await serialize ( editor . children [ 0 ] ) ;
116
- const articleText = getTextFromHTML ( articleHTML ) ;
93
+ const articleText = editorValueToPlainText ( editor . children ) ;
117
94
if ( ! articleText ) {
118
95
console . error ( "No article content provided to generate meta description" ) ;
119
96
return ;
0 commit comments