22import shutil
33import re
44
5- from .HTMLandCSS import HTMLforEditor , read_file , front , back , front_cloze , back_cloze , css
5+ from .HTMLandCSS import (
6+ HTMLforEditor ,
7+ read_file ,
8+ front ,
9+ back ,
10+ front_cloze ,
11+ back_cloze ,
12+ front_cloze_show ,
13+ css ,
14+ )
615from aqt import mw
716from anki .hooks import addHook
817import anki
@@ -20,7 +29,7 @@ def markdownPreview(editor):
2029 editor .web .eval (HTMLforEditor )
2130 else : # removes the markdown preview
2231 editor .web .eval (
23- """
32+ """
2433 var area = document.getElementById('markdown-area');
2534 if(area) area.remove();
2635 """
@@ -37,11 +46,14 @@ def create_model_if_necessacy():
3746 """
3847 model = mw .col .models .by_name (MODEL_NAME + " Basic (Color)" )
3948 model_cloze = mw .col .models .by_name (MODEL_NAME + " Cloze (Color)" )
49+ model_cloze_show = mw .col .models .by_name (MODEL_NAME + " Cloze + Show Cloze (Color)" )
4050
4151 if not model :
4252 create_model ()
4353 if not model_cloze :
4454 create_model_cloze ()
55+ if not model_cloze_show :
56+ create_model_cloze_show ()
4557
4658 update ()
4759
@@ -89,10 +101,33 @@ def create_model_cloze():
89101 m .save (model )
90102
91103
104+ def create_model_cloze_show ():
105+ """Creates the Cloze Card type"""
106+ m = mw .col .models
107+ model = m .new (MODEL_NAME + " Cloze + Show Cloze (Color)" )
108+ model ["type" ] = anki .consts .MODEL_CLOZE
109+
110+ field = m .newField ("Text" )
111+ m .addField (model , field )
112+
113+ field = m .newField ("Back Extra" )
114+ m .addField (model , field )
115+
116+ template = m .newTemplate (MODEL_NAME + " Cloze + Show Cloze (Color)" )
117+ template ["qfmt" ] = front_cloze_show
118+ template ["afmt" ] = back_cloze
119+ model ["css" ] = css
120+
121+ m .addTemplate (model , template )
122+ m .add (model )
123+ m .save (model )
124+
125+
92126def update ():
93127 """Updates the card types the addon has a pending update"""
94128 model = mw .col .models .by_name (MODEL_NAME + " Basic (Color)" )
95129 model_cloze = mw .col .models .by_name (MODEL_NAME + " Cloze (Color)" )
130+ model_cloze_show = mw .col .models .by_name (MODEL_NAME + " Cloze + Show Cloze (Color)" )
96131
97132 model ["tmpls" ][0 ]["qfmt" ] = front
98133 model ["tmpls" ][0 ]["afmt" ] = back
@@ -102,8 +137,13 @@ def update():
102137 model_cloze ["tmpls" ][0 ]["afmt" ] = back_cloze
103138 model_cloze ["css" ] = css
104139
140+ model_cloze_show ["tmpls" ][0 ]["qfmt" ] = front_cloze_show
141+ model_cloze_show ["tmpls" ][0 ]["afmt" ] = back_cloze
142+ model_cloze_show ["css" ] = css
143+
105144 mw .col .models .save (model )
106145 mw .col .models .save (model_cloze )
146+ mw .col .models .save (model_cloze_show )
107147
108148 if os .path .isdir (os .path .join (mw .col .media .dir (), "_katex" )):
109149 shutil .rmtree (os .path .join (mw .col .media .dir (), "_katex" ))
@@ -113,18 +153,16 @@ def update():
113153
114154 addon_path = os .path .join (os .path .dirname (os .path .realpath (__file__ )))
115155
116- _write_data ("_style.css" , bytes (read_file ("css/_style.css" ), ' utf-8' ))
117- _add_file (os .path .join (addon_path , "css" , "_user_style.css" ), "_user_style.css" )
156+ _write_data ("_style.css" , bytes (read_file ("css/_style.css" ), " utf-8" ))
157+ _add_file (os .path .join (addon_path , "css" , "_user_style.css" ), "_user_style.css" )
118158 _add_file (os .path .join (addon_path , "_katex.min.js" ), "_katex.min.js" )
119159 _add_file (os .path .join (addon_path , "_katex.css" ), "_katex.css" )
120160 _add_file (os .path .join (addon_path , "_auto-render.js" ), "_auto-render.js" )
121- _add_file (os .path .join (addon_path , "_markdown-it.min.js" ),
122- "_markdown-it.min.js" )
161+ _add_file (os .path .join (addon_path , "_markdown-it.min.js" ), "_markdown-it.min.js" )
123162 _add_file (os .path .join (addon_path , "_highlight.css" ), "_highlight.css" )
124163 _add_file (os .path .join (addon_path , "_highlight.js" ), "_highlight.js" )
125164 _add_file (os .path .join (addon_path , "_mhchem.js" ), "_mhchem.js" )
126- _add_file (os .path .join (addon_path , "_markdown-it-mark.js" ),
127- "_markdown-it-mark.js" )
165+ _add_file (os .path .join (addon_path , "_markdown-it-mark.js" ), "_markdown-it-mark.js" )
128166
129167 for katex_font in os .listdir (os .path .join (addon_path , "fonts" )):
130168 _add_file (os .path .join (addon_path , "fonts" , katex_font ), katex_font )
0 commit comments