use a clearer name for fmtQA()

This commit is contained in:
Damien Elmes 2017-03-14 15:48:40 +09:00
parent ef0a28f294
commit 17d68cc957
3 changed files with 8 additions and 8 deletions

View file

@ -153,7 +153,7 @@ def minimizeHTML(s):
'<u>\\1</u>', s) '<u>\\1</u>', s)
return s return s
def fmtQA(s): def htmlToTextLine(s):
s = s.replace("<br>", " ") s = s.replace("<br>", " ")
s = s.replace("<br />", " ") s = s.replace("<br />", " ")
s = s.replace("<div>", " ") s = s.replace("<div>", " ")

View file

@ -9,7 +9,7 @@ from aqt.utils import saveGeom, restoreGeom, showWarning, askUser, shortcut, \
tooltip, openHelp, addCloseShortcut, downArrow tooltip, openHelp, addCloseShortcut, downArrow
from anki.sound import clearAudioQueue from anki.sound import clearAudioQueue
from anki.hooks import addHook, remHook, runHook from anki.hooks import addHook, remHook, runHook
from anki.utils import stripHTMLMedia, fmtQA, isMac from anki.utils import stripHTMLMedia, htmlToTextLine, isMac
import aqt.editor, aqt.modelchooser, aqt.deckchooser import aqt.editor, aqt.modelchooser, aqt.deckchooser
class AddCards(QDialog): class AddCards(QDialog):
@ -145,7 +145,7 @@ class AddCards(QDialog):
for nid in self.history: for nid in self.history:
if self.mw.col.findNotes("nid:%s" % nid): if self.mw.col.findNotes("nid:%s" % nid):
fields = self.mw.col.getNote(nid).fields fields = self.mw.col.getNote(nid).fields
txt = fmtQA(", ".join(fields)) txt = htmlToTextLine(", ".join(fields))
if len(txt) > 30: if len(txt) > 30:
txt = txt[:30] + "..." txt = txt[:30] + "..."
a = m.addAction(_("Edit \"%s\"") % txt) a = m.addAction(_("Edit \"%s\"") % txt)

View file

@ -12,7 +12,7 @@ from anki.lang import ngettext
from aqt.qt import * from aqt.qt import *
import anki import anki
import aqt.forms import aqt.forms
from anki.utils import fmtTimeSpan, ids2str, stripHTMLMedia, fmtQA, isWin, intTime, isMac from anki.utils import fmtTimeSpan, ids2str, stripHTMLMedia, htmlToTextLine, isWin, intTime, isMac
from aqt.utils import saveGeom, restoreGeom, saveSplitter, restoreSplitter, \ from aqt.utils import saveGeom, restoreGeom, saveSplitter, restoreSplitter, \
saveHeader, restoreHeader, saveState, restoreState, applyStyles, getTag, \ saveHeader, restoreHeader, saveState, restoreState, applyStyles, getTag, \
showInfo, askUser, tooltip, openHelp, showWarning, shortcut, mungeQA showInfo, askUser, tooltip, openHelp, showWarning, shortcut, mungeQA
@ -234,7 +234,7 @@ class DataModel(QAbstractTableModel):
return self.answer(c) return self.answer(c)
elif type == "noteFld": elif type == "noteFld":
f = c.note() f = c.note()
return fmtQA(f.fields[self.col.models.sortIdx(f.model())]) return htmlToTextLine(f.fields[self.col.models.sortIdx(f.model())])
elif type == "template": elif type == "template":
t = c.template()['name'] t = c.template()['name']
if c.model()['type'] == MODEL_CLOZE: if c.model()['type'] == MODEL_CLOZE:
@ -283,16 +283,16 @@ class DataModel(QAbstractTableModel):
return self.browser.mw.col.decks.name(c.did) return self.browser.mw.col.decks.name(c.did)
def question(self, c): def question(self, c):
return fmtQA(c.q(browser=True)) return htmlToTextLine(c.q(browser=True))
def answer(self, c): def answer(self, c):
if c.template().get('bafmt'): if c.template().get('bafmt'):
# they have provided a template, use it verbatim # they have provided a template, use it verbatim
c.q(browser=True) c.q(browser=True)
return fmtQA(c.a()) return htmlToTextLine(c.a())
# need to strip question from answer # need to strip question from answer
q = self.question(c) q = self.question(c)
a = fmtQA(c.a()) a = htmlToTextLine(c.a())
if a.startswith(q): if a.startswith(q):
return a[len(q):].strip() return a[len(q):].strip()
return a return a