This commit is contained in:
恍兮惚兮 2024-05-30 14:24:31 +08:00
parent c1110822cb
commit 6f497fa489
6 changed files with 41 additions and 15 deletions

View File

@ -2483,14 +2483,14 @@ class mdict(cishubase):
return "application/octet-stream" return "application/octet-stream"
def repairtarget(self, index, base, html_content): def repairtarget(self, index, base, html_content):
import base64 import base64, uuid
src_pattern = r'src="([^"]+)"' src_pattern = r'src="([^"]+)"'
href_pattern = r'href="([^"]+)"' href_pattern = r'href="([^"]+)"'
src_matches = re.findall(src_pattern, html_content) src_matches = re.findall(src_pattern, html_content)
href_matches = re.findall(href_pattern, html_content) href_matches = re.findall(href_pattern, html_content)
divid = "luna_internal_" + str(uuid.uuid4())
for url in src_matches + href_matches: for url in src_matches + href_matches:
oked = False oked = False
iscss = url.lower().endswith(".css") iscss = url.lower().endswith(".css")
@ -2537,6 +2537,34 @@ class mdict(cishubase):
except: except:
file_content = None file_content = None
if file_content: 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") base64_content = base64.b64encode(file_content).decode("utf-8")
if iscss: if iscss:
html_content = html_content.replace( html_content = html_content.replace(
@ -2548,7 +2576,7 @@ class mdict(cishubase):
) )
elif not oked: elif not oked:
print(url) print(url)
return html_content return f'<div id="{divid}">{html_content}</div>'
def search(self, word): def search(self, word):
allres = [] allres = []
@ -2644,12 +2672,10 @@ function onclickbtn_mdict_internal(_id) {
{commonstyle} {commonstyle}
<div class="tab-widget_mdict_internal"> <div class="tab-widget_mdict_internal">
<div class="centerdiv_mdict_internal"> <div class="centerdiv_mdict_internal">
<div class="tab-buttons_mdict_internal" id="tab_buttons_mdict_internal">
{''.join(btns)} {''.join(btns)}
</div>
</div> </div>
<div> <div>
<div class="tab-content_mdict_internal" id="tab_contents_mdict_internal"> <div class="tab-content_mdict_internal">
{''.join(contents)} {''.join(contents)}
</div> </div>
</div> </div>

View File

@ -10,3 +10,4 @@ from importlib import resources
from distutils.version import StrictVersion from distutils.version import StrictVersion
from dataclasses import dataclass from dataclasses import dataclass
import colorsys import colorsys
import sass

View File

@ -40,9 +40,7 @@
</div> </div>
<div class="tab-widget"> <div class="tab-widget">
<div class="centerdiv"> <div class="centerdiv" id="tab_buttons">
<div class="tab-buttons" id="tab_buttons">
</div>
</div> </div>
<div class="centerdiv"> <div class="centerdiv">
<div class="tab-content" id="tab_contents"> <div class="tab-content" id="tab_contents">

View File

@ -34,9 +34,6 @@
cursor: pointer; cursor: pointer;
} }
.tab-widget .tab-buttons {
display: flex;
}
.tab-widget .tab-button { .tab-widget .tab-button {
padding: 10px 20px; padding: 10px 20px;

View File

@ -1,5 +1,7 @@
#python3.7.9
PyQt5==5.15.10 PyQt5==5.15.10
PyQt5-Qt5==5.15.2 PyQt5-Qt5==5.15.2
webviewpy==1.2.0 webviewpy==1.2.0
pefile pefile
#python3.7.9 libsass

View File

@ -1,5 +1,7 @@
#python3.11.8
PyQt6==6.7.0 PyQt6==6.7.0
PyQt6-Qt6==6.7.0 PyQt6-Qt6==6.7.0
webviewpy==1.2.0 webviewpy==1.2.0
pefile pefile
#python3.11.8 libsass