From 3e65ad1fe082fd748ccc5c2c75f5175093093787 Mon Sep 17 00:00:00 2001 From: "St.Huang" Date: Sun, 19 Aug 2018 12:01:41 +0800 Subject: [PATCH] fix #35 --- addons/fastwq/service/base.py | 28 ++++++++++++++++++---------- addons21/fastwq/service/base.py | 28 ++++++++++++++++++---------- 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/addons/fastwq/service/base.py b/addons/fastwq/service/base.py index 012189b..2b8e02d 100644 --- a/addons/fastwq/service/base.py +++ b/addons/fastwq/service/base.py @@ -549,6 +549,7 @@ class MdxService(LocalService): self.cache = defaultdict(str) self.html_cache = defaultdict(str) self.query_interval = 0.01 + self.word_links = [] self.styles = [] if MdxService.check(self.dict_path): self.builder = self._get_builer(dict_path, service_wrap(MdxBuilder, dict_path)) @@ -620,16 +621,23 @@ class MdxService(LocalService): default get html from mdx interface ''' if not self.cache[self.word]: - html = '' - result = self.builder.mdx_lookup(self.word, ignorecase=True) # self.word: unicode - if result: - if result[0].upper().find(u"@@@LINK=") > -1: - # redirect to a new word behind the equal symol. - self.word = result[0][len(u"@@@LINK="):].strip() - return self.get_default_html() - else: - html = self.adapt_to_anki(result[0]) - self.cache[self.word] = html + self.word_links = [self.word.upper()] + self._get_default_html() + return self.cache[self.word] + + def _get_default_html(self): + html = u'' + result = self.builder.mdx_lookup(self.word, ignorecase=True) # self.word: unicode + if result: + if result[0].upper().find(u"@@@LINK=") > -1: + # redirect to a new word behind the equal symol. + word = result[0][len(u"@@@LINK="):].strip() + if not word.upper() in self.word_links: + self.word_links.append(word.upper()) + self.word = word + return self._get_default_html() + html = self.adapt_to_anki(result[0]) + self.cache[self.word] = html return self.cache[self.word] def adapt_to_anki(self, html): diff --git a/addons21/fastwq/service/base.py b/addons21/fastwq/service/base.py index 27210bf..ff6456c 100644 --- a/addons21/fastwq/service/base.py +++ b/addons21/fastwq/service/base.py @@ -555,6 +555,7 @@ class MdxService(LocalService): self.cache = defaultdict(str) self.html_cache = defaultdict(str) self.query_interval = 0.01 + self.word_links = [] self.styles = [] if MdxService.check(self.dict_path): self.builder = self._get_builer(dict_path, service_wrap(MdxBuilder, dict_path)) @@ -626,16 +627,23 @@ class MdxService(LocalService): default get html from mdx interface ''' if not self.cache[self.word]: - html = '' - result = self.builder.mdx_lookup(self.word, ignorecase=True) # self.word: unicode - if result: - if result[0].upper().find(u"@@@LINK=") > -1: - # redirect to a new word behind the equal symol. - self.word = result[0][len(u"@@@LINK="):].strip() - return self.get_default_html() - else: - html = self.adapt_to_anki(result[0]) - self.cache[self.word] = html + self.word_links = [self.word.upper()] + self._get_default_html() + return self.cache[self.word] + + def _get_default_html(self): + html = u'' + result = self.builder.mdx_lookup(self.word, ignorecase=True) # self.word: unicode + if result: + if result[0].upper().find(u"@@@LINK=") > -1: + # redirect to a new word behind the equal symol. + word = result[0][len(u"@@@LINK="):].strip() + if not word.upper() in self.word_links: + self.word_links.append(word.upper()) + self.word = word + return self._get_default_html() + html = self.adapt_to_anki(result[0]) + self.cache[self.word] = html return self.cache[self.word] def adapt_to_anki(self, html):