Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eudic doesn't load CSS and JS files from .mdd file #5

Open
coolplay opened this issue Mar 2, 2017 · 5 comments
Open

Eudic doesn't load CSS and JS files from .mdd file #5

coolplay opened this issue Mar 2, 2017 · 5 comments

Comments

@coolplay
Copy link

coolplay commented Mar 2, 2017

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!

@zhansliu
Copy link
Owner

zhansliu commented Mar 7, 2017

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.

@coolplay
Copy link
Author

coolplay commented Mar 7, 2017

Here is an example, which actually contains the mdd file where I would like to substitue these JS and CSS files.
Access code: uj5v

@zhansliu
Copy link
Owner

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?

@coolplay
Copy link
Author

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)

@KnIfER
Copy link

KnIfER commented Dec 14, 2017

i think data read is right,try specify mdd formats.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants