pradhyo / anki-markdown-notes Goto Github PK
View Code? Open in Web Editor NEWAnki add-on to extract notes from markdown files and import them to Anki
Home Page: https://ankiweb.net/shared/info/2141874715
License: MIT License
Anki add-on to extract notes from markdown files and import them to Anki
Home Page: https://ankiweb.net/shared/info/2141874715
License: MIT License
Using Anki 2.0.52 and installing add-on using the ID through the Anki UI, I cannot get the existing notes exported using Tools > Export to Markdown Notes. The resulting file that is created is empty except for a level-1 heading with the name of the deck. (There is also a file called Default.md but I expected that to be empty because its the dummy deck that Anki provides before you create a deck of your own.)
Any chance you can point me in the right direction to fixing this? Not sure how to get to a debug console in Anki but if there is one available, I'm happy to provide the output that prints when I try to export to markdown...
Thanks!
Having used this for a bit, I tend to leave out context in the questions in my markdown notes because of the file name and everything surrounding the questions but this gets confusing without tags in anki
Since #2 doesn't let me delete notes directly from the app, deleting a note (remove completely or just the ID and Q: and A: parts) from the markdown files should delete it from Anki when importing again.
I installed the plugin through Anki's own specific menu. Since then, I receive the following error message each time I open Anki:
An error occurred in an add-on.
Please post on the add-on forum:
https://anki.tenderapp.com/discussions/add-onsTraceback (most recent call last): File "aqt/addons.py", line 41, in loadAddons File "/home/andras/.local/share/Anki2/addons/Anki_Markdown_Notes.py", line 6, in <module> from glob import glob ImportError: No module named glob
It has been already reported here: https://anki.tenderapp.com/discussions/add-ons/16903-error-with-markdown-addon
I checked, and I have glob2
installed:
>>> ~$ pip list | grep glob
glob2 0.6
Neither the following console command yields any error:
from glob import glob
An error occurred in an add-on.
Please post on the add-on forum:
https://anki.tenderapp.com/discussions/add-ons
Traceback (most recent call last):
File "aqt\addons.py", line 41, in loadAddons
File "C:\Users\User\AppData\Roaming\Anki2\addons\Anki_Markdown_Notes.py", line 8 , in
from logging.handlers import RotatingFileHandler
ImportError: No module named handlers
Based on the documentation, this shouldn't be too difficult.
Hi @Pradhyo - thanks for creating and maintaining this add on. I ran into a fail when trying to export my existing decks to Markdown. Here's the error:
An error occurred in an add-on.
Please post on the add-on forum:
https://anki.tenderapp.com/discussions/add-ons
Traceback (most recent call last):
File "/Users/alexcthompson/Library/Application Support/Anki2/addons/anki-markdown.py", line 271, in exportNotesUI
exportedDecks = exportAllNotes(NotesPath)
File "/Users/alexcthompson/Library/Application Support/Anki2/addons/anki-markdown.py", line 238, in exportAllNotes
writeNote(note)
File "/Users/alexcthompson/Library/Application Support/Anki2/addons/anki-markdown.py", line 226, in writeNote
deckFile.write("A: {}\n".format(note.fields[1].replace("<br>", "\n")))
UnicodeEncodeError: 'ascii' codec can't encode characters in position 198-199: ordinal not in range(128)
I think we're dealing with a classic Python unicode problem here. My hunch, having done absolutely zero investigation is that L226
in anki-markdown.py
, by creating a format string, is casting some unicode characters to utf-8 badly, creating this error. Using my Stackoverflow spidey sense, I wonder if this answer might resolve the issue.
Debug info:
Anki 2.1.33 (3f403040) Python 3.8.0 Qt 5.14.1 PyQt 5.14.1
Platform: Windows 10
Flags: frz=True ao=True sv=1
Add-ons, last update check: 2022-01-31 11:46:14
Caught exception:
Traceback (most recent call last):
File "C:\Users\User\AppData\Roaming\Anki2\addons21\2141874715_init_.py", line 317, in exportNotesUI
exportedDecks = exportAllNotes(NotesPath)
File "C:\Users\User\AppData\Roaming\Anki2\addons21\2141874715_init_.py", line 279, in exportAllNotes
os.makedirs(deckFolder)
File "os.py", line 221, in makedirs
OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: 'C:/Users/User/Documents/Obsidian/Vault/Notes\Notes\Default::Nested
I think what's going on is that nested decks are named "parent::deckname", but windows doesn't allow colons in filenames.
So when you set deckFolder
to os.path.join(NotesPath, deck)
where deck
has double colons, everything is fine. But in the next line when you try to create a folder with that name, Windows forbids that and the error is thrown.
This is the exportAllNotes function that the bug is in:
def exportAllNotes(NotesPath):
"""
Exports all notes to markdown files in a Notes folder in 'NotesPath'.
Aborts if 'Notes' folder already exists.
For deck 'DeckName', a folder 'DeckName' is created and all the notes
in that deck are stored in 'DeckName.md' in that folder.
"""
showInfo("Logs are located here - " + directory)
NotesPath = os.path.join(NotesPath, "Notes")
if os.path.exists(NotesPath):
showInfo("Aborting - 'Notes' folder already exists")
return
os.makedirs(NotesPath)
allDecks = mw.col.decks.allNames()
for deck in allDecks:
deckFolder = os.path.join(NotesPath, deck)
os.makedirs(deckFolder)
with open(os.path.join(deckFolder, deck + ".md"), "w") as deckFile:
deckFile.write("# {} \n\n".format(deck))
for cid in mw.col.findNotes("deck:" + deck):
note = mw.col.getNote(cid)
writeNote(note, deckFile)
return allDecks`
Consider the markdown notes as the source of truth.
Deleting a note from the Anki app was throwing an error when importing notes again because that note with the ID from the markdown comment was not found anymore. Fix this by adding these notes again with the same ID.
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.