From 9d756b8d965160e4bca0cab17e67a955e3823a7d Mon Sep 17 00:00:00 2001 From: BTMuli Date: Sun, 2 Apr 2023 18:04:14 +0800 Subject: [PATCH] =?UTF-8?q?fix(parser):=20=E8=A7=A3=E5=86=B3=E6=A0=B7?= =?UTF-8?q?=E5=BC=8F=E4=B8=8D=E7=94=9F=E6=95=88=E9=97=AE=E9=A2=98=EF=BC=8C?= =?UTF-8?q?=E5=90=8E=E7=BB=AD=E5=BE=85=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/assets/css/anno-parser.css | 21 +++++++++++---------- src/assets/css/post-parser.css | 1 + src/plugins/Genshin/utils/annoParser.ts | 19 ++++++++++++++++++- src/views/t-anno.vue | 2 +- src/views/t-post.vue | 2 +- 5 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/assets/css/anno-parser.css b/src/assets/css/anno-parser.css index d662e71b..4c12913f 100644 --- a/src/assets/css/anno-parser.css +++ b/src/assets/css/anno-parser.css @@ -3,6 +3,7 @@ * @since Alpha v0.1.1 */ +/* todo scoped 不生效 */ .anno-body { margin: 20px auto; width: 800px; @@ -41,37 +42,37 @@ color: #00c3ff; } -.anno-content :deep(a) { +.anno-content a { color: #00c3ff; text-decoration: none; } -.anno-content :deep(span) { - color: #4b5366; -} - -.anno-content :deep(p) { +.anno-content p { line-height: 2; color: #4b5366; } -.anno-content :deep(details) { +.anno-content details { border: #35acce 2px solid; padding: 10px; border-radius: 10px; margin: 10px; } -.anno-content :deep(details) ::marker { +.anno-content details div { + margin-left: 10px; +} + +.anno-content details ::marker { color: #35acce; content: "✧"; } -.anno-content :deep(ol) { +.anno-content ol { list-style: "✧"; } -.anno-content :deep(td) { +.anno-content td { line-height: 2; padding-left: 10px; } diff --git a/src/assets/css/post-parser.css b/src/assets/css/post-parser.css index 8bce341a..0ba07afb 100644 --- a/src/assets/css/post-parser.css +++ b/src/assets/css/post-parser.css @@ -2,6 +2,7 @@ * @description 米游社解析 css * @since Alpha v0.1.1 */ +/* todo scoped 不生效 */ .mys-post-body { margin: 20px auto; width: 800px; diff --git a/src/plugins/Genshin/utils/annoParser.ts b/src/plugins/Genshin/utils/annoParser.ts index 7da2f07b..3881eed6 100644 --- a/src/plugins/Genshin/utils/annoParser.ts +++ b/src/plugins/Genshin/utils/annoParser.ts @@ -15,13 +15,30 @@ export function parseAnnoContent(data: string): string { const htmlBase = new DOMParser().parseFromString(data, "text/html"); // 遍历所有 span 标签 htmlBase.querySelectorAll("span").forEach(span => { - return (span.innerHTML = decodeRegExp(span.innerHTML)); + if (span.style.fontSize) { + span.style.fontSize = ""; + } + if (span.children.length === 0) { + return (span.innerHTML = decodeRegExp(span.innerHTML)); + } else { + span.querySelectorAll("*").forEach(child => { + if (child.children.length === 0) { + return (child.innerHTML = decodeRegExp(child.innerHTML)); + } + }); + } }); // 遍历所有 p 标签 htmlBase.querySelectorAll("p").forEach(p => { // 如果没有子元素 if (p.children.length === 0) { return (p.innerHTML = decodeRegExp(p.innerHTML)); + } else { + p.querySelectorAll("*").forEach(child => { + if (child.children.length === 0) { + return (child.innerHTML = decodeRegExp(child.innerHTML)); + } + }); } }); // 遍历所有 a 标签 diff --git a/src/views/t-anno.vue b/src/views/t-anno.vue index fef2f4a0..15be9d65 100644 --- a/src/views/t-anno.vue +++ b/src/views/t-anno.vue @@ -52,6 +52,6 @@ onMounted(async () => { }, 200); }); - diff --git a/src/views/t-post.vue b/src/views/t-post.vue index 3f08a2c7..3eb2e185 100644 --- a/src/views/t-post.vue +++ b/src/views/t-post.vue @@ -44,6 +44,6 @@ onMounted(async () => { }, 200); }); -