jasonwilliams / anki Goto Github PK
View Code? Open in Web Editor NEWAnki VSCode Plugin
License: MIT License
Anki VSCode Plugin
License: MIT License
I'm going to start working on automatically updating Anki on save. I can think of two ways to do this. Looking for feedback.
If using strategy 1, the user can then prevent further sends to anki by deleting the metadata. 1 is my current strategy. But 2 might be cleaner.
The metadata added would include the note Ids that were created by the send. Then subsequent sends will check to see if the correlates of those notes still exist in the markdown and trigger a delete if they have been removed from the markdown.
I want the delete to occur because let's say I'm working on a topic and decide I need to totally rewrite some markdown files. I don't want tons of duplicate and out of date cards to be left in my Anki.
Hopefully, I think, this effect would be intuitive to people.
i want to generate the vsxi extention for developpement mode
Executing prepublish script 'npm run vscode:prepublish'...
[email protected] vscode:prepublish /home/abed/Bureau/anki-master
webpack --mode development
One CLI for webpack must be installed. These are recommended choices, delivered as separate packages:
webpack --mode development
npm ERR! A complete log of this run can be found in:
npm ERR! /home/abed/.npm/_logs/2020-09-16T17_35_51_681Z-debug.log
ERROR npm failed with exit code 1
new markdown and use “send to deck”, it's ok!
but then I modify the markdown,same title,then “send to deck”,no changes in Anki.
## Foo
bar
send to deck - OK!
## Foo
bar change
send to deck - not changes!
How can I rewirte the same card?
The Anki VSCode extension should support the native markup language of Anki itself for writing questions and answer flashcards.
The Anki VSCode extension currently supports only Markdown for writing questions and answer flashcards. Presumably —
at some point before sending flashcard content to Anki —the extension implements a Markdown-to-HTML transformation step to transform users' Markdown into the native markup language that Anki requires.
As a software developer I have experience writing HTML. I also have experience using vscode. So, knowing that the native markup language of Anki is HTML, I would like to be able to write HTML in vscode and have the Anki VSCode extension create Anki flashcards using that vscode-authored HTML.
It is reasonable to presume that vscode is used by software developers. It is reasonable to presume the majority of software developers are very likely to have at least some development experience writing basic HTML.
The vscode IDE supports the creation and editing of HTML out of the box…
...There is syntax highlighting, smart completions with IntelliSense, and customizable formatting...
The native markup language in Anki itself, is HTML…
Hey Jason!
First, thanks for making this!
Second, I'm having some issues getting it to work. I wonder if you could add a "Quickstart" or "Getting Started" section to the README.md
.
Here's what I did:
Here is the markdown file I had open when I tried (anki.md
):
# Anki
## What does JS stand for?
JavaScript
## What is the best IDE/text editor for coding?
VS Code
I'm guessing there is something I'm missing. Any help would be appreciated! And happy to submit a PR to make it more clear in the README.md
after.
Anki
Version 2.1.14 (7b93e985)
Qt 5.12.1 PyQt 5.11.3
I tried creating a new deck with called "notes" and doing the command "send to deck"
I was using an older version of Anki. I upgraded, but still nothing. Debug info from Anki below:
Anki 2.1.28 (7d8818f8) Python 3.8.0 Qt 5.15.0 PyQt 5.15.0
Platform: Mac 10.14.6
Flags: frz=True ao=True sv=1
Add-ons, last update check: 2020-07-27 19:23:22
===Add-ons (active)===
(add-on provided name [Add-on folder, installed at, version, is config changed])
AnkiConnect ['2055492159', 2020-07-27T18:48, 'None', '']
Auto Markdown ['1030875226', 2019-10-12T12:30, 'None', '']
===IDs of active AnkiWeb add-ons===
1030875226 2055492159
===Add-ons (inactive)===
(add-on provided name [Add-on folder, installed at, version, is config changed])
in markdown tag is
@jasonwilliams thanks for the wonderful tool.
would be good to have cloze deletion support.
When I write a shell or Python comment in a code block, it is incorrectly resolved to a deck name.
So I just think about that could you please add a new option that use the current directory structure as deck name?
If the user enables this option
D:/Anki
D:/Anki/Deck1/SubDeck1/note.md
Deck1::SubDeck1
Thanks a lot!
When a markdown file contains remote image, it will throw a file not found error
Deck not sent: ENOENT: no such file or directory, open '/Users/terwer/Documents/mydocs/src.terwer.github.io/docs/001.后端开发/002.开源框架/001.MyBatis/https:/cdn.jsdelivr.net/gh/terwer/upload/img/20220314184626.png'
It is better to treat remote image as a image link and add to html tags,not to check file.
Title says it all.
I have the localhost instance running.
The desk is created however the actual card(s) never appear in the deck so the deck always has 0 cards and I can't add any.
Suggestions? @jasonwilliams
In the current version (0.3.0), if I push the same markdown file twice to anki, duplicated cards are created in anki.
Can we automatically detect the duplicates (e.g. by comparing front side of cards)?
VS Code: 1.59.0
Anki 2.1.44 (b2b3275f) Python 3.8.6 Qt 5.14.2 PyQt 5.14.2
Platform: Windows 10
Flags: frz=True ao=True sv=2
Add-ons, last update check: 2021-08-18 10:33:56
===Add-ons (active)===
(add-on provided name [Add-on folder, installed at, version, is config changed])
AnkiConnect ['2055492159', 2021-07-13T19:59, 'None', '']
I've create a markdown file that looks like it should work:
Doesn't look like cards are created
But I can run some python to do ankiconnect and they will create.
What am I doing wrong here?
Hi guys, apologies if this is a stupid question, I'm new to VS Code.
I want to add an Anki card, and then have some sort of closing operator, so that the text I write after it is not part of the Anki card. How can I do this? Is it possible with this software?
This is a super neat extension! Thanks for doing it.
Reading the README, I spotted a couple things:
#
" as the title of the current document“ might be clearer; Especially since you don't mention anywhere how to give the current file a title.#
at the top of the file means. But what if they don't?http://www.example.com
?mac os
Version 2.1.21 (f1734a47)
Python 3.8.0 Qt 5.13.1 PyQt 5.14.1
Anki for VSCode 1.0.4
when i first set headline h1
and answer abc
and send to deck i got a card like this
and then , i want update the answer to 123
, i change the markdown and send to deck , But it didn't seem to work,Anki not update the answer
When I want to update an answer, I need to delete the key from anki and then resynchronize it. Is there any simple way to deal with this problem?
At present it is possible to view CSS in the ide.
There is an endpoint: updateModelStyling
in ankiconnect, which we could use to pass styles to anki as a string.
We could register a command to do this.
It would make it possible to use sass/less to style cards.
Other ideas after this is complete include a preview - some sort of hot refresh of the anki viewport.
I don't think this is yet possible with existing tooling in the anki desktop app?
What are your thoughts?
EDIT
In case I was vague I am familiar with TypeScript and would like to invest some time here.
software | version |
---|---|
anki | 2.1.44 (b2b3275f) |
vscode | 1.56.2 |
Anki for VSCode | 1.2.0 |
OS | macOS big sur 11.3.1(M1) |
I have tried reinstall Anki and add-on
I also re-checked Anki and can't find the card
{
"label": "Anki for VSCode",
"level": "info",
"message": "active Editor..",
"time": "2021-05-24T11:05:01.827Z"
}
{
"label": "Anki for VSCode",
"level": "trace",
"message": "{\"action\":\"createDeck\",\"version\":6,\"params\":{\"deck\":\"notes\"}}",
"time": "2021-05-24T11:05:01.852Z"
}
{
"label": "Anki for VSCode",
"level": "trace",
"message": "{\"action\":\"addNotes\",\"version\":6,\"params\":{\"notes\":[{\"deckName\":\"notes\",\"modelName\":\"BasicWithHighlightVSCode\",\"options\":{\"allowDuplicate\":false,\"duplicateScope\":\"deck\"},\"fields\":{\"Front\":\"<h2 id=\\\"test\\\">test</h2>\\n\",\"Back\":\"<p>this is a test file</p>\\n\"},\"tags\":[\"os_test\"]}]}}",
"time": "2021-05-24T11:05:01.879Z"
}
Anki in dark mode on windows has blurry Syntax.
firstly, thank you for the huge effort to make this great extension ..
i'll be so happy if you can't add in settings of VSC for the addon the ability to allow duplicate cards ..
it's helpful for me...
for example if i wrote the following cards
then coming back the next day and forgetting about the Front Insight Card exists before .. and i wrote some content like :
The card won't be available inside Anki ... can you add this feature for me please ? thank you
I tried creating a MD file with the following text:
# Test Deck
## What's the Markdown?
Markdown is a lightweight markup language with plain-text-formatting syntax.
Its design allows it to be converted to many output formats,
but the original tool by the same name only supports HTML.
## Who created Markdown?
John Gruber created the Markdown language in 2004 in collaboration with
Aaron Swartz on the syntax.
I copied the questions directly our of the README.md. The "What's the Markdown?" question gets duplicated every time I run Anki: Send to Deck.
A quick diff check of the default notes's deck's JSON files for the questions shows that the duplicated questions only differ in the "id" field.
A minimal repro of this bug can be found by using the following test deck:
## Test'
Answer
## Test
Answer
The first question "Test'" will be duplicated but the second question "Test" will not. It looks like the apostrophe throws off the duplicate check somewhere and causes it to be re-added every time the question set is added to Anki.
Inspecting the generated card JSON file, I suspect that this is because the apostrophe converts to ' which triggers FooSoft/anki-connect#194 but I haven't done any deeper dive into this yet.
Thank you for sharing this plugin!
I would like to remove the h2 tag resulting from the usage of markdown level 2 headings as card separator. It is nice for visual display in vscode, but ugly on the flashcards. Mapping ## to another tag in the conversion or just nothing, would be a good solution.
Could you provide some build instructions? I could not get it to work, as it is the first time I am using esbuild.
When I use "Send to dirname deck", it always send to the default deck
I see a request for #12 and #23 for alternate card creation strategies.
I think that one from notion is really cool and clean.
I made my own favorite on my fork, modeled after my old attempts to make ODT and Word notes into Anki flashcards https://github.com/fletchermoore/n2c2 and https://github.com/fletchermoore/AnkiNotebooks
So I propose a card creation strategy option list:
Not sure what to call the default one:
Default
Notion2anki
Nested Headers <-- mine
Since it's just a matter of running them through different parsers, I think this should be good. We could add more if there are others out there people are using. Difficulty is describing what they do in the config file.
Will send this pull incrementally as well.
Currently images created in markdown are not transferred across.
When you call Deck.pushNewCardsToAnki, you assign Node ids to the Card.id member.
When you call AnkiService.findCards, you then assign Card ids to the Card.id member.
I don't think this is causing issues in the current code but presents something of a timebomb waiting to go off as I recently discovered in my fork. I propose renaming Card.id to Card.noteId and assigning v.note to the member in AnkiService.findCards. (ref: https://github.com/FooSoft/anki-connect/blob/master/actions/cards.md)
Anki may create multiple cards for each note, depending on the note model.
Jason, thanks for making this tool. It's super useful for my note-taking workflow!
Just a thought: right now this tool submits the whole markdown file to anki (i.e. everything under the ## ). This works if I create dedicated markdown files with anki cards only, but if my markdown files contain other content than anki cards, this does not work well.
There is another tool called Neuracache that imports flashcards from markdown files and they search for flashcards with some tags in the files: https://www.youtube.com/watch?v=RsV3qMUkgoA&ab_channel=IdeaRoots
Something like this could be a useful feature for this vscode plugin as well.
I'd love to import, edit and re-export some existing Anki decks. Is this a feature that might be possible to implement?
I did note that AnkiConnect has been recently updated as of May 9th 2021.
So when I create a deck using the "Send To Own Deck" command the deck name basically ends up being everything under the initial "#" and I was wondering if this is expected behavior and if there is any way around it. Below are some sceenshots of what I am referring to.
I would assume the deck's name would just be whatever the title header has up till it reaches a new line not till it finds a new card.
If this requires some code changes that you don't think you can quickly bang out you can direct me to some files and I probably can get a PR in relatively soon as I assume this isn't a crazy bug
When I try to use Cloze on latex equations now, they do not render properly. For example they the $ sign is just recognized as an actual $. Thanks for your consideration.
Anki:
Anki 2.1.35 (84dcaa86) Python 3.8.1 Qt 5.15.1 PyQt 5.15.1
Platform: Linux
Flags: frz=True ao=True sv=1
Add-ons, last update check: 2020-11-27 11:13:09
===Add-ons (active)===
(add-on provided name [Add-on folder, installed at, version, is config changed])
AnkiConnect ['2055492159', 2020-11-02T08:16, 'None', '']
===IDs of active AnkiWeb add-ons===
2055492159
===Add-ons (inactive)===
(add-on provided name [Add-on folder, installed at, version, is config changed])
AnkiConnect:
https://ankiweb.net/shared/info/2055492159
Anki for VSCode:
v1.0,3
Get null while addNotes
{
"result": [
null
],
"error": null
}
curl --location --request POST '127.0.0.1:8765' \
--header 'Content-Type: application/json' \
--data-raw '{
"action": "addNotes",
"version": 6,
"params": {
"notes": [
{
"deckName": "Things",
"modelName": "BasicWithHighlightVSCode",
"options": {
"allowDuplicate": false,
"duplicateScope": "deck"
},
"fields": {
"Front": "<h2 id=\"whats-the-markdown\">What's the Markdown?</h2>\n",
"Back": "<p>Markdown is a lightweight markup language with plain-text-formatting syntax.<br>Its design allows it to be converted to many output formats,<br>but the original tool by the same name only supports HTML.</p>\n"
},
"tags": []
}
]
}
}
'
{
"result": [
1606448001382
],
"error": null
}
After debug, only work when change "modelName": "BasicWithHighlightVSCode"
to "modelName": "Basic"
.
so this issue caused by constants definition at src/constants.ts
?
I've noticed that LaTeX curly brackets do not convert correctly (according to standard LaTeX editing rules).
Fails: $\{STUFF\}$
[correct LaTeX syntax] -> \({STUFF}\)
[appears wrong, as "STUFF"]
Works: $\\{STUFF\\}$
[wrong LaTeX syntax] -> \(\{STUFF\}\)
[appears correct, as "{STUFF}"]
Ideally, the correct LaTeX syntax results in the correct display/conversion in Anki; right now adding an extra backslash works, but is not accurate LaTeX syntax.
My directory tree is:
anki-decks/
└── python
└── argparse
└── note.md
If I cd to anki-decks, type code .
, open the note and use the command 'Anki: Send to DirName deck', it just creates a new deck called 'python/argparse'. It does not create a subdeck.
Edit: I can rename the deck in Anki, replacing the /
with ::
and it fixes the nesting. But the feature doesn't work as documented.
OpenSUSE Tumbleweed, (KDE/Plasma)
Anki Desktop: 2.1.54, Qt6
Vs Code: 1.69
Tests would be nice
So, this may be an AnkiConnect bug. It may be due to my version of Anki. Not sure yet. Anki 2.1.38 on Windows
The Anki main window, main view HTML hides and is no longer shown. Doesn't seem to have any other impact on function but I am unable to get it to show and have to close Anki to fix the bug.
On Send, if the Anki Card brower is open and the review screen is on "Congratulations you have completed this deck for now", it will cause the Anki main window HTML to hide.
anki:Version 2.1.38 (355e4cd5)
vscod: 1.54.3 (Universal)
anki connect: AnkiConnect 0.01MB. Updated 2021-03-07.
markdown file
# Vscode to Anki Test
## How to use Vscod to anki?
don't know
## fdsafdsa ?
???
info log
{
"label": "Anki for VSCode",
"level": "info",
"message": "active Editor..",
"time": "2020-08-10 13:17:32.838Z"
}
{
"label": "Anki for VSCode",
"level": "info",
"message": "{\"action\":\"createDeck\",\"version\":6,\"params\":{\"deck\":\"notes\"}}",
"time": "2020-08-10 13:17:32.853Z"
}
{
"label": "Anki for VSCode",
"level": "info",
"message": "{\"action\":\"addNotes\",\"version\":6,\"params\":{\"notes\":[{\"deckName\":\"notes\",\"modelName\":\"BasicWithHighlightVSCode\",\"options\":{\"allowDuplicate\":false,\"duplicateScope\":\"deck\"},\"fields\":{\"Front\":\"<h2 id=\\\"how-to-use-vscod-to-anki\\\">How to use Vscod to anki?</h2>\\n\",\"Back\":\"<p>don't know</p>\\n\"},\"tags\":[\"Vscode_to_Anki_Test\"]},{\"deckName\":\"notes\",\"modelName\":\"BasicWithHighlightVSCode\",\"options\":{\"allowDuplicate\":false,\"duplicateScope\":\"deck\"},\"fields\":{\"Front\":\"<h2 id=\\\"fdsafdsa-\\\">fdsafdsa ?</h2>\\n\",\"Back\":\"<p>wtf</p>\\n\"},\"tags\":[\"Vscode_to_Anki_Test\"]}]}}",
"time": "2020-08-10 13:17:33.059Z"
}
It would be nice to be able to create cards with a custom model and templates. The default ones in Anki are pretty limited: "Basic" cards have only two fields ("Front" and "Back"), while "Cloze" cards just one.
Perhaps the greatest strength of Anki is the ability to define a new card model with a customized set of fields. For example, I can define a new model "Model1" with 4 fields "A", "B", "C" and "D". Then templates define how to construct real cards using these fields. For example the template "Card1" assigns field "A" and "B" to the front, and "C" to the back; while template "Card2" assigns field "D" to the front and "A" to the back. So, every time I use the model "Model1" and specify a concrete value for the 4 fields (i.e. I write a "fact"), Anki automatically generates two cards by compiling the two templates.
In addition, I often use custom CSS and JS inside templates, especially for adding MathJax macros.
Theoretically, this could be done by using AnkiConnect API, as can be seen here.
One possibility would be to define a set of models (with their templates) in the extension's configuration. At the start of a markdown file, the model to be used is specified, and it is created through the AnkiConnect API, if a model with the same name and the same number of fields does not already exist (maybe this could be done once after changing configuration, and not every time cards are sent).
Then a way to correctly parse the required fields is needed. Maybe the simplest way would be to define a fixed "separator" (configurable?) to distinguish fields, since there could be any number of them. The standard h2 titles can be used to distinguish different cards in the same file.
A possible example:
# DeckName {model:ModelName}
## First card
Field A
{separator}
Field B
{separator}
Field C
{separator}
Field D
## Second card
...
Maybe there is a way to avoid additional parsing in the markdown, e.g. a prompt for the card model when sending the markdown to Anki, or some other way to distinguish different fields.
I have been using this add-on successfully for few times. Now it has only reinstall and sync available, other commands that push to the deck are not available.
What have I done to debug:
Any suggestions on how I can debug this will be very helpful.
System info:
OS: PopOS
VS Code version: 1.62.3
notion2anki uses toggles to separate questions from answers. I use the same pattern in VSCode using folds to test myself from VSCode. Allowing the same format to export to Anki would be awesome, thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.