Skip to content

Commit

Permalink
fix an encoding bug in lib mdict #48
Browse files Browse the repository at this point in the history
  • Loading branch information
finalion committed Jul 11, 2017
1 parent 21166dd commit 73f5d43
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,5 @@ dicts/
*wqcfg
.vscode/
test/
anki.zip
anki.zip
*wqcfg.json
13 changes: 9 additions & 4 deletions wquery/libs/mdict/mdict_query.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-


from readmdict import MDX, MDD
from struct import pack, unpack
from io import BytesIO
Expand All @@ -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
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion wquery/service/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def adapt_to_anki(self, html):
msrc = re.findall(r'<img.*?src="([\w\./]\S+?)".*?>', 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])
Expand Down

0 comments on commit 73f5d43

Please sign in to comment.