Skip to content
Merged
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
Binary file added .github/assets/example-cloze-show-answer.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion .github/workflows/github-actions-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions MDKaTeX/HTMLandCSS.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" This file contains all the HTML / CSS strings for the different card types """

import os


Expand All @@ -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")
54 changes: 46 additions & 8 deletions MDKaTeX/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
"""
Expand All @@ -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()

Expand Down Expand Up @@ -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
Expand All @@ -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"))
Expand All @@ -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)
Expand Down
27 changes: 17 additions & 10 deletions MDKaTeX/css/_style.css
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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;
}

Expand Down
3 changes: 1 addition & 2 deletions MDKaTeX/html/script_cloze.html
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -192,4 +191,4 @@
}
return str;
}
</script>
</script>
Loading
Loading