debugging broken cards

Adam's Avatar

Adam

12 Sep, 2018 02:22 AM

I'm observing a small number of broken cards in my copy of the Hanping Chinese HSK (1-6) deck and I'd like to debug them but I don't know how to proceed. Hoping someone here can guide me in the right direction.

The observed problem: I have set up CSS preferences to see both traditional and simplified characters, and pinyin with tone markings. The vast majority of cards look fine but a very small number (like 5 out of a thousand) are broken so that only the simplified characters are displayed and the pinyin tone markings are not displayed.

I have tried viewing both a broken card and a working card in Anki's card browser and the template text is identical, but when I click "Cards..." the back preview pane shows the problem on the broken card. How is this possible?

  1. 1 Posted by Guillem Palau-S... on 13 Sep, 2018 01:40 AM

    Guillem Palau-Salvà (contributor user)'s Avatar

    Hi Adam,

    I can help you. Could you provide an apkg file containing those 5 cards and some random more that is working? Like this will be much quicker to help you and we'll save a lot messages.

    Guiilem

  2. 2 Posted by Adam on 13 Sep, 2018 06:31 PM

    Adam's Avatar

    Hi Guillem,
    Thanks for the help! Attached is an apkg file with a couple of broken cards (tagged 'broken') and a couple of ok cards (tagged 'ok'). I know there are some other broken cards but unfortunately I can't remember which ones.
    --Adam

  3. 3 Posted by Guillem Palau-S... on 13 Sep, 2018 07:57 PM

    Guillem Palau-Salvà (contributor user)'s Avatar

    Hi Adam, I looked at your cards.

    I guess it is this shared deck. I suggest you to contact the author ( EmberMitre Ltd), since seems they have a dictionary and an app set up.

    About those cards that are broken it is because of a flaw of the scripting, since depends absolutely on that dict and any character that is missing in this dictionary will be just skipped.

    I must say there is an enormous amount of scripting. In fact the all front and back templates are purely script. In my modest opinion, that's a heavily inefficient way to style and generate cards. It even has the whole zhuyin dictionary repeated twice for each card... A lot of immutable info could be hard-coded into extra fields. No need to convert or generate things each time you show a card.

    Take into account that the script code is saved for each card. Actually it weights 17.4kB and is repeated 8 times per note. So, imagine the space wasted with thousands of notes. Also, the reviewing experience could be slower in mobile.

    Guillem

  4. 4 Posted by Adam on 13 Sep, 2018 08:39 PM

    Adam's Avatar

    Hi Guillem,
    Thank you again for taking a look. Are you saying that the script is looking up the character in a dictionary each time a card is reviewed? Could you please point me to the relevant part of the template code?
    Thanks,
    --Adam

  5. 5 Posted by Guillem Palau-S... on 15 Sep, 2018 03:27 AM

    Guillem Palau-Salvà (contributor user)'s Avatar

    Hi,

    Yes, the script uses the dictionary. Also, the author states that fact explicitly in the description. Look at this section of the code.

    <a class=hanzi href='intent:#Intent;action=com.hanpingchinese.cmn.intent.action.DETAILS;package=com.embermitre.hanping.app.pro;S.p={{text:Pinyin}};S.s={{text:Simplified}};S.t={{text:Traditional}};S.LANG=cmn;S._SOURCE=anki;end'>{{Simplified}}</a><br><br>{{#Pinyin}}<a class=phonetic href='intent:#Intent;action=com.hanpingchinese.cmn.intent.action.PLAY;package=com.embermitre.hanping.app.pro;S.p={{text:Pinyin}};S.s={{text:Simplified}};S.t={{text:Traditional}};S.LANG=cmn;S._SOURCE=anki;end'>{{Pinyin}}</a>{{/Pinyin}}<br><br><span class=meaning>{{Meaning}}</span><br><br><a class=links_button href='intent:#Intent;action=com.hanpingchinese.cmn.intent.action.LINKS;package=com.embermitre.hanping.app.pro;S.p={{text:Pinyin}};S.s={{text:Simplified}};S.t={{text:Traditional}};S.LANG=cmn;S._SOURCE=anki;end'>links</a>

    The traditional hanzi are generated here where it calls the methon 'toHanzi'
    document.getElementsByClassName('hanzi')[0].innerHTML=toHanzi('cmn', '{{Traditional}}', '{{Simplified}}', false);

    Guillem

  6. 6 Posted by arthaey on 10 Oct, 2018 07:27 PM

    arthaey's Avatar

    You could reduce the file size of the collection by loading the Javascript dynamically, at least. This works for both desktop and iPhone (and presumably Android, although I can't test that):

    <script type="text/javascript">
      var script = document.createElement("script");
      script.type = "text/javascript";
      script.src = "_myScriptFilename.js";
      document.getElementsByTagName("head")[0].appendChild(script);
    </script>
    

    This way, you have a lot less repeated text per Card, and the bulk of the repeated Javascript is in the _myScriptFilename.js file in your collection.media directly.

    This won't help any with speed, of course.

    Depending on how their script works, you may have to do some sort of async "on load" checking.

  7. 7 Posted by Adam on 10 Oct, 2018 08:43 PM

    Adam's Avatar

    Sorry for my cluelessness here. What exactly is saved per-card to disk? Just the fields, or also the javascript template, or generated html?

    If the template or generated html are saved then I suppose there is no guarantee that the javascript used for one card is the same as the code used for another. Then I have to ask whether the template displayed in anki's editor (when I look at a particular card) is the template stored on disk with that card or whether it is some common default copy. Because when I make a change to that template and then view different card, I still see the change associated with the new card.

  8. 8 Posted by arthaey on 12 Oct, 2018 03:50 AM

    arthaey's Avatar

    The front & back templates you see is stored per card template. (The CSS styles are shared between all cards of the same note type.) So if you have the Javascript copy-pasted in each of those, then you're absolutely right, you have no guarantee that they're exactly the same.

    That's why I like dynamically loading an external Javascript file — I'm sure there's only one copy that they all share! :)

  9. 9 Posted by Adam on 26 Oct, 2018 02:20 AM

    Adam's Avatar

    After some research I was able to open up the .apkg and debug. For anyone who might be interested: unzip the apkg file, view the collection.anki2 file with sqlite3. Use .help to see the list of commands - there is a command to see the full schema and another to dump the table data.

    From the schema it is clear that the templates are NOT stored per card. A single copy is stored in the 'conf' field of the 'col' table.

    The problem had nothing to do with the dictionary - it was the unescaped single-quote mark in the meaning field.

Comments are closed, but you can start a new discussion.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac