def mungeQAB(deck, txt): txt = renderLatex(deck, txt) txt = stripSounds(txt) # hack to fix thai presentation issues if mw.bodyView.main.config['addZeroSpace']: txt = txt.replace("</span>", "​</span>") return txt
def return_data(idx): """ Return a cleaned-up version of the field content. Get the text, remove html, and return the field name, the clean text, and what we got when we tried to split into kanji and kana, when different from the text. """ text = note[field_names[idx]] # This is taken from aqt/browser.py. text = text.replace(u'<br>', u' ') text = text.replace(u'<br />', u' ') if strip_interpunct: text = text.replace(u'・', u'') text = stripHTML(text) text = stripSounds(text) # Reformat so we have exactly one space between words. text = u' '.join(text.split()) if not text and not get_empty: raise ValueError('Source field empty') # We pass the reading/plain on to the update dialog. We don't # look at the texts any more to decide what to do. So don't # set anything to empty here. Rather do the split even if it # is pointless. base = furigana.kanji(text) ruby = furigana.kana(text) return field_names[idx], fname, text, base, ruby, readings
def mungeQA(deck, txt): txt = renderLatex(deck, txt) txt = stripSounds(txt) # webkit currently doesn't handle bold/underline properly txt = txt.replace("font-weight: 600;", "font-weight: 900;") txt = txt.replace("text-decoration: underline;", "border-bottom: 1px solid #000;") return txt
def mungeQA(col, txt): txt = col.media.escapeImages(txt) txt = stripSounds(txt) # osx webkit doesn't understand font weight 600 txt = re.sub("font-weight: *600", "font-weight:bold", txt) if isMac: # custom fonts cause crashes on osx at the moment txt = txt.replace("font-face", "invalid") return txt
def __init__(self, w_field, a_field, word): self.word_field_name = w_field self.audio_field_name = a_field # This is taken from aqt/browser.py. self.word = word.replace(u'<br>', u' ') self.word = self.word.replace(u'<br />', u' ') if strip_interpunct: self.word = self.word.replace(u'・', u'') self.word = stripHTML(self.word) self.word = stripSounds(self.word) # Reformat so we have exactly one space between words. self.word = u' '.join(self.word.split())
def myRenderQA(self, data, qfmt=None, afmt=None): "Returns hash of id, question, answer." # data is [cid, nid, mid, did, ord, tags, flds, flags] # unpack fields and create dict flist = splitFields(data[6]) fields = {} model = self.models.get(data[2]) for (name, (idx, conf)) in self.models.fieldMap(model).items(): fields[name] = flist[idx] if len(data) > 7: shakyWarningFieldName = _getShakyWarningFieldName(data[7]) if shakyWarningFieldName: fields[shakyWarningFieldName] = shakyWarningFieldName fields['Tags'] = data[5].strip() fields['Type'] = model['name'] fields['Deck'] = self.decks.name(data[3]) if model['type'] == MODEL_STD: template = model['tmpls'][data[4]] else: template = model['tmpls'][0] fields['Card'] = template['name'] fields['c%d' % (data[4]+1)] = "1" # render q & a d = dict(id=data[0]) qfmt = qfmt or template['qfmt'] afmt = afmt or template['afmt'] for (type, format) in (("q", qfmt), ("a", afmt)): if type == "q": format = re.sub("{{(?!type:)(.*?)cloze:", r"{{\1cq-%d:" % (data[4]+1), format) format = format.replace("<%cloze:", "<%%cq:%d:" % ( data[4]+1)) else: format = re.sub("{{(.*?)cloze:", r"{{\1ca-%d:" % (data[4]+1), format) format = format.replace("<%cloze:", "<%%ca:%d:" % ( data[4]+1)) fields['FrontSide'] = stripSounds(d['q']) fields = runFilter("mungeFields", fields, model, data, self) html = anki.template.render(format, fields) d[type] = runFilter( "mungeQA", html, type, fields, model, data, self) # empty cloze? if type == 'q' and model['type'] == MODEL_CLOZE: if not self.models._availClozeOrds(model, data[6], False): d['q'] += ("<p>" + _( "Please edit this note and add some cloze deletions. (%s)") % ( "<a href=%s#cloze>%s</a>" % (HELP_SITE, _("help")))) return d
def mungeQA(txt): txt = stripSounds(txt) # osx webkit doesn't understand font weight 600 txt = re.sub("font-weight: *600", "font-weight:bold", txt) return txt
def mungeQA(col, txt): txt = col.media.escapeImages(txt) txt = stripSounds(txt) # osx webkit doesn't understand font weight 600 txt = re.sub("font-weight: *600", "font-weight:bold", txt) return txt
def mungeQA(col, txt): txt = col.media.escapeImages(txt) txt = stripSounds(txt) return txt
def mungeQA(deck, txt): txt = renderLatex(deck, txt) txt = stripSounds(txt) return txt
def _renderQA(self, data, qfmt=None, afmt=None): """Returns hash of id, question, answer. Keyword arguments: data -- [cid, nid, mid, did, ord, tags, flds] (see db documentation for more information about those values) This corresponds to the information you can obtain in templates, using {{Tags}}, {{Type}}, etc.. qfmt -- question format string (as in template) afmt -- answer format string (as in template) unpack fields and create dict TODO comment better """ flist = splitFields(data[6])#the list of fields fields = {} # #name -> ord for each field, tags # Type: the name of the model, # Deck, Subdeck: their name # Card: the template name # cn: 1 for n being the ord+1 # FrontSide : model = self.models.get(data[2]) for (name, (idx, conf)) in list(self.models.fieldMap(model).items()):#conf is not used fields[name] = flist[idx] fields['Tags'] = data[5].strip() fields['Type'] = model['name'] fields['Deck'] = self.decks.name(data[3]) fields['Subdeck'] = fields['Deck'].split('::')[-1] if model['type'] == MODEL_STD:#model['type'] is distinct from fields['Type'] template = model['tmpls'][data[4]] else:#for cloze deletions template = model['tmpls'][0] fields['Card'] = template['name'] fields['c%d' % (data[4]+1)] = "1" # render q & a d = dict(id=data[0]) # id: card id qfmt = qfmt or template['qfmt'] afmt = afmt or template['afmt'] for (type, format) in (("q", qfmt), ("a", afmt)): if type == "q":#if/else is in the loop in order for d['q'] to be defined below format = re.sub("{{(?!type:)(.*?)cloze:", r"{{\1cq-%d:" % (data[4]+1), format) #Replace {{'foo'cloze: by {{'foo'cq-(ord+1), where 'foo' does not begins with "type:" format = format.replace("<%cloze:", "<%%cq:%d:" % ( data[4]+1)) #Replace <%cloze: by <%%cq:(ord+1) else: format = re.sub("{{(.*?)cloze:", r"{{\1ca-%d:" % (data[4]+1), format) #Replace {{'foo'cloze: by {{'foo'ca-(ord+1) format = format.replace("<%cloze:", "<%%ca:%d:" % ( data[4]+1)) #Replace <%cloze: by <%%ca:(ord+1) fields['FrontSide'] = stripSounds(d['q']) #d['q'] defined during loop's first iteration fields = runFilter("mungeFields", fields, model, data, self) html = anki.template.render(format, fields) #probably replace everything of the form {{ by its value d[type] = runFilter( "mungeQA", html, type, fields, model, data, self) # empty cloze? if type == 'q' and model['type'] == MODEL_CLOZE: if not self.models._availClozeOrds(model, data[6], False): d['q'] += ("<p>" + _( "Please edit this note and add some cloze deletions. (%s)") % ( "<a href=%s#cloze>%s</a>" % (HELP_SITE, _("help")))) #in the case where there is a cloze note type #without {{cn in fields indicated by #{{cloze:fieldName; an error message should be #shown return d
def mungeQA(deck, txt): txt = renderLatex(deck, txt) txt = stripSounds(txt) # osx webkit doesn't understand font weight 600 txt = re.sub("font-weight:.+?;", "font-weight: bold;", txt) return txt
def mungeQA(deck, txt): txt = stripSounds(txt) # osx webkit doesn't understand font weight 600 txt = re.sub("font-weight:.+?;", "font-weight: bold;", txt) return txt