mirror of
https://github.com/ankidroid/Anki-Android.git
synced 2024-09-20 03:52:15 +02:00
fix: "{{FrontSide}}" should be blank on front
People use this - Anki has it special cased unintentionally due to hooks, but this is in use in AnkiDroid It wasn't working before this, but the template {{Front}}{{FrontSide}} previously rendered as helloworld{Unknown field FrontSide} in 2.14.6 Anki:400254277b/rslib/src/template.rs (L409-L417)
Our change:08217da
(issue 7980) Fixes 8951 (cherry picked from commit2391712061
)
This commit is contained in:
parent
d65606e7a1
commit
a34e674bae
@ -54,6 +54,8 @@ import com.ichi2.utils.JSONArray;
|
||||
import com.ichi2.utils.JSONException;
|
||||
import com.ichi2.utils.JSONObject;
|
||||
|
||||
import net.ankiweb.rsdroid.RustCleanup;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
@ -1081,6 +1083,7 @@ public class Collection implements CollectionGetter {
|
||||
}
|
||||
|
||||
|
||||
@RustCleanup("#8951 - Remove FrontSide added to the front")
|
||||
public HashMap<String, String> _renderQA(long cid, Model model, long did, int ord, String tags, String[] flist, int flags, boolean browser, String qfmt, String afmt) {
|
||||
// data is [cid, nid, mid, did, ord, tags, flds, cardFlags]
|
||||
// unpack fields and create dict
|
||||
@ -1116,6 +1119,7 @@ public class Collection implements CollectionGetter {
|
||||
if ("q".equals(type)) {
|
||||
format = fClozePatternQ.matcher(format).replaceAll(String.format(Locale.US, "{{$1cq-%d:", cardNum));
|
||||
format = fClozeTagStart.matcher(format).replaceAll(String.format(Locale.US, "<%%cq:%d:", cardNum));
|
||||
fields.put("FrontSide", "");
|
||||
} else {
|
||||
format = fClozePatternA.matcher(format).replaceAll(String.format(Locale.US, "{{$1ca-%d:", cardNum));
|
||||
format = fClozeTagStart.matcher(format).replaceAll(String.format(Locale.US, "<%%ca:%d:", cardNum));
|
||||
|
@ -26,6 +26,7 @@ import static com.ichi2.libanki.Utils.stripHTML;
|
||||
import static com.ichi2.utils.ListUtil.assertListEquals;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.endsWith;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@ -35,6 +36,23 @@ import static org.junit.Assert.fail;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ModelTest extends RobolectricTest {
|
||||
|
||||
@Test
|
||||
public void test_frontSide_field() {
|
||||
// #8951 - Anki Special-cases {{FrontSide}} on the front to return empty string
|
||||
Collection col = getCol();
|
||||
Model m = col.getModels().current();
|
||||
m.getJSONArray("tmpls").getJSONObject(0).put("qfmt", "{{Front}}{{FrontSide}}");
|
||||
col.getModels().save(m);
|
||||
Note note = col.newNote();
|
||||
note.setItem("Front", "helloworld");
|
||||
col.addNote(note);
|
||||
Card card = note.firstCard();
|
||||
String q = card.q();
|
||||
assertThat("field should be at the end of the template - empty string for front", q, endsWith("helloworld"));
|
||||
assertThat("field should not have a problem", q, not(containsString("has a problem")));
|
||||
}
|
||||
|
||||
/*****************
|
||||
** Models *
|
||||
*****************/
|
||||
|
Loading…
Reference in New Issue
Block a user