@@ -37,9 +37,10 @@ function formatDate(date: Date): string {
3737 return `${ d . getFullYear ( ) } -${ String ( d . getMonth ( ) + 1 ) . padStart ( 2 , '0' ) } -${ String ( d . getDate ( ) ) . padStart ( 2 , '0' ) } ` ;
3838}
3939
40- function stripHtml ( html : string ) : string {
40+ /** 从 TipTap JSON 或纯 HTML 中提取纯文本 */
41+ function extractPlainText ( content : string ) : string {
4142 try {
42- const json = JSON . parse ( html ) ;
43+ const json = JSON . parse ( content ) ;
4344 if ( json ?. content ) {
4445 const extract = ( nodes : unknown [ ] ) : string => {
4546 let text = '' ;
@@ -50,14 +51,19 @@ function stripHtml(html: string): string {
5051 }
5152 return text ;
5253 } ;
53- return extract ( json . content ) . slice ( 0 , 120 ) ;
54+ return extract ( json . content ) ;
5455 }
5556 return '' ;
5657 } catch {
57- return html . slice ( 0 , 120 ) ;
58+ return content ;
5859 }
5960}
6061
62+ /** 列表预览用:截断至 120 字符 */
63+ function stripHtml ( html : string ) : string {
64+ return extractPlainText ( html ) . slice ( 0 , 120 ) ;
65+ }
66+
6167/* ── 动画 variants ── */
6268const listVariants = {
6369 hidden : { } ,
@@ -241,7 +247,7 @@ export default function NotesPage() {
241247 case 'export' : handleExportNote ( noteCtx ) ; break ;
242248 case 'delete' : handleDeleteNote ( noteCtx . id ! ) ; break ;
243249 case 'ai-summary' : {
244- const text = stripHtml ( noteCtx . content ) ;
250+ const text = extractPlainText ( noteCtx . content ) ;
245251 if ( text . length < 10 ) { toast ( { type : 'warning' , message : '笔记内容太少,无法生成摘要' } ) ; break ; }
246252 toast ( { type : 'info' , message : 'AI 正在生成摘要...' } ) ;
247253 try {
@@ -252,7 +258,7 @@ export default function NotesPage() {
252258 break ;
253259 }
254260 case 'ai-flashcard' : {
255- const text = stripHtml ( noteCtx . content ) ;
261+ const text = extractPlainText ( noteCtx . content ) ;
256262 if ( text . length < 20 ) { toast ( { type : 'warning' , message : '笔记内容太少,无法生成闪卡' } ) ; break ; }
257263 toast ( { type : 'info' , message : 'AI 正在生成闪卡...' } ) ;
258264 try {
0 commit comments