mirror of
https://github.com/ankitects/anki.git
synced 2025-11-07 05:07:10 -05:00
another fix for mathjax+cloze
This commit is contained in:
parent
bd414595de
commit
8737c6737b
2 changed files with 26 additions and 1 deletions
|
|
@ -207,8 +207,20 @@ class Template:
|
||||||
|
|
||||||
# look for clozes wrapped in mathjax, and change {{cx to {{Cx
|
# look for clozes wrapped in mathjax, and change {{cx to {{Cx
|
||||||
def _removeFormattingFromMathjax(self, txt, ord):
|
def _removeFormattingFromMathjax(self, txt, ord):
|
||||||
regex = r"(\\[([]).*?"+(clozeReg%ord)+r".*?(\\[\])])"
|
opening = ["\\(", "\\["]
|
||||||
|
closing = ["\\)", "\\]"]
|
||||||
|
regex = r"(\\[([])(.*?)"+(clozeReg%ord)+r"(.*?)(\\[\])])"
|
||||||
def repl(m):
|
def repl(m):
|
||||||
|
enclosed = True
|
||||||
|
for s in closing:
|
||||||
|
if s in m.group(1):
|
||||||
|
enclosed = False
|
||||||
|
for s in opening:
|
||||||
|
if s in m.group(7):
|
||||||
|
enclosed = False
|
||||||
|
if not enclosed:
|
||||||
|
return m.group(0)
|
||||||
|
# remove formatting
|
||||||
return m.group(0).replace("{{c", "{{C")
|
return m.group(0).replace("{{c", "{{C")
|
||||||
txt = re.sub(regex, repl, txt)
|
txt = re.sub(regex, repl, txt)
|
||||||
return txt
|
return txt
|
||||||
|
|
|
||||||
|
|
@ -187,6 +187,19 @@ def test_cloze():
|
||||||
f.flush()
|
f.flush()
|
||||||
assert len(f.cards()) == 2
|
assert len(f.cards()) == 2
|
||||||
|
|
||||||
|
def test_cloze_mathjax():
|
||||||
|
d = getEmptyCol()
|
||||||
|
d.models.setCurrent(d.models.byName("Cloze"))
|
||||||
|
f = d.newNote()
|
||||||
|
f['Text'] = r'{{c1::ok}} \(2^2\) {{c2::not ok}} \(2^{{c3::2}}\) \(x^3\) {{c4::blah}} {{c5::text with \(x^2\) jax}}'
|
||||||
|
assert d.addNote(f)
|
||||||
|
assert len(f.cards()) == 5
|
||||||
|
assert "class=cloze" in f.cards()[0].q()
|
||||||
|
assert "class=cloze" in f.cards()[1].q()
|
||||||
|
assert "class=cloze" not in f.cards()[2].q()
|
||||||
|
assert "class=cloze" in f.cards()[3].q()
|
||||||
|
assert "class=cloze" in f.cards()[4].q()
|
||||||
|
|
||||||
def test_chained_mods():
|
def test_chained_mods():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
d.models.setCurrent(d.models.byName("Cloze"))
|
d.models.setCurrent(d.models.byName("Cloze"))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue