From 75b6ba40e970dd8d21b8d66ad08315159313ccb0 Mon Sep 17 00:00:00 2001 From: BTMuli Date: Sat, 17 Jan 2026 13:58:59 +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=EF=BC=8C=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E9=83=A8=E5=88=86=E6=95=B0=E6=8D=AE=E8=A7=A3=E6=9E=90=E5=BC=82?= =?UTF-8?q?=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/web/t-link.vue | 2 +- src/utils/toolFunc.ts | 25 ++++++++++++++----------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/components/web/t-link.vue b/src/components/web/t-link.vue index 67093cf2..3e507a77 100644 --- a/src/components/web/t-link.vue +++ b/src/components/web/t-link.vue @@ -9,7 +9,7 @@ import showHyperLink from "@comp/func/hyperlink.js"; import showSnackbar from "@comp/func/snackbar.js"; import { parseHtmlText } from "@utils/toolFunc.js"; -import { defineProps, onMounted, shallowRef } from "vue"; +import { onMounted, shallowRef } from "vue"; import { WikiHyperLinkData } from "@/data/index.js"; diff --git a/src/utils/toolFunc.ts b/src/utils/toolFunc.ts index c9da3930..35eca29d 100644 --- a/src/utils/toolFunc.ts +++ b/src/utils/toolFunc.ts @@ -190,7 +190,21 @@ export function getRandomString(length: number, type: string = "all"): string { * @returns 解析后的文本 */ export function parseHtmlText(desc: string): string { + const colorReg = /(.*?)<\/color>/g; const linkReg = /\{LINK#(.*?)}(.*?)\{\/LINK}/g; + let colorMatch = colorReg.exec(desc); + while (colorMatch !== null) { + const color = colorMatch[1]; + const text = new DOMParser().parseFromString(colorMatch[2], "text/html").body.textContent; + let title = text; + const colorLinkMatch = linkReg.exec(text); + if (colorLinkMatch !== null) title = colorLinkMatch[2]; + desc = desc.replace( + colorMatch[0], + `${text}`, + ); + colorMatch = colorReg.exec(desc); + } let linkMatch = linkReg.exec(desc); while (linkMatch !== null) { const link = linkMatch[1]; @@ -201,17 +215,6 @@ export function parseHtmlText(desc: string): string { ); linkMatch = linkReg.exec(desc); } - const colorReg = /(.*?)<\/color>/g; - let colorMatch = colorReg.exec(desc); - while (colorMatch !== null) { - const color = colorMatch[1]; - const text = new DOMParser().parseFromString(colorMatch[2], "text/html").body.textContent; - desc = desc.replace( - colorMatch[0], - `${text}`, - ); - colorMatch = colorReg.exec(desc); - } desc = desc.replace(/\\n/g, "
"); return desc; }