From 21b7c734a4ee7cfa5cfd22f343d0d98777c5fc00 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 9 Nov 2013 18:33:31 -0800 Subject: [PATCH] Switching way markup fields are formatted for cards Former-commit-id: e97bb1211a24175976293161878ec771d94334dc --- yomi_base/reader.py | 18 ++++++++---------- yomi_base/reader_util.py | 27 ++++++++++----------------- 2 files changed, 18 insertions(+), 27 deletions(-) diff --git a/yomi_base/reader.py b/yomi_base/reader.py index 2a46438..92e93a3 100644 --- a/yomi_base/reader.py +++ b/yomi_base/reader.py @@ -444,26 +444,24 @@ class MainWindowReader(QtGui.QMainWindow, reader_ui.Ui_MainWindowReader): if factId is None: return False - expression, reading = markup['%e'], markup['%r'] - summary = expression - if reading: - summary = u'{0} [{1}]'.format(expression, reading) + if markup['reading']: + summary = u'{expression} [{reading}]'.format(**markup) + else: + summary = expression self.addedFacts.append(factId) self.listDefinitions.addItem(summary) 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() return True def ankiIsFactValid(self, markup): - if self.anki is None: - return False - - fields = reader_util.replaceMarkupInFields(self.preferences.ankiFields, markup) - return self.anki.canAddNote(self.preferences.ankiDeck, self.preferences.ankiModel, fields) + if self.anki is not None: + fields = reader_util.replaceMarkupInFields(self.preferences.ankiFields, markup) + return self.anki.canAddNote(self.preferences.ankiDeck, self.preferences.ankiModel, fields) def updateSampleMouseEvent(self, event): diff --git a/yomi_base/reader_util.py b/yomi_base/reader_util.py index 07e32fe..eb66749 100644 --- a/yomi_base/reader_util.py +++ b/yomi_base/reader_util.py @@ -80,36 +80,29 @@ def findSentence(content, position): 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): result = dict() for field, value in fields.items(): - result[field] = replaceMarkupInField(value, markup) + result[field] = value.format(**markup) return result def buildFactMarkupExpression(expression, reading, glossary, sentence=None): return { - '%e': expression, - '%r': reading, - '%g': glossary, - '%s': sentence + 'expression': expression, + 'reading': reading, + 'glossary': glossary, + 'sentence': sentence } def buildFactMarkupReading(reading, glossary, sentence=None): return { - '%e': reading, - '%r': None, - '%g': glossary, - '%s': sentence + 'expression': reading, + 'reading': unicode(), + 'glossary': glossary, + 'sentence': sentence } @@ -136,7 +129,7 @@ def buildDefinitionHtml(definition, factIndex, factQuery): conjugations = unicode() if len(definition['rules']) > 0: - conjugations = u' :: '.join(definition['rules']) + conjugations = u' • '.join(definition['rules']) conjugations = '<{0}>
'.format(conjugations) links = ''.format(factIndex)