diff --git a/.github/assets/example-cloze-show-answer.gif b/.github/assets/example-cloze-show-answer.gif new file mode 100644 index 0000000..e90b96f Binary files /dev/null and b/.github/assets/example-cloze-show-answer.gif differ diff --git a/.github/workflows/github-actions-dev.yml b/.github/workflows/github-actions-dev.yml index 522ae26..5cfb700 100644 --- a/.github/workflows/github-actions-dev.yml +++ b/.github/workflows/github-actions-dev.yml @@ -21,7 +21,7 @@ jobs: ls - name: Upload artifact - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: MDKaTeX.ankiaddon path: ./MDKaTeX.ankiaddon diff --git a/MDKaTeX/HTMLandCSS.py b/MDKaTeX/HTMLandCSS.py index 30cb571..f263365 100644 --- a/MDKaTeX/HTMLandCSS.py +++ b/MDKaTeX/HTMLandCSS.py @@ -1,4 +1,5 @@ """ This file contains all the HTML / CSS strings for the different card types """ + import os @@ -21,11 +22,13 @@ def read_file(path): script_base = read_file("html/script_base.html") script_cloze = read_file("html/script_cloze.html") +script_cloze_show = read_file("html/script_cloze_show.html") front = read_file("html/front.html") + script_base back = read_file("html/back.html") + script_base front_cloze = read_file("html/front_cloze.html") + script_cloze +front_cloze_show = read_file("html/front_cloze.html") + script_cloze_show back_cloze = read_file("html/back_cloze.html") + script_cloze css = read_file("css/style_import.css") diff --git a/MDKaTeX/__init__.py b/MDKaTeX/__init__.py index 23b6c9a..a90f808 100644 --- a/MDKaTeX/__init__.py +++ b/MDKaTeX/__init__.py @@ -2,7 +2,16 @@ import shutil import re -from .HTMLandCSS import HTMLforEditor, read_file, front, back, front_cloze, back_cloze, css +from .HTMLandCSS import ( + HTMLforEditor, + read_file, + front, + back, + front_cloze, + back_cloze, + front_cloze_show, + css, +) from aqt import mw from anki.hooks import addHook import anki @@ -20,7 +29,7 @@ def markdownPreview(editor): editor.web.eval(HTMLforEditor) else: # removes the markdown preview editor.web.eval( - """ + """ var area = document.getElementById('markdown-area'); if(area) area.remove(); """ @@ -37,11 +46,14 @@ def create_model_if_necessacy(): """ model = mw.col.models.by_name(MODEL_NAME + " Basic (Color)") model_cloze = mw.col.models.by_name(MODEL_NAME + " Cloze (Color)") + model_cloze_show = mw.col.models.by_name(MODEL_NAME + " Cloze + Show Cloze (Color)") if not model: create_model() if not model_cloze: create_model_cloze() + if not model_cloze_show: + create_model_cloze_show() update() @@ -89,10 +101,33 @@ def create_model_cloze(): m.save(model) +def create_model_cloze_show(): + """Creates the Cloze Card type""" + m = mw.col.models + model = m.new(MODEL_NAME + " Cloze + Show Cloze (Color)") + model["type"] = anki.consts.MODEL_CLOZE + + field = m.newField("Text") + m.addField(model, field) + + field = m.newField("Back Extra") + m.addField(model, field) + + template = m.newTemplate(MODEL_NAME + " Cloze + Show Cloze (Color)") + template["qfmt"] = front_cloze_show + template["afmt"] = back_cloze + model["css"] = css + + m.addTemplate(model, template) + m.add(model) + m.save(model) + + def update(): """Updates the card types the addon has a pending update""" model = mw.col.models.by_name(MODEL_NAME + " Basic (Color)") model_cloze = mw.col.models.by_name(MODEL_NAME + " Cloze (Color)") + model_cloze_show = mw.col.models.by_name(MODEL_NAME + " Cloze + Show Cloze (Color)") model["tmpls"][0]["qfmt"] = front model["tmpls"][0]["afmt"] = back @@ -102,8 +137,13 @@ def update(): model_cloze["tmpls"][0]["afmt"] = back_cloze model_cloze["css"] = css + model_cloze_show["tmpls"][0]["qfmt"] = front_cloze_show + model_cloze_show["tmpls"][0]["afmt"] = back_cloze + model_cloze_show["css"] = css + mw.col.models.save(model) mw.col.models.save(model_cloze) + mw.col.models.save(model_cloze_show) if os.path.isdir(os.path.join(mw.col.media.dir(), "_katex")): shutil.rmtree(os.path.join(mw.col.media.dir(), "_katex")) @@ -113,18 +153,16 @@ def update(): addon_path = os.path.join(os.path.dirname(os.path.realpath(__file__))) - _write_data("_style.css", bytes(read_file("css/_style.css"), 'utf-8')) - _add_file(os.path.join(addon_path, "css", "_user_style.css"), "_user_style.css") + _write_data("_style.css", bytes(read_file("css/_style.css"), "utf-8")) + _add_file(os.path.join(addon_path, "css", "_user_style.css"), "_user_style.css") _add_file(os.path.join(addon_path, "_katex.min.js"), "_katex.min.js") _add_file(os.path.join(addon_path, "_katex.css"), "_katex.css") _add_file(os.path.join(addon_path, "_auto-render.js"), "_auto-render.js") - _add_file(os.path.join(addon_path, "_markdown-it.min.js"), - "_markdown-it.min.js") + _add_file(os.path.join(addon_path, "_markdown-it.min.js"), "_markdown-it.min.js") _add_file(os.path.join(addon_path, "_highlight.css"), "_highlight.css") _add_file(os.path.join(addon_path, "_highlight.js"), "_highlight.js") _add_file(os.path.join(addon_path, "_mhchem.js"), "_mhchem.js") - _add_file(os.path.join(addon_path, "_markdown-it-mark.js"), - "_markdown-it-mark.js") + _add_file(os.path.join(addon_path, "_markdown-it-mark.js"), "_markdown-it-mark.js") for katex_font in os.listdir(os.path.join(addon_path, "fonts")): _add_file(os.path.join(addon_path, "fonts", katex_font), katex_font) diff --git a/MDKaTeX/css/_style.css b/MDKaTeX/css/_style.css index 8538b0d..919542a 100644 --- a/MDKaTeX/css/_style.css +++ b/MDKaTeX/css/_style.css @@ -1,17 +1,22 @@ -.card, .fields { +.card, +.fields { font-family: arial; font-size: 20px; color: black; background-color: white; } -table, th, td { - border: 1px solid black; - border-collapse: collapse; +table, +th, +td { + border: 1px solid black; + border-collapse: collapse; } -#front, #back, #extra { - visibility: hidden; +#front, +#back, +#extra { + visibility: hidden; } pre code { @@ -22,16 +27,18 @@ pre code { } .cloze { - color: #42C0FB !important; - display: inline-block; + color: #42C0FB !important; + display: inline-flex; } .cloze-inactive { display: inline-block; } -.nightMode, .night-mode, .night_mode { - background-color: #0f0f0f !important; +.nightMode, +.night-mode, +.night_mode { + background-color: #0f0f0f !important; color: #c0c0c0 !important; } diff --git a/MDKaTeX/html/script_cloze.html b/MDKaTeX/html/script_cloze.html index bfb519f..367d478 100644 --- a/MDKaTeX/html/script_cloze.html +++ b/MDKaTeX/html/script_cloze.html @@ -182,7 +182,6 @@ } function restoreHTMLElementsInString(str) { - console.log(str); for (let i = 0; i < restoreElements.length; i++) { if (restoreElements[i].is_plaintext) { str = str.replaceAll(restoreElements[i].from, restoreElements[i].to); @@ -192,4 +191,4 @@ } return str; } - + \ No newline at end of file diff --git a/MDKaTeX/html/script_cloze_show.html b/MDKaTeX/html/script_cloze_show.html new file mode 100644 index 0000000..ef74de2 --- /dev/null +++ b/MDKaTeX/html/script_cloze_show.html @@ -0,0 +1,232 @@ + \ No newline at end of file diff --git a/README.md b/README.md index 88f915b..66a6af3 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,12 @@ # Anki Markdown + +## Latest Release : New Card Type "Markdown and KaTeX Cloze + Show Cloze (Color)" + +![Latest Update](.github/assets/example-cloze-show-answer.gif) + +## How to use + [Download Anki Add-On](https://ankiweb.net/shared/info/1786114227) Adding support and improvements of how cards are displayed.