themoeway / yomitan

Pop-up dictionary browser extension. Successor to Yomichan.
https://yomitan.wiki
GNU General Public License v3.0
1.2k stars 94 forks source link

[object Object] for {glossary} when making anki cards through yomitan #246

Closed Weroxig closed 11 months ago

Weroxig commented 1 year ago

Description

<div style="text-align: left;">
    <ol>
        <li><i>(1, v5m, vt, JMdict Extra)</i> to read</li>
        <li><i>(1, v5m, vt, JMdict)</i> to read</li>
        <li><i>(2, JMdict Extra)</i> to recite (e.g. a sutra) | to chant</li>
        <li><i>(2, JMdict)</i> to recite (e.g. a sutra) | to chant</li>
        <li><i>(3, JMdict Extra)</i> [object Object]</li>
        <li><i>(3, JMdict)</i> [object Object]</li>
        <li><i>(4, JMdict Extra)</i> to decipher</li>
        <li><i>(4, JMdict)</i> to decipher</li>
        <li><i>(5, JMdict Extra)</i> [object Object]</li>
        <li><i>(5, JMdict)</i> [object Object]</li>
        <li><i>(6, JMdict Extra)</i> [object Object]</li>
        <li><i>(6, JMdict)</i> [object Object]</li>
    </ol>
</div>

This is {glossary} for 読め (beautified)

Browser version Firefox nightly 119.0a1 (2023-09-20) I also tried Firefox stable 117.0.1 (64-bit)

Yomichan version 23.8.19.0

Exported settings file yomitan-settings-2023-09-23-06-58-13.zip

dtop129 commented 1 year ago

I have the same problem, happening only with Firefox, if I try switching to Chromium {glossary} works as expected

Using Firefox 117.0.1

jarmanso7 commented 1 year ago

@Weroxig I am trying to reproduce your issue to no avail. Are you using a custom Anki Card Template? Besides the exported settings file (thanks for that), can you also please provide:

  1. The dictionaries you are using
  2. the dictionary configuration you are using
  3. the anki card template you are using

1. Dictionaries

You have an option to export your dictionary collection at (Settings -> Backup -> Export Dictionary Collection). The result should be a rather heavy file in the format yomitan-dictionaries-2023-10-03-13-24-26.json:

image

2. Dictionary configuration

What I currently have is probably different than your setup (Settings -> Dictionaries -> Configure installed and enabled dictionaries...:

image

3. Anki card template

You can find the anki card template (handlebars) if you go to Settings -> Anki -> Configure Anki card templates..., inside the textbox. Make sure you copy all the contents until the last line inside the textbox and save it into a txt file:

image

praschke commented 1 year ago

@jarmanso7 all you need to reproduce is yomitan, firefox, a dictionary with structured data like JMdict Extra, and to test {glossary}. i've reproduced this already.

jarmanso7 commented 1 year ago

@praschke Okay, I guess the missing part of the puzzle for me is JMdic Extra then. Thanks for the help, I'll try with that.

jarmanso7 commented 1 year ago

@praschke I was able to reproduce the issue. Thanks.

jarmanso7 commented 1 year ago

I've been investigating and I've hit a wall beyond which I'm unable to progress. This is what I've found out so far.

When creating an Anki card from Yomitan, at some point the function _renderTemplate at template-renderer.js is called. The value in the variable data is identical when debugging for both Firefox and Chrome. However, on passing data to instance(data) (a function that corresponds to Handlebars.compileAST at execution time) the values returned by this call and stored into the variable result already differ between Firefox and Chrome:

    _renderTemplate(instance, data) {
        const renderSetup = this._renderSetup;
        const renderCleanup = this._renderCleanup;
        let result;
        let additions1;
        let additions2;
        try {
            additions1 = (typeof renderSetup === 'function' ? renderSetup(data) : null);
            result = instance(data).trim();
        } finally {
            additions2 = (typeof renderCleanup === 'function' ? renderCleanup(data) : null);
        }
        return Object.assign({result}, additions1, additions2);
    }

For this reason, I believe there's some problem in the Handlebars processing (it may be related to Fix Handlebars not working on Firefox due to eval #171).

It is very difficult to debug inside Handlebars.min.js. @Aquafina-water-bottle, can you provide a way or would you kindly point me to the right direction to be able to debug a beautified/pretty version of Handlebars.min.js? Is it worth it (I've seen in the mentioned issue that using this library is a temporary fix)?.

Thank you.

praschke commented 1 year ago

@jarmanso7 the sourcemap can be found at https://github.com/Aquafina-water-bottle/handlebars-noeval/raw/master/handlebars.min.js.map

jsyk, Aquafina hasn't been around for a while.

jarmanso7 commented 1 year ago

@praschke I will try to set the sourcemaps. I am not a frontend developer which means each new step I take I have to learn it on the go, but hopefully I can get it to work. Thanks your your help

jarmanso7 commented 11 months ago

@praschke Thank you very much!! I just came back here to let you guys know I ran out of time to continue to look into this issue, just to find it already solved. Thank you again.