add the ability to add extra classes to q/a

This commit is contained in:
Damien Elmes 2011-03-23 08:33:30 +09:00
parent 1d91e459ec
commit 4d0e4836fe
2 changed files with 15 additions and 7 deletions

View file

@ -99,11 +99,11 @@ streak=?, lapses=?, grade=?, cycles=?, edue=? where id = ?""",
self.factor, self.reps, self.streak, self.lapses,
self.grade, self.cycles, self.edue, self.id)
def q(self):
return self._withClass(self._getQA()['q'])
def q(self, classes="q"):
return self._withClass(self._getQA()['q'], classes)
def a(self):
return self._withClass(self._getQA()['a'])
def a(self, classes="a"):
return self._withClass(self._getQA()['a'], classes)
def _getQA(self, reload=False):
if not self._qa or reload:
@ -115,8 +115,8 @@ streak=?, lapses=?, grade=?, cycles=?, edue=? where id = ?""",
self._qa = self.deck._renderQA(self.model(), gname, data)
return self._qa
def _withClass(self, txt):
return '<div class="%s">%s</div>' % (self.cssClass(), txt)
def _withClass(self, txt, extra):
return '<div class="%s %s">%s</div>' % (self.cssClass(), extra, txt)
def _reviewData(self, reload=False):
"Fetch the model and fact."

View file

@ -2,7 +2,8 @@
# Copyright: Damien Elmes <anki@ichi2.net>
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
import os, shutil, re, urllib2, time, tempfile, unicodedata, urllib
import os, shutil, re, urllib, urllib2, time, tempfile, unicodedata, \
urllib, sys
from anki.utils import checksum, intTime
from anki.lang import _
@ -102,6 +103,13 @@ If the same name exists, compare checksums."""
return txt
def escapeImages(self, string):
# Feeding webkit unicode can result in it not finding images, so on
# linux/osx we percent escape the image paths as utf8. On Windows the
# problem is more complicated - if we percent-escape as utf8 it fixes
# some images but breaks others. When filenames are normalized by
# dropbox they become unreadable if we escape them.
if sys.platform.startswith("win32"):
return string
def repl(match):
tag = match.group(1)
fname = match.group(2)