reuseman / flashcards-obsidian

🎴 An Anki plugin for Obsidian.md
MIT License
872 stars 86 forks source link

Plugin ceases to create flashcards. #143

Closed jaded0 closed 1 year ago

jaded0 commented 1 year ago

After the big obsidian update, I managed to create a few flashcards, but upon running the 'Generate for the current file' command, there is no error message and no response whatsoever. Anki does not show new flashcards made, nor do the little '^1666026165215' type tags show up in my note. I'm using Ubuntu Linux. In settings, clicking, the 'test' button creates a message saying "Anki works."

github-actions[bot] commented 1 year ago

Thank you for taking the time to report the issue and help me to make the project better! 🙂

jaded0 commented 1 year ago

It works again if I close every single other tab. Scratch that, I went back to one of the notes that I tried to make a flashcard for, didn't work.

jaded0 commented 1 year ago

Ok, now I restarted my computer, opened obsidian and anki, created the simplest possible flashcard:

ok::a card

And, nothing. Nothing happens.

jaded0 commented 1 year ago

Here's the log from anki:

[request] { "action": "version", "params": {}, "version": 6 }

[reply] { "error": null, "result": 6 }

[request] { "action": "version", "params": {}, "version": 6 }

[reply] { "error": null, "result": 6 }

[request] { "action": "retrieveMediaFile", "params": { "filename": "_highlightInit.js" }, "version": 6 }

[reply] { "error": null, "result": "ZG9jdW1lbnQucXVlcnlTZWxlY3RvckFsbCgncHJlIGNvZGUnKS5mb3JFYWNoKChibG9jaykgPT4gewogICAgaGxqcy5oaWdobGlnaHRCbG9jayhibG9jayk7Cn0pOw==" }

