Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# data.json need save
./data.json
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
185 changes: 53 additions & 132 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,132 +1,53 @@
# Obsidian_to_Anki
Plugin to add flashcards from a text or markdown file to Anki. Run in Obsidian as a plugin, or from the command-line as a python script. Built with [Obsidian](https://obsidian.md/) markdown syntax in mind. Supports **user-defined custom syntax for flashcards.**
See the [Trello](https://trello.com/b/6MXEizGg/obsidiantoanki) for planned features.

## Getting started

Check out the [Wiki](https://github.com/Pseudonium/Obsidian_to_Anki/wiki)! It has a ton of information, including setup instructions for new users. I will include a copy of the instructions here:

## Setup

### All users
1. Start up [Anki](https://apps.ankiweb.net/), and navigate to your desired profile.
2. Ensure that you've installed [AnkiConnect](https://git.foosoft.net/alex/anki-connect).

### Obsidian plugin users
3. Have [Obsidian](https://obsidian.md/) downloaded
4. Search the 'Community plugins' list for this plugin
5. Install the plugin.
6. In Anki, navigate to Tools->Addons->AnkiConnect->Config, and change it to look like this:
<pre>
{
"apiKey": null,
"apiLogPath": null,
"webBindAddress": "127.0.0.1",
"webBindPort": 8765,
"webCorsOrigin": "http://localhost",
"webCorsOriginList": [
"http://localhost",
"app://obsidian.md"
]
}
</pre>

7. Restart Anki to apply the above changes
8. With Anki running in the background, load the plugin. This will generate the plugin settings.


You shouldn't need Anki running to load Obsidian in the future, though of course you will need it for using the plugin!

To run the plugin, look for an Anki icon on your ribbon (the place where buttons such as 'open Graph view' and 'open Quick Switcher' are).
For more information on use, please check out the [Wiki](https://github.com/Pseudonium/Obsidian_to_Anki/wiki)!

### Python script users
3. Install the latest version of [Python](https://www.python.org/downloads/).
4. If you are a new user, download `obstoanki_setup.py` from the [releases page](https://github.com/Pseudonium/Obsidian_to_Anki/releases), and place it in the folder you want the script installed (for example your notes folder).
5. Run `obstoanki_setup.py`, for example by double-clicking it in a file explorer. This will download the latest version of the script and required dependencies automatically. Existing users should be able to run their existing `obstoanki_setup.py` to get the latest version of the script.
6. Check the Permissions tab below to ensure the script is able to run.
7. Run `obsidian_to_anki.py`, for example by double-clicking it in a file explorer. This will generate a config file, `obsidian_to_anki_config.ini`.

#### Permissions
The script needs to be able to:
* Make a config file in the directory the script is installed.
* Read the file in the directory the script is used.
* Make a backup file in the directory the script is used.
* Rename files in the directory the script is used.
* Remove a backup file in the directory the script is used.
* Change the current working directory temporarily (so that local image paths are resolved correctly).

## Features

Current features (check out the wiki for more details):
* **Custom note types** - You're not limited to the 6 built-in note types of Anki.
* **Custom scan directory**
* The plugin will scan the entire vault by default
* You can also set which directory (includes all sub-directories as well) to scan via plugin settings
* **Ignore Folders and Files**
* You can specify which files and folders to ignore
* This can be done in the settings of this plugin with [Glob syntax](https://en.wikipedia.org/wiki/Glob_(programming)#Syntax).
* If you're working on your own globs, you can test them out [here](https://globster.xyz/)
* Examples:
* `**/*.excalidraw.md` - Ignore all files that end in `.excalidraw.md`
* => avoids excalidraw files from being scanned which can be extremely slow
* `Template/**` - Ignore all files in the `Template` folder (including subfolders)
* `**/private/**` - Ignore all files in folders that are called `private` no matter where they are in the vault
* `[Pp]rivate*/**` - Ignore all files and folders in the root of the vault that start with `private` or with `Private`
* **Updating notes from file** - Your text files are the canonical source of the notes.
* **Tags**, including **tags for an entire file**.
* **Adding to user-specified deck** on a *per-file* basis.
* **Markdown formatting**.
* **Math formatting**.
* **Embedded images**. GIFs should work too.
* **Audio**.
* **Auto-deleting notes from the file**.
* **Reading from all files in a directory automatically** - recursively too!
* **Inline Notes** - Shorter syntax for typing out notes on a single line.
* **Easy cloze formatting** - A more compact syntax to do Cloze text
* **Frozen Fields**
* **Obsidian integration** - A link to the file that made the flashcard, full link and image embed support.
* **Custom syntax** - Using **regular expressions**, add custom syntax to generate **notes that make sense for you.** Some examples:
* RemNote single-line style. `This is how to use::Remnote single-line style`
![Remnote 1](Images/Remnote_1.png)
* Header paragraph style.
<pre>
# Style
This style is suitable for having the header as the front, and the answer as the back
</pre>
![Header 1](Images/Header_1.png)
* Question answer style.
<pre>
Q: How do you use this style?
A: Just like this.
</pre>
![Question 1](Images/Question_1.png)
* Neuracache #flashcard style.
<pre>
In Neuracache style, to make a flashcard you do #flashcard
The next lines then become the back of the flashcard
</pre>
![Neuracache 1](Images/Neuracache_1.png)
* Ruled style
<pre>
How do you use ruled style?
---
You need at least three '-' between the front and back of the card.
</pre>
![Ruled 1](Images/Ruled_1.png)
* Markdown table style
<pre>
| Why might this style be useful? |
| ------ |
| It looks nice when rendered as HTML in a markdown editor. |
</pre>
![Table 2](Images/Table_2.png)
* Cloze paragraph style
<pre>
The idea of {cloze paragraph style} is to be able to recognise any paragraphs that contain {cloze deletions}.
</pre>
![Cloze 1](Images/Cloze_1.png)

Note that **all custom syntax is off by default**, and must be programmed into the script via the config file - see the Wiki for more details.

<a href='https://ko-fi.com/K3K52X4L6' target='_blank'><img height='36' style='border:0px;height:36px;' src='https://cdn.ko-fi.com/cdn/kofi1.png?v=2' border='0' alt='Buy Me a Coffee at ko-fi.com' /></a>
# 简介
本项目由 [Obsidian_to_Anki](https://github.com/Pseudonium/Obsidian_to_Anki) fork而来
在原来代码的基础上,添加一些功能
1. 让obsidian markdown文件中的卡片在anki的deck的结构与文件夹结构保存一致
例如:"/root/hello/world.md"中的卡片会自动同步到"root::hello::world"中
2. 把id修改为blockid的形式,从而实现anki直接跳转到obsidian markdown文件对应的block
![图 1](images/5913712e835c128fdc7a12c0c0c1caa006ac7d47bf85a3a9f6c5970e37a0a948.png)
3. 优化了context的内容,路径和标题加在最前面,以换行分割,后面有一行分割线和卡片具体内容区分。标题中如果有链接或公式可以转化成功。
4. 对于卡片中对blockid的引用链接,自动转化为anki link插件支持的格式`[link test|nid1714433449297]`
5. 优化了$的识别。现在\\\$不会识别为公式,会转化为\$。修改的格式化的顺序。现在先处理代码的部分。所以代码中出现\$不会识别为latex
# 本项目使用方法
将main.js和manifes.json文件替换obsidian to anki中的main.js manifes.json
在插件设置中,开启设置,并重启obsidian
具体的使用方法可以参考[Obsidian_to_Anki](https://github.com/Pseudonium/Obsidian_to_Anki)

原来的正则表达式`(?<!<!--)`改为`(?<!<!--)(?<!\^ID-)`即可正常使用blockid

# todo
优化数学公式的转化,保证`}}`能够正常显示
修复bug,行末链接会导致卡片无法导入
修复bug,markdown文件过长会导致卡片无法正常导入
优化hash算法或者加入当前文件必定扫描,如果文件过长,修改了文件靠后的内容,不会识别到文件修改,除非后半部分改动很大
优化有时候一些卡片无法识别到bug 跳过的范围存在问题
添加代码形式的卡片
```anki
font
---
back
```
# \$失效的场景
`M` : Block math mode. Only run this snippet inside a `$$ ... $$` block
`M` :块数学模式。仅在 `$$ ... $$` 块内运行此代码段
- `n` : Inline math mode. Only run this snippet inside a `$ ... $` block
`n` :内联数学模式。仅在 `$ ... $` 块内运行此代码段

![](image.png)
识别blockid失败

# tip
填空题存在问题,可能会匹配bookxnote和latex公式,请使用"((?:.+\n)*(?:.*{{c.*)(?:\n(?:^.{1,3}$|^.{4}(?<!<!--).*))*)",
并只使用{{c\d:: text }}格式的填空题
推荐搭配latex-suite快速输入
# Introduction
This project was forked by [Obsidian_to_Anki](https://github.com/Pseudonium/Obsidian_to_Anki) Based on the original code, two features have been added
1. Let the cards in the Obsidian markdown file be synchronized with the folder structure in the anki. For example, cards in "/root/hello/world.md" will be automatically synchronized to "root::hello::world".

2.Change the id to a block link so that anki jumps directly to the corresponding block in the obsidian markdown file.
![图 2](images/1cfcb1bb28a06e354b339691fe79a5d40c32ac3d8d74a0c1a5fd1b4f554e201a.png)

# How to use
Replace the main.js and manifes.json file with the main.js and manifes.json in Obsidian to Anki
In the plugin settings, turn on the settings and restart obsidian
For details, please refer to [Obsidian_to_Anki](https://github.com/Pseudonium/Obsidian_to_Anki).
Loading