HTML Error in Anki 2.1

n8abx9y2qg's Avatar

n8abx9y2qg

05 Dec, 2019 05:44 PM

<div>
<img src="ajanilmaukset-14-728.jpg"><div>Lupaan ryhdistäytyä lähiaikoina.</div>
</div>

Hi,
I never had the tiniest problem with Anki 2.0. Thousands of cards worked wonderfully. Now I switched to 2.1 due to the syncing embargo, and suddenly my cards do not show anymore but

"Invalid HTML on card: SyntaxError: Invalid or unexpected token"

This error message shows for the HTML that I posted above. The HTML shows fine in the editing window. The picture exists locally and equally shows fine in the editing window? What is wrong with it? (BTW why do pictures take so much longer to load in 2.1?) Thx.

  1. 1 Posted by schmidhauser on 05 Dec, 2019 05:52 PM

    schmidhauser's Avatar

    What happens if you exchange the above expression by the following one?

    <div><img src="ajanilmaukset-14-728.jpg"></div>
    <div>Lupaan ryhdistäytyä lähiaikoina.</div>
    
  2. 2 Posted by ijg on 05 Dec, 2019 09:08 PM

    ijg's Avatar

    just a user here:

    this code works for me in the latest anki version 2.1.15.

    check your card template for invalid code. Remove everything apart from {{my field name}} - Does it work then?

    also check https://apps.ankiweb.net/docs/manual.html#javascript

    There's also https://anki.tenderapp.com/kb/problems/when-problems-occur

    Ideally you would say which steps you've performed from this list, if you have this problem without add-ons, what exact version you have, which os etc.

  3. 3 Posted by n8abx9y2qg on 07 Dec, 2019 08:48 AM

    n8abx9y2qg's Avatar
    What happens if you exchange the above expression by the following one?
    
    <div><img src="ajanilmaukset-14-728.jpg"></div>
    <div>Lupaan ryhdistäytyä lähiaikoina.</div>
    

    This indeed solves the problem occuring in
    Version 2.1.15 (442df9d6)
    Qt 5.12.1 PyQt 5.11.3
    Windows 10

    Thank you very much!


    I also had other HTML errors on other cards which involve JS. After not finding anything possibly wrong with the HTML I finally figured out that the evaluation order must have changed. Anki 2.0 tolerated expressions such as

    document.getElementById("whatever").innerHTML = "<a  id='whatever'>" + {{myAnkiField}} + "</a>";
    

    and correctly interpolated the content of myAnkiField.

    Anki 2.1. however throws an error. The Anki 2.1. error disappears after changing the line to

    var content = document.getElementById("whatever").innerHTML;
    document.getElementById("whatever").innerHTML = "<a  id='whatever'>" + content + "</a>";
    

    with the contents of myAnkiField previously saved into the JS variable "content". I hope this helps others.

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

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