1

Switching way markup fields are formatted for cards

Former-commit-id: e97bb1211a24175976293161878ec771d94334dc
This commit is contained in:
Alex Yatskov 2013-11-09 18:33:31 -08:00
parent d2c9cb7b6b
commit 21b7c734a4
2 changed files with 18 additions and 27 deletions

View File

@ -444,26 +444,24 @@ class MainWindowReader(QtGui.QMainWindow, reader_ui.Ui_MainWindowReader):
if factId is None: if factId is None:
return False return False
expression, reading = markup['%e'], markup['%r'] if markup['reading']:
summary = expression summary = u'{expression} [{reading}]'.format(**markup)
if reading: else:
summary = u'{0} [{1}]'.format(expression, reading) summary = expression
self.addedFacts.append(factId) self.addedFacts.append(factId)
self.listDefinitions.addItem(summary) self.listDefinitions.addItem(summary)
self.listDefinitions.setCurrentRow(self.listDefinitions.count() - 1) self.listDefinitions.setCurrentRow(self.listDefinitions.count() - 1)
self.setStatus(u'Added expression {0}; {1} new fact(s) total'.format(expression, len(self.addedFacts))) self.setStatus(u'Added expression {0}; {1} new fact(s) total'.format(markup['expression'], len(self.addedFacts)))
self.updateDefinitions() self.updateDefinitions()
return True return True
def ankiIsFactValid(self, markup): def ankiIsFactValid(self, markup):
if self.anki is None: if self.anki is not None:
return False fields = reader_util.replaceMarkupInFields(self.preferences.ankiFields, markup)
return self.anki.canAddNote(self.preferences.ankiDeck, self.preferences.ankiModel, fields)
fields = reader_util.replaceMarkupInFields(self.preferences.ankiFields, markup)
return self.anki.canAddNote(self.preferences.ankiDeck, self.preferences.ankiModel, fields)
def updateSampleMouseEvent(self, event): def updateSampleMouseEvent(self, event):

View File

@ -80,36 +80,29 @@ def findSentence(content, position):
return content[start:end].strip() return content[start:end].strip()
def replaceMarkupInField(field, markup):
for marker, value in markup.items():
field = field.replace(marker, value or unicode())
return field
def replaceMarkupInFields(fields, markup): def replaceMarkupInFields(fields, markup):
result = dict() result = dict()
for field, value in fields.items(): for field, value in fields.items():
result[field] = replaceMarkupInField(value, markup) result[field] = value.format(**markup)
return result return result
def buildFactMarkupExpression(expression, reading, glossary, sentence=None): def buildFactMarkupExpression(expression, reading, glossary, sentence=None):
return { return {
'%e': expression, 'expression': expression,
'%r': reading, 'reading': reading,
'%g': glossary, 'glossary': glossary,
'%s': sentence 'sentence': sentence
} }
def buildFactMarkupReading(reading, glossary, sentence=None): def buildFactMarkupReading(reading, glossary, sentence=None):
return { return {
'%e': reading, 'expression': reading,
'%r': None, 'reading': unicode(),
'%g': glossary, 'glossary': glossary,
'%s': sentence 'sentence': sentence
} }
@ -136,7 +129,7 @@ def buildDefinitionHtml(definition, factIndex, factQuery):
conjugations = unicode() conjugations = unicode()
if len(definition['rules']) > 0: if len(definition['rules']) > 0:
conjugations = u' :: '.join(definition['rules']) conjugations = u' • '.join(definition['rules'])
conjugations = '<span class = "conjugations">&lt;{0}&gt;<br/></span>'.format(conjugations) conjugations = '<span class = "conjugations">&lt;{0}&gt;<br/></span>'.format(conjugations)
links = '<a href = "copyDefinition:{0}"><img src = "://img/img/icon_copy_definition.png" align = "right"/></a>'.format(factIndex) links = '<a href = "copyDefinition:{0}"><img src = "://img/img/icon_copy_definition.png" align = "right"/></a>'.format(factIndex)