Skip to content

Commit 180d250

Browse files
authored
Merge pull request #8 from alexthillen/feat/cloze-show
Feat/cloze show
2 parents 0057a3f + 69af4cf commit 180d250

File tree

8 files changed

+307
-21
lines changed

8 files changed

+307
-21
lines changed
191 KB
Loading

.github/workflows/github-actions-dev.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
ls
2222
2323
- name: Upload artifact
24-
uses: actions/upload-artifact@v2
24+
uses: actions/upload-artifact@v3
2525
with:
2626
name: MDKaTeX.ankiaddon
2727
path: ./MDKaTeX.ankiaddon

MDKaTeX/HTMLandCSS.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
""" This file contains all the HTML / CSS strings for the different card types """
2+
23
import os
34

45

@@ -21,11 +22,13 @@ def read_file(path):
2122

2223
script_base = read_file("html/script_base.html")
2324
script_cloze = read_file("html/script_cloze.html")
25+
script_cloze_show = read_file("html/script_cloze_show.html")
2426

2527
front = read_file("html/front.html") + script_base
2628
back = read_file("html/back.html") + script_base
2729

2830
front_cloze = read_file("html/front_cloze.html") + script_cloze
31+
front_cloze_show = read_file("html/front_cloze.html") + script_cloze_show
2932
back_cloze = read_file("html/back_cloze.html") + script_cloze
3033

3134
css = read_file("css/style_import.css")

MDKaTeX/__init__.py

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,16 @@
22
import shutil
33
import 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+
)
615
from aqt import mw
716
from anki.hooks import addHook
817
import 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+
92126
def 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)

MDKaTeX/css/_style.css

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
1-
.card, .fields {
1+
.card,
2+
.fields {
23
font-family: arial;
34
font-size: 20px;
45
color: black;
56
background-color: white;
67
}
78

8-
table, th, td {
9-
border: 1px solid black;
10-
border-collapse: collapse;
9+
table,
10+
th,
11+
td {
12+
border: 1px solid black;
13+
border-collapse: collapse;
1114
}
1215

13-
#front, #back, #extra {
14-
visibility: hidden;
16+
#front,
17+
#back,
18+
#extra {
19+
visibility: hidden;
1520
}
1621

1722
pre code {
@@ -22,16 +27,18 @@ pre code {
2227
}
2328

2429
.cloze {
25-
color: #42C0FB !important;
26-
display: inline-block;
30+
color: #42C0FB !important;
31+
display: inline-flex;
2732
}
2833

2934
.cloze-inactive {
3035
display: inline-block;
3136
}
3237

33-
.nightMode, .night-mode, .night_mode {
34-
background-color: #0f0f0f !important;
38+
.nightMode,
39+
.night-mode,
40+
.night_mode {
41+
background-color: #0f0f0f !important;
3542
color: #c0c0c0 !important;
3643
}
3744

MDKaTeX/html/script_cloze.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@
182182
}
183183

184184
function restoreHTMLElementsInString(str) {
185-
console.log(str);
186185
for (let i = 0; i < restoreElements.length; i++) {
187186
if (restoreElements[i].is_plaintext) {
188187
str = str.replaceAll(restoreElements[i].from, restoreElements[i].to);
@@ -192,4 +191,4 @@
192191
}
193192
return str;
194193
}
195-
</script>
194+
</script>

0 commit comments

Comments
 (0)