From 73f5d43301686bf6318fc799f04a0daeb6e01ce2 Mon Sep 17 00:00:00 2001 From: vleon Date: Tue, 11 Jul 2017 21:30:07 +0300 Subject: [PATCH] fix an encoding bug in lib mdict #48 --- .gitignore | 3 ++- wquery/libs/mdict/mdict_query.py | 13 +++++++++---- wquery/service/base.py | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 77257b0..8b6a5e8 100644 --- a/.gitignore +++ b/.gitignore @@ -95,4 +95,5 @@ dicts/ *wqcfg .vscode/ test/ -anki.zip \ No newline at end of file +anki.zip +*wqcfg.json \ No newline at end of file diff --git a/wquery/libs/mdict/mdict_query.py b/wquery/libs/mdict/mdict_query.py index 6d54f46..7798a3e 100644 --- a/wquery/libs/mdict/mdict_query.py +++ b/wquery/libs/mdict/mdict_query.py @@ -1,6 +1,4 @@ # -*- coding: utf-8 -*- - - from readmdict import MDX, MDD from struct import pack, unpack from io import BytesIO @@ -9,6 +7,7 @@ import os import sqlite3 import json +from aqt.utils import showInfo, showText, tooltip # zlib compression is used for engine version >=2.0 import zlib @@ -119,10 +118,16 @@ def _replace_stylesheet(self, txt): for j, p in enumerate(txt_list[1:]): style = self._stylesheet[txt_tag[j][1:-1]] if p and p[-1] == '\n': + # showInfo('txt_styled: ' + repr(txt_styled)) + # showInfo('style[0]: ' + repr(style[0])) + # showInfo('p:' + repr(p.rstrip())) + # showInfo('style[1]:' + repr(style[1])) txt_styled = txt_styled + \ - style[0] + p.rstrip() + style[1] + '\r\n' + style[0].encode('utf-8') + p.rstrip() + \ + style[1].encode('utf-8') + '\r\n' else: - txt_styled = txt_styled + style[0] + p + style[1] + txt_styled = txt_styled + \ + style[0].encode('utf-8') + p + style[1].encode('utf-8') return txt_styled def _make_mdx_index(self, db_name): diff --git a/wquery/service/base.py b/wquery/service/base.py index b3f4b06..7c0610d 100644 --- a/wquery/service/base.py +++ b/wquery/service/base.py @@ -307,7 +307,7 @@ def adapt_to_anki(self, html): msrc = re.findall(r'', html) media_files_set.update(set(msrc)) msound = re.findall(r'href="sound:(.*?\.(?:mp3|wav))"', html) - if config.export_media(): + if config.export_media: media_files_set.update(set(msound)) for each in media_files_set: html = html.replace(each, u'_' + each.split('/')[-1])