writemdict
writemdict copied to clipboard
Eudic doesn't load CSS and JS files from .mdd file
Eudic (Android app) doesn't load CSS and JS files from mdd file packaged by writemdict. Other resources in mdd file, like images and sounds, work well. Is this issue related to dictionary encryption and registration?
Hope you can give me some advice! Thanks!
Thanks for the report! My own research into the mdd files is somewhat hampered because I don't have many examples of mdd files to begin with. Do you have an example of an mdd file that Eudic is able to read? If so, that would help me figure out what the problem is.
Here is an example, which actually contains the mdd file where I would like to substitue these JS and CSS files. Access code: uj5v
I tried, and I cannot reproduce the issue. I wrote a small test dictionary, and the CSS style appears to load correct with 欧路词典 on Android.
The code I used to create it was this:
from __future__ import unicode_literals, print_function
from writemdict import MDictWriter
outfile = open("issue5_test.mdx", "wb")
d = {
"test":"<link href=\"teststyle.css\" rel=\"stylesheet\" type=\"text/css\" /><span>Definition</span>",
}
writer = MDictWriter(d, "Issue #5 test", "description")
writer.write(outfile)
outfile.close()
outfilemdd = open("issue5_test.mdd", "wb")
d = {"\\teststyle.css": "\nspan { color: #ff0000; font-style: italic; }\n".encode("ascii")}
writer = MDictWriter(d, "MDD", "MDD Description", is_mdd=True)
writer.write(outfilemdd)
outfilemdd.close()
Does this solve the issue for you?
All I want to do is substitute old css/js files in mdd file in previous example link. I first unpack mdd file using xwang's readmdict.py
with python readmdict.py -x oald8.mdx
, resulting in a data
directory. After replacing old css/js files, I pack mdd file using the following code, which Eudic refuses to load correctly.
from __future__ import unicode_literals, print_function
import os
from writemdict import MDictWriter
data_dir = 'data'
mdd_file = 'oald8_new.mdd'
def mdd_data_from_dir(directory):
"Return mdd dict with contents from `directory`"
directory = directory.rstrip('/')
l = len(directory)
paths = []
for dir, subdirs, files in os.walk(directory):
for file in files:
path = os.path.join(dir, file)
name = path[l:].replace('/', '\\')
paths.append((path, name))
data = {name: open(path, 'rb').read() for path, name in paths}
return data
def write_mdd_file(directory, fname):
"Write contents in `directory` to mdd file `fname`"
outfilemdd = open(fname, "wb")
d = mdd_data_from_dir(directory)
writer = MDictWriter(d, "MDD", "MDD Description", is_mdd=True)
writer.write(outfilemdd)
outfilemdd.close()
write_mdd_file(mdd_file)
i think data read is right,try specify mdd formats.