From 2c0589cf3c6efa1694831bfb6c6ec279b5e918cf 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: Mon, 20 May 2024 02:06:50 +0800 Subject: [PATCH] fix --- LunaTranslator/LunaTranslator/cishu/mdict.py | 64 +++++++++++-------- .../files/defaultconfig/config.json | 2 +- 2 files changed, 38 insertions(+), 28 deletions(-) diff --git a/LunaTranslator/LunaTranslator/cishu/mdict.py b/LunaTranslator/LunaTranslator/cishu/mdict.py index ed857e10..2938b0a9 100644 --- a/LunaTranslator/LunaTranslator/cishu/mdict.py +++ b/LunaTranslator/LunaTranslator/cishu/mdict.py @@ -2330,8 +2330,11 @@ class mdict(cishubase): if os.path.exists(f): try: self.builders.append((IndexBuilder(f), f)) + # print(self.builders[-1][0].get_mdd_keys()) except: - pass + from traceback import print_exc + + print_exc() def querycomplex(self, word, index): # 0 严格,1 前缀,2 后缀,3 中缀 @@ -2379,6 +2382,7 @@ class mdict(cishubase): items = self.parse_strings(item) html = "" for type_, string in items: + ishtml = False if type_ == "1": html += f'{string}' elif type_ == "2": @@ -2392,34 +2396,16 @@ class mdict(cishubase): elif type_ == "5": html += f'{string}' else: - html += item + "
" - print("unknown", item) - if string.endswith("
") == False: + html += item + ishtml = True + # html + + if (not ishtml) and not string.endswith("
"): html += "
" return html - def search(self, word): - results = [] - 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 = """ - """ + 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 + #
+ # /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"" + if len(results) == 0: + return return style + "".join(results) diff --git a/LunaTranslator/files/defaultconfig/config.json b/LunaTranslator/files/defaultconfig/config.json index 88175307..1523ef40 100644 --- a/LunaTranslator/files/defaultconfig/config.json +++ b/LunaTranslator/files/defaultconfig/config.json @@ -946,7 +946,7 @@ "name": "路径", "dir": false, "multi": true, - "filter": "*.mdx;*.mdd" + "filter": "*.mdx" }, "ambiguity": { "type": "intspin",