This commit is contained in:
恍兮惚兮 2024-05-20 02:06:50 +08:00
parent b300b57e53
commit 2c0589cf3c
2 changed files with 38 additions and 28 deletions

View File

@ -2330,8 +2330,11 @@ class mdict(cishubase):
if os.path.exists(f): if os.path.exists(f):
try: try:
self.builders.append((IndexBuilder(f), f)) self.builders.append((IndexBuilder(f), f))
# print(self.builders[-1][0].get_mdd_keys())
except: except:
pass from traceback import print_exc
print_exc()
def querycomplex(self, word, index): def querycomplex(self, word, index):
# 0 严格1 前缀2 后缀3 中缀 # 0 严格1 前缀2 后缀3 中缀
@ -2379,6 +2382,7 @@ class mdict(cishubase):
items = self.parse_strings(item) items = self.parse_strings(item)
html = "" html = ""
for type_, string in items: for type_, string in items:
ishtml = False
if type_ == "1": if type_ == "1":
html += f'<font color="#FF0000" size=5>{string}</font>' html += f'<font color="#FF0000" size=5>{string}</font>'
elif type_ == "2": elif type_ == "2":
@ -2392,34 +2396,16 @@ class mdict(cishubase):
elif type_ == "5": elif type_ == "5":
html += f'<font color="#04A6B5">{string}</font>' html += f'<font color="#04A6B5">{string}</font>'
else: else:
html += item + "<br>" html += item
print("unknown", item) ishtml = True
if string.endswith("<br>") == False: # html
if (not ishtml) and not string.endswith("<br>"):
html += "<br>" html += "<br>"
return html return html
def search(self, word): def dfstyle(self):
results = [] return """
for index, f in self.builders:
if f.lower().endswith(".mdx"):
try:
keys = self.querycomplex(word, index.get_mdx_keys)
for k in keys:
results.append(self.parseashtml(index.mdx_lookup(k)[0]))
except:
pass
elif f.lower().endswith(".mdd"):
try:
keys = self.querycomplex(word, index.get_mdd_keys)
for k in keys:
results.append(self.parseashtml(index.mdd_lookup(k)[0]))
except:
pass
if len(results) == 0:
return
style = """
<style>
.mdx_btn { .mdx_btn {
font-size: 0.7em; font-size: 0.7em;
line-height: normal; line-height: normal;
@ -2460,7 +2446,31 @@ class mdict(cishubase):
.tabs ul li.tabs_active a {color:#333;} .tabs ul li.tabs_active a {color:#333;}
.tabs ul li.tabs_active a {color:#555555;} .tabs ul li.tabs_active a {color:#555555;}
.ui-tabs .ui-tabs-panel {border-width:0;display:block;} .ui-tabs .ui-tabs-panel {border-width:0;display:block;}
</style>
""" """
def search(self, word):
results = []
style = ""
for index, f in self.builders:
try:
keys = self.querycomplex(word, index.get_mdx_keys)
for k in keys:
results.append(self.parseashtml(index.mdx_lookup(k)[0]))
except:
pass
# @@@LINK=rjx0849\r\n ->跳转到mdxkey rjx0849
# <img src="/rjx0849.png" width="1080px"><br><center> <a href="entry://rjx0848">
# /rjx0849.png->mddkey \\rjx0849.png entry://rjx0848->跳转到mdxkey rjx0849
# 太麻烦,不搞了。
base, ext = os.path.splitext(f)
css = base + ".css"
if os.path.exists(css):
with open(css, "r", encoding="utf8") as ff:
style1 = ff.read()
else:
style1 = self.dfstyle()
style += f"<style>{style1}</style>"
if len(results) == 0:
return
return style + "".join(results) return style + "".join(results)

View File

@ -946,7 +946,7 @@
"name": "路径", "name": "路径",
"dir": false, "dir": false,
"multi": true, "multi": true,
"filter": "*.mdx;*.mdd" "filter": "*.mdx"
}, },
"ambiguity": { "ambiguity": {
"type": "intspin", "type": "intspin",