[request] { "action": "multi", "params": { "actions": [ { "action": "createModel", "params": { "cardTemplates": [ { "Back": "{{FrontSide}}\n\n


\n\n{{Back}}\r\n

\r\nSource: {{Source}}", "Front": "{{Front}}\r\n<p class=\"tags\">{{Tags}}

\r\n\r\n", "Name": "Front / Back" } ], "css": ".card {\r\n font-family: arial;\r\n font-size: 20px;\r\n text-align: center;\r\n color: black;\r\n background-color: white;\r\n}\r\n\r\n.tag::before {\r\n\tcontent: \"#\";\r\n}\r\n\r\n.tag {\r\n color: white;\r\n background-color: #9F2BFF;\r\n border: none;\r\n font-size: 11px;\r\n font-weight: bold;\r\n padding: 1px 8px;\r\n margin: 0px 3px;\r\n text-align: center;\r\n text-decoration: none;\r\n cursor: pointer;\r\n border-radius: 14px;\r\n display: inline;\r\n vertical-align: middle;\r\n}\r\n .cloze { font-weight: bold; color: blue;}.nightMode .cloze { color: lightblue;}", "inOrderFields": [ "Front", "Back", "Source" ], "modelName": "Obsidian-basic-source" } }, { "action": "createModel", "params": { "cardTemplates": [ { "Back": "{{FrontSide}}\n\n
\n\n{{Back}}\r\n

\r\nSource: {{Source}}", "Front": "{{Front}}\r\n<p class=\"tags\">{{Tags}}

\r\n\r\n", "Name": "Front / Back" }, { "Back": "{{FrontSide}}\n\n
\n\n{{Front}}\r\n

\r\nSource: {{Source}}", "Front": "{{Back}}\r\n<p class=\"tags\">{{Tags}}

\r\n\r\n", "Name": "Back / Front" } ], "css": ".card {\r\n font-family: arial;\r\n font-size: 20px;\r\n text-align: center;\r\n color: black;\r\n background-color: white;\r\n}\r\n\r\n.tag::before {\r\n\tcontent: \"#\";\r\n}\r\n\r\n.tag {\r\n color: white;\r\n background-color: #9F2BFF;\r\n border: none;\r\n font-size: 11px;\r\n font-weight: bold;\r\n padding: 1px 8px;\r\n margin: 0px 3px;\r\n text-align: center;\r\n text-decoration: none;\r\n cursor: pointer;\r\n border-radius: 14px;\r\n display: inline;\r\n vertical-align: middle;\r\n}\r\n .cloze { font-weight: bold; color: blue;}.nightMode .cloze { color: lightblue;}", "inOrderFields": [ "Front", "Back", "Source" ], "modelName": "Obsidian-basic-reversed-source" } }, { "action": "createModel", "params": { "cardTemplates": [ { "Back": "{{cloze:Text}}\n\n
{{Extra}}\r\n

\r\nSource: {{Source}}", "Front": "{{cloze:Text}}\n\n", "Name": "Cloze" } ], "css": ".card {\r\n font-family: arial;\r\n font-size: 20px;\r\n text-align: center;\r\n color: black;\r\n background-color: white;\r\n}\r\n\r\n.tag::before {\r\n\tcontent: \"#\";\r\n}\r\n\r\n.tag {\r\n color: white;\r\n background-color: #9F2BFF;\r\n border: none;\r\n font-size: 11px;\r\n font-weight: bold;\r\n padding: 1px 8px;\r\n margin: 0px 3px;\r\n text-align: center;\r\n text-decoration: none;\r\n cursor: pointer;\r\n border-radius: 14px;\r\n display: inline;\r\n vertical-align: middle;\r\n}\r\n .cloze { font-weight: bold; color: blue;}.nightMode .cloze { color: lightblue;}", "inOrderFields": [ "Text", "Extra", "Source" ], "isCloze": true, "modelName": "Obsidian-cloze-source" } }, { "action": "createModel", "params": { "cardTemplates": [ { "Back": "{{FrontSide}}\n\n
\ud83e\udde0 Review done.\r\n

\r\nSource: {{Source}}", "Front": "{{Prompt}}\r\n<p class=\"tags\">\ud83e\udde0spaced {{Tags}}

\r\n\r\n", "Name": "Spaced" } ], "css": ".card {\r\n font-family: arial;\r\n font-size: 20px;\r\n text-align: center;\r\n color: black;\r\n background-color: white;\r\n}\r\n\r\n.tag::before {\r\n\tcontent: \"#\";\r\n}\r\n\r\n.tag {\r\n color: white;\r\n background-color: #9F2BFF;\r\n border: none;\r\n font-size: 11px;\r\n font-weight: bold;\r\n padding: 1px 8px;\r\n margin: 0px 3px;\r\n text-align: center;\r\n text-decoration: none;\r\n cursor: pointer;\r\n border-radius: 14px;\r\n display: inline;\r\n vertical-align: middle;\r\n}\r\n .cloze { font-weight: bold; color: blue;}.nightMode .cloze { color: lightblue;}", "inOrderFields": [ "Prompt", "Source" ], "modelName": "Obsidian-spaced-source" } } ] }, "version": 6 }

[request] { "action": "createModel", "params": { "cardTemplates": [ { "Back": "{{FrontSide}}\n\n


\n\n{{Back}}\r\n

\r\nSource: {{Source}}", "Front": "{{Front}}\r\n<p class=\"tags\">{{Tags}}

\r\n\r\n", "Name": "Front / Back" } ], "css": ".card {\r\n font-family: arial;\r\n font-size: 20px;\r\n text-align: center;\r\n color: black;\r\n background-color: white;\r\n}\r\n\r\n.tag::before {\r\n\tcontent: \"#\";\r\n}\r\n\r\n.tag {\r\n color: white;\r\n background-color: #9F2BFF;\r\n border: none;\r\n font-size: 11px;\r\n font-weight: bold;\r\n padding: 1px 8px;\r\n margin: 0px 3px;\r\n text-align: center;\r\n text-decoration: none;\r\n cursor: pointer;\r\n border-radius: 14px;\r\n display: inline;\r\n vertical-align: middle;\r\n}\r\n .cloze { font-weight: bold; color: blue;}.nightMode .cloze { color: lightblue;}", "inOrderFields": [ "Front", "Back", "Source" ], "modelName": "Obsidian-basic-source" } }

[reply] { "error": "Model name already exists", "result": null }

[request] { "action": "createModel", "params": { "cardTemplates": [ { "Back": "{{FrontSide}}\n\n


\n\n{{Back}}\r\n

\r\nSource: {{Source}}", "Front": "{{Front}}\r\n<p class=\"tags\">{{Tags}}

\r\n\r\n", "Name": "Front / Back" }, { "Back": "{{FrontSide}}\n\n
\n\n{{Front}}\r\n

\r\nSource: {{Source}}", "Front": "{{Back}}\r\n<p class=\"tags\">{{Tags}}

\r\n\r\n", "Name": "Back / Front" } ], "css": ".card {\r\n font-family: arial;\r\n font-size: 20px;\r\n text-align: center;\r\n color: black;\r\n background-color: white;\r\n}\r\n\r\n.tag::before {\r\n\tcontent: \"#\";\r\n}\r\n\r\n.tag {\r\n color: white;\r\n background-color: #9F2BFF;\r\n border: none;\r\n font-size: 11px;\r\n font-weight: bold;\r\n padding: 1px 8px;\r\n margin: 0px 3px;\r\n text-align: center;\r\n text-decoration: none;\r\n cursor: pointer;\r\n border-radius: 14px;\r\n display: inline;\r\n vertical-align: middle;\r\n}\r\n .cloze { font-weight: bold; color: blue;}.nightMode .cloze { color: lightblue;}", "inOrderFields": [ "Front", "Back", "Source" ], "modelName": "Obsidian-basic-reversed-source" } }

[reply] { "error": "Model name already exists", "result": null }

[request] { "action": "createModel", "params": { "cardTemplates": [ { "Back": "{{cloze:Text}}\n\n
{{Extra}}\r\n

\r\nSource: {{Source}}", "Front": "{{cloze:Text}}\n\n", "Name": "Cloze" } ], "css": ".card {\r\n font-family: arial;\r\n font-size: 20px;\r\n text-align: center;\r\n color: black;\r\n background-color: white;\r\n}\r\n\r\n.tag::before {\r\n\tcontent: \"#\";\r\n}\r\n\r\n.tag {\r\n color: white;\r\n background-color: #9F2BFF;\r\n border: none;\r\n font-size: 11px;\r\n font-weight: bold;\r\n padding: 1px 8px;\r\n margin: 0px 3px;\r\n text-align: center;\r\n text-decoration: none;\r\n cursor: pointer;\r\n border-radius: 14px;\r\n display: inline;\r\n vertical-align: middle;\r\n}\r\n .cloze { font-weight: bold; color: blue;}.nightMode .cloze { color: lightblue;}", "inOrderFields": [ "Text", "Extra", "Source" ], "isCloze": true, "modelName": "Obsidian-cloze-source" } }

[reply] { "error": "Model name already exists", "result": null }

[request] { "action": "createModel", "params": { "cardTemplates": [ { "Back": "{{FrontSide}}\n\n


\ud83e\udde0 Review done.\r\n

\r\nSource: {{Source}}", "Front": "{{Prompt}}\r\n<p class=\"tags\">\ud83e\udde0spaced {{Tags}}

\r\n\r\n", "Name": "Spaced" } ], "css": ".card {\r\n font-family: arial;\r\n font-size: 20px;\r\n text-align: center;\r\n color: black;\r\n background-color: white;\r\n}\r\n\r\n.tag::before {\r\n\tcontent: \"#\";\r\n}\r\n\r\n.tag {\r\n color: white;\r\n background-color: #9F2BFF;\r\n border: none;\r\n font-size: 11px;\r\n font-weight: bold;\r\n padding: 1px 8px;\r\n margin: 0px 3px;\r\n text-align: center;\r\n text-decoration: none;\r\n cursor: pointer;\r\n border-radius: 14px;\r\n display: inline;\r\n vertical-align: middle;\r\n}\r\n .cloze { font-weight: bold; color: blue;}.nightMode .cloze { color: lightblue;}", "inOrderFields": [ "Prompt", "Source" ], "modelName": "Obsidian-spaced-source" } }

[reply] { "error": "Model name already exists", "result": null }

[reply] { "error": null, "result": [ { "error": "Model name already exists", "result": null }, { "error": "Model name already exists", "result": null }, { "error": "Model name already exists", "result": null }, { "error": "Model name already exists", "result": null } ] }

[request] { "action": "createDeck", "params": { "deck": "default_obsidian" }, "version": 6 }

[reply] { "error": null, "result": 1651360049944 }

[request] { "action": "notesInfo", "params": { "notes": [] }, "version": 6 }

[reply] { "error": null, "result": [] }

[request] { "action": "version", "params": {}, "version": 6 }

[reply] { "error": null, "result": 6 }

jaded0 commented 1 year ago

Update: The issue does not occur if I remove the embedded image that I had placed a few lines below my inline flashcard.

reuseman commented 1 year ago

Probably there is something wrong with the new update of Obsidian

xverbatim1971 commented 1 year ago

I also have the same problem. Windows 10 Flashcards are not created. Connection to Anki is established, but nothing happens after pressing the "generate" button. after a restart of obsidian it worked.

is it important in which mode you have the note open? difference between preview or editmode? I am not sure

thanks for the plugin and the effort in the work

i hope the bug will be found

Schabolon commented 1 year ago

I encountered a similar problem. For me the card generation worked again after removing an embedded image from the .md file. (the image was NOT in the flashcards). Hope this helps.

JH-Stuvansys commented 1 year ago

I think I know where in your code it's breaking. Here: image

The reason: image

I would love to help with bugfixing, but I'm a freelancer (with 2 companies, among others as a software engineer for major customers like Daimler) and on the side I'm doing my master and have a daughter. Just wanted to help you a bit, because I read somewhere that you are looking for support and I use your plugin super gladly and as a colleague knows exactly how it is when the bugs paralyze you.

BTW: Strange I find the occupation of my port with this strange service. The ensures that at the beginning of this error is thrown:

image

JH-Stuvansys commented 1 year ago
image

This happens, when i take a fresh markdown-file. I dont know wether card.ts line 100 is refererring to the minified version of the typescript file. But far away from that and please dont take it personal, but i would avoid putting too much code in a try catch block. I do programming since about 30 years and i did many code reviews and i was never strict in a sense of doing formalism that helps nobody. But thats really a point that makes it hard to find bugs. I will now switch for the meanwhile to neuracacne, because i have stress for learning for my master (in artificial intelligence, many hardcore-math stuff i didnt have in my cs bachelor) so i need asap a new solution. When you have fixed the bug, you will surely release a new version. I will come back then. Like i have said, i am a big fan of your tool.

erfanbashar1q commented 1 year ago

I also have the same problem with creating cards if i have embeded image, when i remove the "!" from the first of embeded image, it can be generated. in a file presence of just one "!" is equal to this bug

thank you for your support

bytewife commented 1 year ago

I was able to reproduce the bug by adding an embedded image (ex ![[image.png]]) to any flashcard style.

bytewife commented 1 year ago

It appears that this line in parser.ts

      var embedContentHtml = el.getElementsByClassName('markdown-embed-content')[0];

now fails to retrieve any html elements.

Looking into fixes now

bytewife commented 1 year ago

I have a working solution in https://github.com/ivyraine/flashcards-obsidian/tree/143

However, before merging it should be backwards compatible: @jaded0 @Schabolon @JH-Stuvansys @xverbatim1971 Did this error occur in previous Obsidian versions? What was the last working version?

xverbatim1971 commented 1 year ago

the problem was from version 1.0 - the current version. there were also image problems. before that, everything worked fine. the images were displayed to me and the cards produced.

now i don't do anything with images and so far everything is ok... I have only noticed that the information is sometimes not correct. information such as update, created - but directly in anki I have not noticed anything.

Translated with www.DeepL.com/Translator (free version)

JH-Stuvansys commented 1 year ago

It appears that this line in parser.ts

      var embedContentHtml = el.getElementsByClassName('markdown-embed-content')[0];

now fails to retrieve any html elements.

Looking into fixes now

Well done. I just have hab a quick look and if you follow down the stacktrace, you see that the core work is done by the parser.

JH-Stuvansys commented 1 year ago

the problem was from version 1.0 - the current version. there were also image problems. before that, everything worked fine. the images were displayed to me and the cards produced.

now i don't do anything with images and so far everything is ok... I have only noticed that the information is sometimes not correct. information such as update, created - but directly in anki I have not noticed anything.

Like xverbatim1971 said: The error appears the first time after the "Big Update / Upgrade" of Obsidian.

reuseman commented 1 year ago

@ivyraine I've just done a quick test on my machine, and it doesn't seem fixed

reuseman commented 1 year ago

Now it should work, the problem seemed to be the fact that after the pull request #114, the embedded images were treated as an embedded block