Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue/feedback for cloze card #6

Open
orbuluh opened this issue May 1, 2023 · 6 comments
Open

Issue/feedback for cloze card #6

orbuluh opened this issue May 1, 2023 · 6 comments
Labels
question Further information is requested

Comments

@orbuluh
Copy link

orbuluh commented May 1, 2023

Hello @Mochitto,

I recently came across your project while searching for a library that can transform markdown to Anki cards and I must say it's a really nice project. However, I encountered some issues when trying out the cloze card. I think the problem with Anki cloze is that in your current design, HandleClozes will eventually create the same content for both the front and back strings. But in the card/model template, the front card has {{cloze:Front}}, and the back card has {{cloze:Back}}. I believe this is not what Anki expects. It may work if you force import the card with an apkg file, but if you are using AnkiConnect, the addNote call will fail. If I go to anki GUI and try to add the card with the content, it won't let me and pops out: Cloze deletion can only be used in fields which use the ‘cloze:’ filter error.

I found a workaround by modifying the card template's back and changing {{cloze:Back}} to {{cloze:Front}}. This way, the backside of the card will just use the same content as the front side, which is likely what cloze deletion operation expects. Then, I am not setting the Back field when making the addNote call.

Also, I had some trouble getting cloze cards to work at the beginning as I was doing something like:

clozes_handler = clozes.HandleClozes(markdown_content)
card_result = clozes_handler.inject_clozes(clozes_handler.hashed_markdown)

When I uploaded the card, it threw an exception, because you have the line:

t=document.querySelectorAll(e);if(!t.length)throw document.body.innerHTML=s,new Error(`Couldn't find any element matching ${e}`);return t}

And I realize the card model template is expecting the tab-group. After searching around the lib, I finally realize the correct calls are:

clozes_handler = clozes.HandleClozes(markdown_content)
# process_card is necessary to wrap around the handler output!
formatted_card_with_hashes = process_card(clozes_handler.hashed_markdown, vault)
card_result = clozes_handler.inject_clozes(formatted_card_with_hashes)

I feel like if cloze hashes and wrapping with process_card to add the tab-group are necessary, they should have been wrapped into one function as an exposed interface, basically mimicking the process_card counterpart:

def process_cloze(markdown_content, vault, linenos):
    clozes_handler = clozes.HandleClozes(markdown_content)
    formatted_card_with_hashes = clozes_handler.hashed_markdown, vault, linenos=linos)
    return clozes_handler.inject_clozes(formatted_card_with_hashes)

I hope this feedback is useful to you, and I'm looking forward to hearing your thoughts on this.
Thank you for your time and effort on this project.

@Mochitto
Copy link
Owner

Mochitto commented May 1, 2023

Hey there!
Thank you so much for the great feedback and taking the time to write this and look into the code :)
The project is still young and this kind of feedback truly helps a lot!


I'll address the different points you brought up one by one:

Note types use cloze:front, cloze:back

I decided to go with this since the design of "tabs" allows you to remove a tab from the front side and swap it out/add others in the back.

The whole output html is wrapped in different layers that make the front-end work.
One of these is .tab_group: this is responsible for the tabs feature (it basically "groups" tabs that are on the same side of the front/back).

You can think of the following card as an example where you have different front and back with clozes:

## [my cloze]
Hello {{c1::there}}
All of the left cards are their own tab group.

## - R [information]
This is a test for tabs and clozes.
All of the right cards have their own tab group

## + BR [Explanation]
The front right tab group had to be to be rebuilt with me in it

## B [Extra]
Same goes for the front left tab group; I was added to it

This will create a front with "my cloze" and "Information", and a back with "my cloze", "Explanation" and "Extra".
Markdown2Anki checks to make sure the cloze is not removed and stays where you've defined it, when creating the back field content.

Although the html/css was designed with modularity in mind, I'm not sure of a way that would allow us to use the "front" in the backside of the note type while retaining this feature, as Anki asks you to do... 😥

The note type does work when importing from csv, even if anki does throw the warning you've talked about when browsing the cards at times.

I'm not sure about how Anki handles clozes, but given they work, I think it's an editor-wise warning to help users avoid writing the cloze twice (or maybe think they can use multiple, different clozes), but when the backend/web view processes clozes, they don't check for it..?
Probably AnkiConnect is the actual part that enforces it.

I've been using clozes a lot in my coding cards and have never had problems with them 🤔

Exposing just one interface

I totally agree with you and that's a great call :)
While coding it, I was always a bit put off by having the interface that way, and I think my thought process was not wanting to entangle the imports (I went through a big refactoring to fix that in the past), but I was overthinking it and totally see and agree with your point!
I will take care of that later on today or tomorrow ☺️🌸

AnkiConnect

I'm wondering, were you trying to implement AnkiConnect to solve the request for it? :)

I've been thinking about it in the last days, and the possibilities are two: using the AnkiConnect interface (which does require the add-on, but power-users could send cards remotely, from what I understood), or using the anki module.
The latter works by having the user add the path to their anki collection in the config file.
Using the anki module, you could create the csv files temporarily and import them using the anki module (this seems to be in the docs), or adding cards manually (even if the steps for that are not well documented).

I am leaning towards AnkiConnect as I expect the package to be smaller in size and with good docs (the anki module has awful docs and you're forced to read the source/check add-ons for inspiration), but if AnkiConnect does enforce the "cloze only in the first field and in the front of the card", it could be a bit of a problem, unless we find a workaround for the "switching/adding tabs" problem...


What are your thoughts? :)
Thank you so much again for your time and help ☺️🌸
I feel like adding the automatic imports (using markdown frontmatter) will make using Markdown2Anki much better!

@orbuluh
Copy link
Author

orbuluh commented May 1, 2023

Hey hey 😃 Thank you so much for taking the time to respond in such detail and being willing to change the interface part! I really appreciate it. Markdown is my favorite format when taking notes, so I'm happy to see your project, which combines it with Anki! I have been using Anki for a while, but I only started to think about generating cards programmatically and discovered AnkiConnect add-ons a few days ago. So I might not be an expert on this subject. However, it seems to me that most libraries that can send cards (particularly remotely?) are using AnkiConnect under the hood though.

I needed to send Anki cards remotely because I use WSL2 on my Windows machine for development purposes. And my understanding is that WSL2 is considered a remote network to the Windows machine. (:rotating_light: Setting up AnkiConnect to work with WSL2 had some challenges, and I would be happy to share more information with you if you are interested in exploring this further.)

Overall my impression of AnkiConnect is that it's quite easy to use (Except for the issue costs by WSL2). The code snippet that ChatGPT provided basically just works. But this brings back the issue of the Cloze card template. If you check the below image, where I simply imported the Markdown2Anki.apkg manually and checked the card. You will see there were errors on the bottom right.

When using AnkiConnect and calling the request with addNote, I received an error response for an unknown reason. My guess is that AnkiConnect encountered the same error and decided not to upload the card as a result. While we could argue that the issue might also be related to the way the apkg loading was bypassing the enforcement, it does seem likely that AnkiConnect is the one that makes it fails. (But there is also a possibility that my local setup just messed it up. So maybe it would be nice if you could give it a try as well!)

example

@Mochitto
Copy link
Owner

Mochitto commented May 1, 2023

Thank you for the feedback and explaining more your situation ☺️
I'm super glad the project is useful to others :) I didn't have a great feedback in the beginning, so I'm always very happy when I get it!

I'm a bit busy today, but I will look into the AnkiConnect issue soon and check if the error is strictly related to the note type issue or could be something else :)

Also, even if the editor shows that error, you should be able to review the card and it should work correctly, can you confirm that? Do the cards work while reviewing?

If I can get AnkiConnect to work and the cards work even if anki complains about the note type, I won't have to think of workarounds for the front-end 🙈


If everything goes well and it's just Anki's editor, then I think I should be able to roll out the new version with AnkiConnect imports by the 15th/20th!

Until then, if the cards imported using the .apkg work for you, then you should be able to use Markdown2Anki and import the cards with its .csv output :)

@orbuluh
Copy link
Author

orbuluh commented May 2, 2023

Yes, confirmed that I can review the card in the Anki app and it works!

@Mochitto
Copy link
Owner

Mochitto commented May 2, 2023

Thanks for letting me know :)
I'll post commits with updates once I get to work on this issue, so you'll be able to see the progress on it 🌸☺️

@Mochitto
Copy link
Owner

Hey there! I've had a rough week so I couldn't get to work on this; hopefully I will be able to look into it tomorrow :)
Sorry for the wait 🙈

@Mochitto Mochitto added the question Further information is requested label May 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
Status: Backlog
Development

No branches or pull requests

2 participants