jdlorimer / incremental-reading

Anki add-on providing incremental reading features
https://ankiweb.net/shared/info/935264945
ISC License
216 stars 38 forks source link

Bug: Invalid HTML on card: TypeError: require is not a function #55

Closed aronneagu closed 6 years ago

aronneagu commented 6 years ago

I have Anki Version 2.1.0beta36 and Incremental addon version 4.7.14.

I added the the source code from https://aws.amazon.com/ec2/faqs/ to a an IR3 note: in the Text field, I pressed "Edit HTML", and added the source code of the above page. However, when I tried to read the article, I got the following error "Invalid HTML on card: TypeError: require is not a function"

I am running MacOS 10.12.6 Below you can see the order in which I tried to open the IR3 notes.

Do I have to downgrade to Anki 2.0? Any help would be appreciated. Thank you.

screen shot 2018-02-12 at 23 16 39 screen shot 2018-02-12 at 23 16 43 screen shot 2018-02-12 at 23 16 47
ghost commented 6 years ago

I'm not Luo Li-Yan, however if I understood the code correctly this is not the correct way to import a webpage. The right way is through Alt + 3 or Read -> Import webpage. This way the tags 'script' (script) and 'iframe' (embedded webpage) and their contents are removed from the html (this operation is done with BeautifulSoup4 and html.parser). In your case, the error seems to come from several 'script' tags that weren't removed.

However, the fun thing is that I got a completely new kind of issue with your webpage (and the correct procedure): the note is totally blank in Anki (in review state), but my mouse can detect links and they work, and if I edit it everything seems to be fine in the 'Text' field. I waited for one minute, thinking that perhaps the content was loading, but it didn't solve the problem. image

image

(Anki 2.1.0beta27, Linux, not really IR v4.8.0 so perhaps I've messed up some part of the code but I think it's more likely that the error comes from this particular page's html)

jdlorimer commented 6 years ago

Hi,

Timothee is basically correct. In my experience, the "invalid HTML on card" is usually embedded JavaScript. IR will strip this out when using "Import Webpage".

I will try to identify what part of your webpage is causing rendering errors, and see if that can be stripped out automatically. The only things that were really causing me trouble were iframes and scripts, so that is all that IR strips out at the moment. I'm happy to add other things to the blacklist, though.

Thanks for the report.

jdlorimer commented 6 years ago

Okay. This is caused by a conditional statement in the HTML. I've solved this by automatically stripping all comments.

This change is complete locally. I'll close this now, and upload the fix in the next few days.

aronneagu commented 6 years ago

Thank you for the prompt reply and fix. Its great to see such activity on the issue tracker. Keep the good work, its an awesome plugin.