Compare commits
No commits in common. "48a803f8f3efa761b686f956aec03583ddd605c4" and "cce8bf0f767abc36dcda518b3fc6627661e74b15" have entirely different histories.
48a803f8f3
...
cce8bf0f76
1
.gitignore
vendored
1
.gitignore
vendored
@ -119,4 +119,3 @@ README.txt
|
|||||||
|
|
||||||
# idea ide
|
# idea ide
|
||||||
/.idea
|
/.idea
|
||||||
*.lnk
|
|
||||||
|
|||||||
@ -1,487 +0,0 @@
|
|||||||
# 单元音
|
|
||||||
## [ɑ:]
|
|
||||||
### tags
|
|
||||||
- 长元音
|
|
||||||
### imgs
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
### words
|
|
||||||
- car
|
|
||||||
- glass
|
|
||||||
|
|
||||||
## [ʌ]
|
|
||||||
### tags
|
|
||||||
- 短元音
|
|
||||||
### imgs
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
### words
|
|
||||||
- bus
|
|
||||||
- mother
|
|
||||||
|
|
||||||
## [ɔ:]
|
|
||||||
### tags
|
|
||||||
- 长元音
|
|
||||||
### imgs
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
### words
|
|
||||||
- ball
|
|
||||||
- horse
|
|
||||||
|
|
||||||
## [ɒ]
|
|
||||||
### tags
|
|
||||||
- 短元音
|
|
||||||
### imgs
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
### words
|
|
||||||
- dog
|
|
||||||
- wash
|
|
||||||
|
|
||||||
## [ɜ:]
|
|
||||||
### tags
|
|
||||||
- 长元音
|
|
||||||
### imgs
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
### words
|
|
||||||
- bird
|
|
||||||
- nurse
|
|
||||||
|
|
||||||
## [ə]
|
|
||||||
### tags
|
|
||||||
- 短元音
|
|
||||||
### imgs
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
### words
|
|
||||||
- tiger
|
|
||||||
- sofa
|
|
||||||
## [i:]
|
|
||||||
### tags
|
|
||||||
- 长元音
|
|
||||||
### imgs
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
### words
|
|
||||||
- bee
|
|
||||||
- sea
|
|
||||||
|
|
||||||
## [ɪ]
|
|
||||||
### tags
|
|
||||||
- 短元音
|
|
||||||
### imgs
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
### words
|
|
||||||
- pig
|
|
||||||
- kid
|
|
||||||
|
|
||||||
## [u:]
|
|
||||||
### tags
|
|
||||||
- 长元音
|
|
||||||
### imgs
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
### words
|
|
||||||
- school
|
|
||||||
- shoe
|
|
||||||
|
|
||||||
## [ʊ]
|
|
||||||
### tags
|
|
||||||
- 短元音
|
|
||||||
### imgs
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
### words
|
|
||||||
- book
|
|
||||||
- foot
|
|
||||||
|
|
||||||
## [æ]
|
|
||||||
### tags
|
|
||||||
- 短元音
|
|
||||||
### imgs
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
### words
|
|
||||||
- cat
|
|
||||||
- bag
|
|
||||||
|
|
||||||
## [e]
|
|
||||||
### tags
|
|
||||||
- 短元音
|
|
||||||
### imgs
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
### words
|
|
||||||
- bed
|
|
||||||
- head
|
|
||||||
|
|
||||||
# 双元音
|
|
||||||
## [aɪ]
|
|
||||||
### tags
|
|
||||||
- [ɪ]结尾
|
|
||||||
### imgs
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
### words
|
|
||||||
- eye
|
|
||||||
- rice
|
|
||||||
## [eɪ]
|
|
||||||
### tags
|
|
||||||
- [ɪ]结尾
|
|
||||||
### imgs
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
### words
|
|
||||||
- cake
|
|
||||||
- rain
|
|
||||||
## [ɔɪ]
|
|
||||||
### tags
|
|
||||||
- [ɪ]结尾
|
|
||||||
### imgs
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
### words
|
|
||||||
- boy
|
|
||||||
- toy
|
|
||||||
## [ɪə]
|
|
||||||
### tags
|
|
||||||
- [ə]结尾
|
|
||||||
### imgs
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
### words
|
|
||||||
- ear
|
|
||||||
- hear
|
|
||||||
## [eə]
|
|
||||||
### tags
|
|
||||||
- [ə]结尾
|
|
||||||
### imgs
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
### words
|
|
||||||
- pear
|
|
||||||
- bear
|
|
||||||
## [ʊə]
|
|
||||||
### tags
|
|
||||||
- [ə]结尾
|
|
||||||
### imgs
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
### words
|
|
||||||
- tour
|
|
||||||
- poor
|
|
||||||
## [aʊ]
|
|
||||||
### tags
|
|
||||||
- [ʊ]结尾
|
|
||||||
### imgs
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
### words
|
|
||||||
- cow
|
|
||||||
- house
|
|
||||||
## [əʊ]
|
|
||||||
### tags
|
|
||||||
- [ʊ]结尾
|
|
||||||
### imgs
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
### words
|
|
||||||
- coat
|
|
||||||
- snow
|
|
||||||
|
|
||||||
# 爆破音
|
|
||||||
## [p]
|
|
||||||
### tags
|
|
||||||
- 清辅音
|
|
||||||
### imgs
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
### words
|
|
||||||
- park
|
|
||||||
- sleep
|
|
||||||
|
|
||||||
## [b]
|
|
||||||
### tags
|
|
||||||
- 浊辅音
|
|
||||||
### imgs
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
### words
|
|
||||||
- baby
|
|
||||||
- rubber
|
|
||||||
|
|
||||||
## [t]
|
|
||||||
### tags
|
|
||||||
- 清辅音
|
|
||||||
### imgs
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
### words
|
|
||||||
- tea
|
|
||||||
- boat
|
|
||||||
|
|
||||||
## [d]
|
|
||||||
### tags
|
|
||||||
- 浊辅音
|
|
||||||
### imgs
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
### words
|
|
||||||
- door
|
|
||||||
- red
|
|
||||||
|
|
||||||
## [k]
|
|
||||||
### tags
|
|
||||||
- 清辅音
|
|
||||||
### imgs
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
### words
|
|
||||||
- cap
|
|
||||||
- milk
|
|
||||||
|
|
||||||
## [g]
|
|
||||||
### tags
|
|
||||||
- 浊辅音
|
|
||||||
### imgs
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
### words
|
|
||||||
- go
|
|
||||||
- egg
|
|
||||||
|
|
||||||
# 摩擦音
|
|
||||||
## [f]
|
|
||||||
### tags
|
|
||||||
- 清辅音
|
|
||||||
### imgs
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
### words
|
|
||||||
- fish
|
|
||||||
- phone
|
|
||||||
|
|
||||||
## [v]
|
|
||||||
### tags
|
|
||||||
- 浊辅音
|
|
||||||
### imgs
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
### words
|
|
||||||
- river
|
|
||||||
- five
|
|
||||||
|
|
||||||
## [s]
|
|
||||||
### tags
|
|
||||||
- 清辅音
|
|
||||||
### imgs
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
### words
|
|
||||||
- sun
|
|
||||||
- ice
|
|
||||||
|
|
||||||
## [z]
|
|
||||||
### tags
|
|
||||||
- 浊辅音
|
|
||||||
### imgs
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
### words
|
|
||||||
- zoo
|
|
||||||
- nose
|
|
||||||
|
|
||||||
## [ʃ]
|
|
||||||
### tags
|
|
||||||
- 清辅音
|
|
||||||
### imgs
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
### words
|
|
||||||
- sheep
|
|
||||||
- shirt
|
|
||||||
|
|
||||||
## [ʒ]
|
|
||||||
### tags
|
|
||||||
- 浊辅音
|
|
||||||
### imgs
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
### words
|
|
||||||
- television
|
|
||||||
- measure
|
|
||||||
|
|
||||||
## [θ]
|
|
||||||
### tags
|
|
||||||
- 清辅音
|
|
||||||
### imgs
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
### words
|
|
||||||
- tooth
|
|
||||||
- three
|
|
||||||
|
|
||||||
## [ð]
|
|
||||||
### tags
|
|
||||||
- 浊辅音
|
|
||||||
### imgs
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
### words
|
|
||||||
- they
|
|
||||||
- father
|
|
||||||
|
|
||||||
## [h]
|
|
||||||
### tags
|
|
||||||
- 清辅音
|
|
||||||
### imgs
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
### words
|
|
||||||
- hair
|
|
||||||
- who
|
|
||||||
|
|
||||||
## [r]
|
|
||||||
### tags
|
|
||||||
- 浊辅音
|
|
||||||
### imgs
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
### words
|
|
||||||
- rose
|
|
||||||
- write
|
|
||||||
|
|
||||||
# 破擦音
|
|
||||||
## [tʃ]
|
|
||||||
### tags
|
|
||||||
- 清辅音
|
|
||||||
### imgs
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
### words
|
|
||||||
- chair
|
|
||||||
- watch
|
|
||||||
|
|
||||||
## [dʒ]
|
|
||||||
### tags
|
|
||||||
- 浊辅音
|
|
||||||
### imgs
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
### words
|
|
||||||
- jeep
|
|
||||||
- cage
|
|
||||||
|
|
||||||
## [tr]
|
|
||||||
### tags
|
|
||||||
- 清辅音
|
|
||||||
### imgs
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
### words
|
|
||||||
- tree
|
|
||||||
- train
|
|
||||||
|
|
||||||
## [dr]
|
|
||||||
### tags
|
|
||||||
- 浊辅音
|
|
||||||
### imgs
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
### words
|
|
||||||
- dress
|
|
||||||
- draw
|
|
||||||
|
|
||||||
## [ts]
|
|
||||||
### tags
|
|
||||||
- 清辅音
|
|
||||||
### imgs
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
### words
|
|
||||||
- chair
|
|
||||||
- warch
|
|
||||||
|
|
||||||
## [tz]
|
|
||||||
### tags
|
|
||||||
- 浊辅音
|
|
||||||
### imgs
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
### words
|
|
||||||
- hands
|
|
||||||
- cards
|
|
||||||
|
|
||||||
# 发鼻音
|
|
||||||
## [m]
|
|
||||||
### tags
|
|
||||||
- 浊辅音
|
|
||||||
### imgs
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
### words
|
|
||||||
- map
|
|
||||||
- summer
|
|
||||||
|
|
||||||
## [n]
|
|
||||||
### tags
|
|
||||||
- 浊辅音
|
|
||||||
### imgs
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
### words
|
|
||||||
- night
|
|
||||||
- pen
|
|
||||||
|
|
||||||
## [ŋ]
|
|
||||||
### tags
|
|
||||||
- 浊辅音
|
|
||||||
### imgs
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
### words
|
|
||||||
- bank
|
|
||||||
- sing
|
|
||||||
|
|
||||||
# 舌侧音
|
|
||||||
## [I]
|
|
||||||
### tags
|
|
||||||
- 浊辅音
|
|
||||||
### imgs
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
### words
|
|
||||||
- leg
|
|
||||||
- table
|
|
||||||
|
|
||||||
# 半元音
|
|
||||||
## [w]
|
|
||||||
### tags
|
|
||||||
- 浊辅音
|
|
||||||
### imgs
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
### words
|
|
||||||
- water
|
|
||||||
- white
|
|
||||||
|
|
||||||
## [j]
|
|
||||||
### tags
|
|
||||||
- 浊辅音
|
|
||||||
### imgs
|
|
||||||
- 
|
|
||||||
- 
|
|
||||||
### words
|
|
||||||
- yes
|
|
||||||
- yellow
|
|
||||||
@ -1,150 +0,0 @@
|
|||||||
{
|
|
||||||
"cells": [
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": 1,
|
|
||||||
"id": "cf4f95a8",
|
|
||||||
"metadata": {},
|
|
||||||
"outputs": [],
|
|
||||||
"source": [
|
|
||||||
"from service import *"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": 2,
|
|
||||||
"id": "d77ecb1b",
|
|
||||||
"metadata": {},
|
|
||||||
"outputs": [
|
|
||||||
{
|
|
||||||
"name": "stdout",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"a filename was not supplied (nor was the CookieJar instance initialised with one) failed load cookie_file\n"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"data": {
|
|
||||||
"text/plain": [
|
|
||||||
"{'result': ['Git', '句素', '示例牌组', '系统默认', '英语', '音标'], 'error': None}"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"execution_count": 2,
|
|
||||||
"metadata": {},
|
|
||||||
"output_type": "execute_result"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"source": [
|
|
||||||
"s = Session()\n",
|
|
||||||
"anki = AnkiClient(s)\n",
|
|
||||||
"anki.make_version()\n",
|
|
||||||
"anki.deckNames()"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": 68,
|
|
||||||
"id": "d13272f8",
|
|
||||||
"metadata": {},
|
|
||||||
"outputs": [
|
|
||||||
{
|
|
||||||
"data": {
|
|
||||||
"text/plain": [
|
|
||||||
"{'result': ['Basic', '单词卡', '句素卡', '选择卡', '音标'], 'error': None}"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"execution_count": 68,
|
|
||||||
"metadata": {},
|
|
||||||
"output_type": "execute_result"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"source": [
|
|
||||||
"anki.modelNames()"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": 69,
|
|
||||||
"id": "b118fa48",
|
|
||||||
"metadata": {},
|
|
||||||
"outputs": [
|
|
||||||
{
|
|
||||||
"data": {
|
|
||||||
"text/plain": [
|
|
||||||
"{'result': ['word',\n",
|
|
||||||
" 'pronounce',\n",
|
|
||||||
" 'audio',\n",
|
|
||||||
" 'eg.',\n",
|
|
||||||
" 'Header',\n",
|
|
||||||
" 'sentences',\n",
|
|
||||||
" 'synonym',\n",
|
|
||||||
" 'part_of_speech',\n",
|
|
||||||
" 'meanEng',\n",
|
|
||||||
" 'meanEngLong',\n",
|
|
||||||
" 'picture'],\n",
|
|
||||||
" 'error': None}"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"execution_count": 69,
|
|
||||||
"metadata": {},
|
|
||||||
"output_type": "execute_result"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"source": [
|
|
||||||
"anki.modelFieldNames(\"单词卡\")"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": 65,
|
|
||||||
"id": "3a15fe88",
|
|
||||||
"metadata": {},
|
|
||||||
"outputs": [
|
|
||||||
{
|
|
||||||
"data": {
|
|
||||||
"text/plain": [
|
|
||||||
"{'result': 1692201363325, 'error': None}"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"execution_count": 65,
|
|
||||||
"metadata": {},
|
|
||||||
"output_type": "execute_result"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"source": [
|
|
||||||
"note = {\n",
|
|
||||||
" \"word\":'[ʌ]'\n",
|
|
||||||
"}\n",
|
|
||||||
"param = {\n",
|
|
||||||
" \"deckName\": \"音标\",\n",
|
|
||||||
" \"modelName\": \"单词卡\",\n",
|
|
||||||
" \"options\": { \"allowDuplicate\": False },\n",
|
|
||||||
" \"fields\": note,\n",
|
|
||||||
" \"tags\": ['单元音', '短元音']\n",
|
|
||||||
"}\n",
|
|
||||||
"anki.addNote(param)"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"metadata": {
|
|
||||||
"kernelspec": {
|
|
||||||
"display_name": "Python 3 (ipykernel)",
|
|
||||||
"language": "python",
|
|
||||||
"name": "python3"
|
|
||||||
},
|
|
||||||
"language_info": {
|
|
||||||
"codemirror_mode": {
|
|
||||||
"name": "ipython",
|
|
||||||
"version": 3
|
|
||||||
},
|
|
||||||
"file_extension": ".py",
|
|
||||||
"mimetype": "text/x-python",
|
|
||||||
"name": "python",
|
|
||||||
"nbconvert_exporter": "python",
|
|
||||||
"pygments_lexer": "ipython3",
|
|
||||||
"version": "3.9.12"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"nbformat": 4,
|
|
||||||
"nbformat_minor": 5
|
|
||||||
}
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
from .anki_tree import *
|
|
||||||
from .anki_renderer import *
|
|
||||||
__all__ = ['AnkiRenderer']
|
|
||||||
@ -1,173 +0,0 @@
|
|||||||
from typing import Dict, Any
|
|
||||||
from mistune import BaseRenderer, BlockState
|
|
||||||
from .anki_tree import AnkiData
|
|
||||||
# 自定义渲染器来提取标题
|
|
||||||
class AnkiRenderer(BaseRenderer):
|
|
||||||
"""A renderer to re-format Markdown text."""
|
|
||||||
NAME = 'anki'
|
|
||||||
def __init__(self):
|
|
||||||
BaseRenderer.__init__(self)
|
|
||||||
self.anki = AnkiData()
|
|
||||||
def __call__(self, tokens, state: BlockState):
|
|
||||||
self.tokens = tokens
|
|
||||||
self.state = state
|
|
||||||
out = self.render_tokens(tokens, state)
|
|
||||||
# special handle for line breaks
|
|
||||||
out += '\n\n'.join(self.render_referrences(state)) + '\n'
|
|
||||||
return out
|
|
||||||
|
|
||||||
def render_referrences(self, state: BlockState):
|
|
||||||
ref_links = state.env['ref_links']
|
|
||||||
for key in ref_links:
|
|
||||||
attrs = ref_links[key]
|
|
||||||
text = '[' + attrs['label'] + ']: ' + attrs['url']
|
|
||||||
title = attrs.get('title')
|
|
||||||
if title:
|
|
||||||
text += ' "' + title + '"'
|
|
||||||
yield text
|
|
||||||
|
|
||||||
def render_children(self, token, state: BlockState):
|
|
||||||
children = token['children']
|
|
||||||
return self.render_tokens(children, state)
|
|
||||||
|
|
||||||
def text(self, token: Dict[str, Any], state: BlockState) -> str:
|
|
||||||
return token['raw']
|
|
||||||
|
|
||||||
def emphasis(self, token: Dict[str, Any], state: BlockState) -> str:
|
|
||||||
return '*' + self.render_children(token, state) + '*'
|
|
||||||
|
|
||||||
def strong(self, token: Dict[str, Any], state: BlockState) -> str:
|
|
||||||
return '**' + self.render_children(token, state) + '**'
|
|
||||||
|
|
||||||
def link(self, token: Dict[str, Any], state: BlockState) -> str:
|
|
||||||
label = token.get('label')
|
|
||||||
text = self.render_children(token, state)
|
|
||||||
out = '[' + text + ']'
|
|
||||||
if label:
|
|
||||||
return out + '[' + label + ']'
|
|
||||||
|
|
||||||
attrs = token['attrs']
|
|
||||||
url = attrs['url']
|
|
||||||
title = attrs.get('title')
|
|
||||||
if text == url and not title:
|
|
||||||
return '<' + text + '>'
|
|
||||||
elif 'mailto:' + text == url and not title:
|
|
||||||
return '<' + text + '>'
|
|
||||||
|
|
||||||
out += '('
|
|
||||||
if '(' in url or ')' in url:
|
|
||||||
out += '<' + url + '>'
|
|
||||||
else:
|
|
||||||
out += url
|
|
||||||
if title:
|
|
||||||
out += ' "' + title + '"'
|
|
||||||
return out + ')'
|
|
||||||
|
|
||||||
def image(self, token: Dict[str, Any], state: BlockState) -> str:
|
|
||||||
return '!' + self.link(token, state)
|
|
||||||
|
|
||||||
def codespan(self, token: Dict[str, Any], state: BlockState) -> str:
|
|
||||||
return '`' + token['raw'] + '`'
|
|
||||||
|
|
||||||
def linebreak(self, token: Dict[str, Any], state: BlockState) -> str:
|
|
||||||
return ' \n'
|
|
||||||
|
|
||||||
def softbreak(self, token: Dict[str, Any], state: BlockState) -> str:
|
|
||||||
return '\n'
|
|
||||||
|
|
||||||
def blank_line(self, token: Dict[str, Any], state: BlockState) -> str:
|
|
||||||
return ''
|
|
||||||
|
|
||||||
def inline_html(self, token: Dict[str, Any], state: BlockState) -> str:
|
|
||||||
return token['raw']
|
|
||||||
|
|
||||||
def paragraph(self, token: Dict[str, Any], state: BlockState) -> str:
|
|
||||||
text = self.render_children(token, state)
|
|
||||||
return text + '\n\n'
|
|
||||||
|
|
||||||
def heading(self, token: Dict[str, Any], state: BlockState) -> str:
|
|
||||||
level = token['attrs']['level']
|
|
||||||
marker = '#' * level
|
|
||||||
text = self.render_children(token, state)
|
|
||||||
self.anki.enterScope(text , level)
|
|
||||||
return marker + ' ' + text + '\n\n'
|
|
||||||
|
|
||||||
def thematic_break(self, token: Dict[str, Any], state: BlockState) -> str:
|
|
||||||
return '***\n\n'
|
|
||||||
|
|
||||||
def block_text(self, token: Dict[str, Any], state: BlockState) -> str:
|
|
||||||
return self.render_children(token, state) + '\n'
|
|
||||||
|
|
||||||
def block_code(self, token: Dict[str, Any], state: BlockState) -> str:
|
|
||||||
attrs = token.get('attrs', {})
|
|
||||||
info = attrs.get('info', '')
|
|
||||||
code = token['raw']
|
|
||||||
if code and code[-1] != '\n':
|
|
||||||
code += '\n'
|
|
||||||
|
|
||||||
marker = token.get('marker')
|
|
||||||
if not marker:
|
|
||||||
marker = _get_fenced_marker(code)
|
|
||||||
return marker + info + '\n' + code + marker + '\n\n'
|
|
||||||
|
|
||||||
def block_quote(self, token: Dict[str, Any], state: BlockState) -> str:
|
|
||||||
text = indent(self.render_children(token, state), '> ')
|
|
||||||
return text + '\n\n'
|
|
||||||
|
|
||||||
def block_html(self, token: Dict[str, Any], state: BlockState) -> str:
|
|
||||||
return token['raw'] + '\n\n'
|
|
||||||
|
|
||||||
def block_error(self, token: Dict[str, Any], state: BlockState) -> str:
|
|
||||||
return ''
|
|
||||||
def _render_list_item(self, renderer, parent, item, state):
|
|
||||||
leading = parent['leading']
|
|
||||||
text = ''
|
|
||||||
for tok in item['children']:
|
|
||||||
if tok['type'] == 'list':
|
|
||||||
tok['parent'] = parent
|
|
||||||
elif tok['type'] == 'blank_line':
|
|
||||||
continue
|
|
||||||
text += renderer.render_token(tok, state)
|
|
||||||
|
|
||||||
lines = text.splitlines()
|
|
||||||
text = (lines[0] if lines else '') + '\n'
|
|
||||||
self.anki.appendAttr(lines[0] if lines else '')
|
|
||||||
prefix = ' ' * len(leading)
|
|
||||||
for line in lines[1:]:
|
|
||||||
if line:
|
|
||||||
text += prefix + line + '\n'
|
|
||||||
else:
|
|
||||||
text += '\n'
|
|
||||||
return leading + text
|
|
||||||
def _render_ordered_list(self, renderer, token, state):
|
|
||||||
attrs = token['attrs']
|
|
||||||
start = attrs.get('start', 1)
|
|
||||||
for item in token['children']:
|
|
||||||
leading = str(start) + token['bullet'] + ' '
|
|
||||||
parent = {
|
|
||||||
'leading': leading,
|
|
||||||
'tight': token['tight'],
|
|
||||||
}
|
|
||||||
yield self._render_list_item(renderer, parent, item, state)
|
|
||||||
start += 1
|
|
||||||
def _render_unordered_list(self, renderer, token, state):
|
|
||||||
parent = {
|
|
||||||
'leading': token['bullet'] + ' ',
|
|
||||||
'tight': token['tight'],
|
|
||||||
}
|
|
||||||
for item in token['children']:
|
|
||||||
yield self._render_list_item(renderer, parent, item, state)
|
|
||||||
def list(self, token: Dict[str, Any], state: BlockState) -> str:
|
|
||||||
attrs = token['attrs']
|
|
||||||
if attrs['ordered']:
|
|
||||||
children = self._render_ordered_list(renderer, token, state)
|
|
||||||
else:
|
|
||||||
children = self._render_unordered_list(renderer, token, state)
|
|
||||||
|
|
||||||
text = ''.join(children)
|
|
||||||
parent = token.get('parent')
|
|
||||||
if parent:
|
|
||||||
if parent['tight']:
|
|
||||||
return text
|
|
||||||
return text + '\n'
|
|
||||||
return text + '\n'
|
|
||||||
@ -1,45 +0,0 @@
|
|||||||
class AnkiTree:
|
|
||||||
def __init__(self, name, level, parent = None):
|
|
||||||
self.childList = []
|
|
||||||
self.attrList = []
|
|
||||||
self.name = name
|
|
||||||
self.level = level
|
|
||||||
self.parent = parent
|
|
||||||
pass
|
|
||||||
def push(self, name, level):
|
|
||||||
child = AnkiTree(name, level, self)
|
|
||||||
self.childList.append(child)
|
|
||||||
return child
|
|
||||||
def appendAttr(self, attr):
|
|
||||||
self.attrList.append(attr)
|
|
||||||
class AnkiData:
|
|
||||||
def __init__(self):
|
|
||||||
self.tree = AnkiTree("root", 0)
|
|
||||||
self.node = self.tree
|
|
||||||
pass
|
|
||||||
def parse(self, tree, parent):
|
|
||||||
tags = []
|
|
||||||
tags.append(parent.name)
|
|
||||||
note = {"name":tree.name , "tags":tags}
|
|
||||||
for child in tree.childList:
|
|
||||||
if child.name not in note:
|
|
||||||
note[child.name] = []
|
|
||||||
for attr in child.attrList:
|
|
||||||
note[child.name].append(attr)
|
|
||||||
return note
|
|
||||||
def __call__(self):
|
|
||||||
tree = self.tree
|
|
||||||
note_list = []
|
|
||||||
for child in tree.childList:
|
|
||||||
for child2 in child.childList:
|
|
||||||
note = self.parse(child2, child)
|
|
||||||
note_list.append(note)
|
|
||||||
return note_list
|
|
||||||
def enterScope(self, name, level):
|
|
||||||
while self.node:
|
|
||||||
if self.node.level < level:
|
|
||||||
self.node = self.node.push(name, level)
|
|
||||||
return
|
|
||||||
self.node = self.node.parent
|
|
||||||
def appendAttr(self, attr):
|
|
||||||
self.node.appendAttr(attr)
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
from .http import *
|
|
||||||
from .anki_client import *
|
|
||||||
__all__ = ['AnkiClient', 'Session', 'Http']
|
|
||||||
@ -1,23 +0,0 @@
|
|||||||
from .http import *
|
|
||||||
class AnkiClient(Http):
|
|
||||||
def __init__(self, session):
|
|
||||||
Http.__init__(self, session)
|
|
||||||
self.url = 'http://127.0.0.1:8765'
|
|
||||||
self.version = None
|
|
||||||
def api(self, data):
|
|
||||||
if self.version:
|
|
||||||
data["version"] = self.version
|
|
||||||
data = json.dumps(data)
|
|
||||||
res = self._post(self.url, data)
|
|
||||||
return json.loads(res)
|
|
||||||
def make_version(self):
|
|
||||||
self.version = self.api({"action":"version"})
|
|
||||||
return self.version
|
|
||||||
def deckNames(self):
|
|
||||||
return self.api({"action":"deckNames"})
|
|
||||||
def modelNames(self):
|
|
||||||
return self.api({"action":"modelNames"})
|
|
||||||
def modelFieldNames(self, modelName):
|
|
||||||
return self.api({"action":"modelFieldNames", "params" :{"modelName" : modelName}})
|
|
||||||
def addNote(self, note):
|
|
||||||
return self.api({"action":"addNote", "params" : {"note": note}})
|
|
||||||
@ -1,35 +0,0 @@
|
|||||||
import json, requests
|
|
||||||
import http.cookiejar as cookielib
|
|
||||||
#from utils import singleton
|
|
||||||
class Session(requests.Session):
|
|
||||||
def __init__(self,headers={},cookie_file=None):
|
|
||||||
requests.Session.__init__(self)
|
|
||||||
self.cookies = cookielib.LWPCookieJar(filename=cookie_file)
|
|
||||||
try:self.cookies.load(ignore_discard=True)
|
|
||||||
except Exception as e:print(e,"failed load cookie_file")
|
|
||||||
self.headers=headers
|
|
||||||
self.auth = ('user', 'pass')
|
|
||||||
self._type='str'
|
|
||||||
def save(self):
|
|
||||||
self.cookies.save()
|
|
||||||
class Http():
|
|
||||||
def __init__(self , session):
|
|
||||||
self.session = session
|
|
||||||
def _get(self, url, data = None):
|
|
||||||
r = self.session.get(url, params = data)
|
|
||||||
self._error(r.status_code,url)
|
|
||||||
return self._res_data(r,self.session._type)
|
|
||||||
|
|
||||||
def _post(self, url, data):
|
|
||||||
r = self.session.post(url, data = data)
|
|
||||||
self._error(r.status_code, url)
|
|
||||||
return self._res_data(r, self.session._type)
|
|
||||||
|
|
||||||
def _error(self, code, url):
|
|
||||||
if code==200:return
|
|
||||||
elif code==403:raise RuntimeError('403 - Forbidden '+url)
|
|
||||||
elif code==404:raise RuntimeError('404 - Not Found '+url)
|
|
||||||
|
|
||||||
def _res_data(self, res, _type):
|
|
||||||
if _type=='json':return json.loads(res.content)
|
|
||||||
return res.content
|
|
||||||
@ -1,89 +0,0 @@
|
|||||||
{
|
|
||||||
"cells": [
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": null,
|
|
||||||
"id": "d9ed21dd",
|
|
||||||
"metadata": {},
|
|
||||||
"outputs": [],
|
|
||||||
"source": [
|
|
||||||
"import mistune\n",
|
|
||||||
"from md import *\n",
|
|
||||||
"with open(\"./md/音标.md\",\"r\", encoding='utf-8')as f:\n",
|
|
||||||
" data = f.read()"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": 6,
|
|
||||||
"id": "c39beca4",
|
|
||||||
"metadata": {},
|
|
||||||
"outputs": [],
|
|
||||||
"source": [
|
|
||||||
"# 创建解析器并解析Markdown\n",
|
|
||||||
"renderer = AnkiRenderer()\n",
|
|
||||||
"md = mistune.create_markdown(renderer=renderer)\n",
|
|
||||||
"text = md(data)"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": 7,
|
|
||||||
"id": "dc4eff8d",
|
|
||||||
"metadata": {},
|
|
||||||
"outputs": [],
|
|
||||||
"source": [
|
|
||||||
"note_list = renderer.anki()\n",
|
|
||||||
"import json\n",
|
|
||||||
"with open('data.json', 'w', encoding=\"utf8\") as f:\n",
|
|
||||||
" json.dump(note_list, f)"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": 12,
|
|
||||||
"id": "d75276bc",
|
|
||||||
"metadata": {},
|
|
||||||
"outputs": [
|
|
||||||
{
|
|
||||||
"data": {
|
|
||||||
"text/plain": [
|
|
||||||
"{'name': '[ʌ]',\n",
|
|
||||||
" 'tags': ['单元音', '短元音'],\n",
|
|
||||||
" 'imgs': ['',\n",
|
|
||||||
" ''],\n",
|
|
||||||
" 'words': ['bus', 'mother']}"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"execution_count": 12,
|
|
||||||
"metadata": {},
|
|
||||||
"output_type": "execute_result"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"source": [
|
|
||||||
"note_list[1]"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"metadata": {
|
|
||||||
"kernelspec": {
|
|
||||||
"display_name": "Python 3 (ipykernel)",
|
|
||||||
"language": "python",
|
|
||||||
"name": "python3"
|
|
||||||
},
|
|
||||||
"language_info": {
|
|
||||||
"codemirror_mode": {
|
|
||||||
"name": "ipython",
|
|
||||||
"version": 3
|
|
||||||
},
|
|
||||||
"file_extension": ".py",
|
|
||||||
"mimetype": "text/x-python",
|
|
||||||
"name": "python",
|
|
||||||
"nbconvert_exporter": "python",
|
|
||||||
"pygments_lexer": "ipython3",
|
|
||||||
"version": "3.9.12"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"nbformat": 4,
|
|
||||||
"nbformat_minor": 5
|
|
||||||
}
|
|
||||||
@ -391,7 +391,8 @@ class TabContent(QScrollArea):
|
|||||||
name = fld['name']
|
name = fld['name']
|
||||||
if maps:
|
if maps:
|
||||||
for j, each in enumerate(maps):
|
for j, each in enumerate(maps):
|
||||||
if each.get('fld_name', '') == name:
|
if each.get('fld_ord', -1) == ord or each.get(
|
||||||
|
'fld_name', '') == name:
|
||||||
each['fld_name'] = name
|
each['fld_name'] = name
|
||||||
each['fld_ord'] = ord
|
each['fld_ord'] = ord
|
||||||
self.add_dict_layout(j, **each)
|
self.add_dict_layout(j, **each)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user