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; }