diff --git a/src/utils/toolFunc.ts b/src/utils/toolFunc.ts index a9b0f0b1..9c522ac9 100644 --- a/src/utils/toolFunc.ts +++ b/src/utils/toolFunc.ts @@ -220,18 +220,30 @@ export function isColorSimilar(colorBg: string, colorText: string): boolean { /** * @description 解析带样式的文本 - * @since Beta v0.3.8 + * @since Beta v0.8.0 * @param {string} desc - 带样式的文本 * @returns {string} 解析后的文本 */ export function parseHtmlText(desc: string): string { - const reg = /(.*?)<\/color>/g; - let match = reg.exec(desc); - while (match !== null) { - const color = match[1]; - const text = match[2]; - desc = desc.replace(match[0], `${text}`); - match = reg.exec(desc); + const linkReg = /\{LINK#(.*?)}(.*?)\{\/LINK}/g; + let linkMatch = linkReg.exec(desc); + while (linkMatch !== null) { + const link = linkMatch[1]; + const text = linkMatch[2]; + // TODO: 后续处理 t-link + desc = desc.replace(linkMatch[0], `${text}`); + 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;