From e7b176f9f479231df7b50699441703b866108321 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9B=AE=E6=A3=83?= Date: Mon, 2 Sep 2024 13:30:27 +0800 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E8=A7=A3=E6=9E=90=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/post/tp-parser.vue | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/components/post/tp-parser.vue b/src/components/post/tp-parser.vue index d6426ace..fce49f43 100644 --- a/src/components/post/tp-parser.vue +++ b/src/components/post/tp-parser.vue @@ -54,9 +54,26 @@ function getParsedData(data: TGApp.Plugins.Mys.SctPost.Base[]): TGApp.Plugins.My continue; } const parsedText = getParsedText(tp); - for (const text of parsedText) { - child.push(text); + let check = 0; + for (let i = 0; i < parsedText.length; i++) { + const text = parsedText[i]; + child.push(parsedText[i]); if (text.insert === "\n") { + cur = { + insert: "", + attributes: text.attributes, + children: child, + }; + res.push(cur); + check += child.length; + child = []; + } + if (i === parsedText.length - 1 && check !== parsedText.length) { + if (child.length === 1) { + res.push(child[0]); + child = []; + continue; + } cur = { insert: "", attributes: text.attributes, @@ -66,16 +83,6 @@ function getParsedData(data: TGApp.Plugins.Mys.SctPost.Base[]): TGApp.Plugins.My child = []; } } - // 可能没有换行符,导致res为空 - if (res.length === 0) { - cur = { - insert: "", - attributes: tp.attributes, - children: child, - }; - res.push(cur); - child = []; - } } return res; }