Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fixes Mathjax inside of a cloze replacement. #5324

Merged
merged 1 commit into from
Jun 11, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ private static String clozeText(String txt, String ord, char type) {
String buf;
if (type == 'q') {
if (!TextUtils.isEmpty(m.group(4))) {
buf = "[$4]";
buf = "[" + m.group(4) + "]";
} else {
buf = "[...]";
}
Expand All @@ -310,7 +310,7 @@ private static String clozeText(String txt, String ord, char type) {
buf = String.format("<span class=cloze>%s</span>", buf);
}

m.appendReplacement(repl, buf);
m.appendReplacement(repl, Matcher.quoteReplacement(buf));
}
txt = m.appendTail(repl).toString();
// and display other clozes normally
Expand Down
18 changes: 18 additions & 0 deletions AnkiDroid/src/test/java/com/ichi2/libanki/MathJaxClozeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,22 @@ public void verifyMathJaxClozeCards() {
assertTrue(cards.get(3).q().contains("class=cloze"));
assertTrue(cards.get(4).q().contains("class=cloze"));
}

@Test
public void verifyMathJaxInCloze() {
final Context context = ApplicationProvider.getApplicationContext();

Collection c = getCol();
Note f = c.newNote(c.getModels().byName("Cloze"));
f.setItem("Text", "\\(1 \\div 2 =\\){{c1::\\(\\frac{1}{2}\\)}}");
c.addNote(f);

ArrayList<Card> cards = f.cards();
Card c2 = cards.get(0);
String q = c2.q();
String a = c2.a();
assertTrue(q.contains("\\(1 \\div 2 =\\)"));
assertTrue(a.contains("\\(1 \\div 2 =\\)"));
assertTrue(a.contains("<span class=cloze>\\(\\frac{1}{2}\\)</span>"));
}
}