foambubble / foam

A personal knowledge management and sharing system for VSCode
https://foambubble.github.io/
Other
15.22k stars 650 forks source link

Proposal: Export to Anki #140

Closed jasonwilliams closed 3 years ago

jasonwilliams commented 4 years ago

So we were having a chat on the discord server about how this could work. I came across https://github.com/caisj-dev/SendToAnki which is a sublime plugin for sending markdown notes to Anki.

I believe we can add something similar to foam as a feature. The Anki api (via openconnect) is a HTTP REST interface, so should be easy to communicate with.

Ideally I imagine at the bottom of each markdown file you can add some quick Anki notes.

Some open questions:

jsjoeio commented 4 years ago

I don't have an open issue for this but I think this also relates to another discussion we had on Discord around creating Anki cards and studying them within VS Code similar to this flashcards extension.

I imagine some of the work overlaps with this feature.

jsjoeio commented 4 years ago

What are your thoughts on adding syntax to create spaced-repetition cards similar to how RemNote does it?

jsjoeio commented 4 years ago

image

For those who aren't familiar, here is a reference.

jasonwilliams commented 4 years ago

Reusing Remnote syntax could be a good idea. I’m not sure how we do that inside of a markdown file though? Does remnote have syntax highlighting? Could it be done in a code block and hidden from preview?

jsjoeio commented 4 years ago

Yeah, I haven't thought through that yet either. Oh, that's a good idea. Maybe that's possible

jasonwilliams commented 4 years ago

I'm leaning towards yaml for syntax, there's already support for it in VSCode, we will have syntax highlighting and we should already be able to parse it with off-the-shelf tools. It's also quite readable.

Here is an initial idea:

Send to specific Deck

DeckName:
  - question: My question here
    answer: my answer here
    optionalHint: My hint here
  - question: My second question here
    answer: my second answer here
    optionalHint: My second hint here

Default to title|config for deck

  - question: My question here
    answer: my answer here
    optionalHint: My hint here
  - question: My second question here
    answer: my second answer here
    optionalHint: My second hint here

Shortening to q and a

  - q: My question here
    a: my answer here
  - q: My second question here
    a: my second answer here

By using this format it allows us to use extra key values for other metadata, like hints, tags or anything else we want to send to Anki or other systems.
Having a new deck per bubble will quickly clutter up anki, so another option is to send to a deck called "notes" or whatever the default is, then use the title of each note as a tag

Config for now: Default Deck: "notes" || forced option

Api Everything we do here needs to map to the AnkiConnect API https://github.com/FooSoft/anki-connect/blob/master/actions/notes.md

jasonwilliams commented 4 years ago

I think flashcards could live as part of the markdown metadata (which i don't think foam uses yet), this also means it won't be rendered in the preview version. Most markdown renderers ignore the initial metadata fields, and they're already yaml so we get a lot of functionality for free.

https://github.com/ninjabachelor/markdown-yaml-metadata-parser

Usage:

---
flashcards:
  - q: question
    a: answer
---

# title
jevakallio commented 4 years ago

@jasonwilliams thanks for this suggestion!

I think flashcards could live as part of the markdown metadata

We call this type of yaml metadata "frontmatter" (as that's what it's typically called in static site publishing circles), and we'll be adding full support shortly. This means extension builders can use it for whatever metadata they need -- so big 👍 for that approach.

The one thing I don't know (as someone who doesn't do spaced repetition) is whether that's a user friendly approach?

Generally speaking,

An ideal solution for Foam might look like:

I'm not an experienced spaced repetition user, but I'd love to learn more, so perhaps I can add value as the novice user who vets the intuitiveness of the approach.

@jasonwilliams @jsjoeio if we can put together a proposal for this, I'd be happy to include it on the roadmap and discuss how to best add this support to Foam, whether as a built in feature or as a third party extension!

jasonwilliams commented 4 years ago

Would you manually write the questions and answers for their flash card?

Personally yes, I don't think this is much of an issue, if you try to be too clever it ends up being complicated both for the user and the implementor. I also think for a first version it should be simple (you can always add on extra functionality later). Some easy-win ideas would be, highlighting some text and having that as the answer, then you just need to write out the question etc.

Would you want to have them at the top of the file like this, or interspersed inside a markdown note closer to where the information is written?

The top doesn't seem great, but it stays within the "frontmatter" standard, and makes it easy for other apps to reuse the questions and answers, i believe this fits in with the foam methodology.

Having it with the content is nice for context, but i don't have much idea on what this would look like.

I may be able to create a plugin as a proof of concept

fmagin commented 4 years ago

I personally use Anki myself and am also quite interested in combining my note taking and my flashcards.

I feel like this issue starts with some really complicated solutions, instead of talking about some simpler ones first: Anki can import typically table formats like CSV/TSV. So as long as you can export a foam note to an appropriate csv you can import it into Anki as an Anki note. This is both available as a GUI option and by simply calling anki cards.csv which starts Anki and opens the import dialog with that CSV file.

it would be nice not to duplicate the Anki questions (if they already exist on Anki don’t add again) the import feature I am talking about has an option if the first field of a row in the CSV matches an existing card. You can either update the existing card with the new field data (and keep the learning progress!), ignore the card, or add a new card.

So my suggestion would be: Foam could just support exporting certain metadata to certain formats in general, in this case this could be the anki field in the frontmatter metadata that is already in a form that can be exported to a CSV as one Anki note per row (an Anki card is not the same as an Anki note. Though at this point it doesn't even feel like you are doing anything Foam related anymore. So maybe even make this a separate extension that just generates Anki notes from Markdown metadata.

If the goal is just to support specific card types it would be possible to create Anki note types that contain fields with Foam related metadata, e.g. the Foam note the flashcard came from. If the first field is designed with this in mind it could then be used to make sure Foam notes that are exported to Anki notes don't interfere with other cards (Anki just checks for duplicate cards of the same note type). That first field can then be used as an identifier of some kind, so you can run the anki import with the update option on first field match, and only the changes will be applied and reimporting the same CSV again is idempotent.

The RemNote syntax looks neat, but I feel like this would introduce an absurd amount of complexity because you would have to extend the markdown parser itself. The metadata approach seems a lot simpler.

I expect this to be a lot simpler than dealing with the Anki API itself and to be enough for many users (extrapolated from myself and friends I know who also actively use Anki)

jasonwilliams commented 4 years ago

The more i think about it the more i think Anki functionality should live in it's own VSCode plugin, I've made good progress on this and will hopefully have something to show in a week or so.

Also no import/export is needed, i've been able to bridge VSCode directly to Anki, so you can just run a command on a Markdown file and it's straight in there.

You can also browse already existing cards. I think this will be good enough for a first-version

I’ve noticed there aren’t really any Anki extensions for VSCode around so this can be both something generally useful and integrates with Foam

jsjoeio commented 4 years ago

Also no import/export is needed, i've been able to bridge VSCode directly to Anki, so you can just run a command on a Markdown file and it's straight in there.

🤯 Oh man, that's exciting to hear.

I've made good progress on this and will hopefully have something to show in a week or so.

Sweet! Looking forward to checking it out!

jasonwilliams commented 4 years ago

@jsjoeio https://marketplace.visualstudio.com/items?itemName=jasew.anki try it and let me know, it may be buggy but should work well enough

jsjoeio commented 4 years ago

Woot woot! Will do. Props for coming up with something so quickly!

jasonwilliams commented 3 years ago

I think this issue can be closed now that https://marketplace.visualstudio.com/items?itemName=jasew.anki is available. If there's a link of extensions this can be used with maybe it can be added there.