From 6f497fa489ffb4e5faff8f6b72d48b1141d065c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?= <101191390+HIllya51@users.noreply.github.com> Date: Thu, 30 May 2024 14:24:31 +0800 Subject: [PATCH] css --- LunaTranslator/LunaTranslator/cishu/mdict.py | 38 ++++++++++++++++---- LunaTranslator/LunaTranslator/keeprefs.py | 3 +- LunaTranslator/files/anki/back.html | 4 +-- LunaTranslator/files/anki/style.css | 3 -- LunaTranslator/requirements.txt | 4 ++- LunaTranslator/requirements_qt6.txt | 4 ++- 6 files changed, 41 insertions(+), 15 deletions(-) diff --git a/LunaTranslator/LunaTranslator/cishu/mdict.py b/LunaTranslator/LunaTranslator/cishu/mdict.py index 56ebc026..6e85e9b5 100644 --- a/LunaTranslator/LunaTranslator/cishu/mdict.py +++ b/LunaTranslator/LunaTranslator/cishu/mdict.py @@ -2483,14 +2483,14 @@ class mdict(cishubase): return "application/octet-stream" def repairtarget(self, index, base, html_content): - import base64 + import base64, uuid src_pattern = r'src="([^"]+)"' href_pattern = r'href="([^"]+)"' src_matches = re.findall(src_pattern, html_content) href_matches = re.findall(href_pattern, html_content) - + divid = "luna_internal_" + str(uuid.uuid4()) for url in src_matches + href_matches: oked = False iscss = url.lower().endswith(".css") @@ -2537,6 +2537,34 @@ class mdict(cishubase): except: file_content = None if file_content: + if iscss: + try: + import sass + + css = file_content.decode("utf8") + css = sass.compile(string=(f"#{divid} {{ {css} }}")) + csss = css.split("\n") + i = 0 + while i < len(csss): + css = csss[i] + if css.endswith(" body {"): + csss[i] = css[: -len(" body {")] + "{" + elif css == "@font-face {": + csss[i + 1] = "" + for j in range(i + 2, len(csss)): + if csss[j].endswith("} }"): + i = j + csss[j] = csss[j][:-1] + break + i += 1 + css = "\n".join(csss) + file_content = css.encode("utf8") + # print(css) + except: + from traceback import print_exc + + print_exc() + base64_content = base64.b64encode(file_content).decode("utf-8") if iscss: html_content = html_content.replace( @@ -2548,7 +2576,7 @@ class mdict(cishubase): ) elif not oked: print(url) - return html_content + return f'
{html_content}
' def search(self, word): allres = [] @@ -2644,12 +2672,10 @@ function onclickbtn_mdict_internal(_id) { {commonstyle}
-
{''.join(btns)} -
-
+
{''.join(contents)}
diff --git a/LunaTranslator/LunaTranslator/keeprefs.py b/LunaTranslator/LunaTranslator/keeprefs.py index 6f40d2b1..0c44cca4 100644 --- a/LunaTranslator/LunaTranslator/keeprefs.py +++ b/LunaTranslator/LunaTranslator/keeprefs.py @@ -9,4 +9,5 @@ from html.parser import HTMLParser from importlib import resources from distutils.version import StrictVersion from dataclasses import dataclass -import colorsys \ No newline at end of file +import colorsys +import sass \ No newline at end of file diff --git a/LunaTranslator/files/anki/back.html b/LunaTranslator/files/anki/back.html index d69d42c9..73c36704 100644 --- a/LunaTranslator/files/anki/back.html +++ b/LunaTranslator/files/anki/back.html @@ -40,9 +40,7 @@
-
-
-
+
diff --git a/LunaTranslator/files/anki/style.css b/LunaTranslator/files/anki/style.css index ede2f7bd..3bf7c65f 100644 --- a/LunaTranslator/files/anki/style.css +++ b/LunaTranslator/files/anki/style.css @@ -34,9 +34,6 @@ cursor: pointer; } -.tab-widget .tab-buttons { - display: flex; -} .tab-widget .tab-button { padding: 10px 20px; diff --git a/LunaTranslator/requirements.txt b/LunaTranslator/requirements.txt index a97c26b7..8a6c5a9b 100644 --- a/LunaTranslator/requirements.txt +++ b/LunaTranslator/requirements.txt @@ -1,5 +1,7 @@ +#python3.7.9 + PyQt5==5.15.10 PyQt5-Qt5==5.15.2 webviewpy==1.2.0 pefile -#python3.7.9 \ No newline at end of file +libsass \ No newline at end of file diff --git a/LunaTranslator/requirements_qt6.txt b/LunaTranslator/requirements_qt6.txt index 7814fb4c..8e92c071 100644 --- a/LunaTranslator/requirements_qt6.txt +++ b/LunaTranslator/requirements_qt6.txt @@ -1,5 +1,7 @@ +#python3.11.8 + PyQt6==6.7.0 PyQt6-Qt6==6.7.0 webviewpy==1.2.0 pefile -#python3.11.8 \ No newline at end of file +libsass \ No newline at end of file