def downloadMissing(deck): from anki.latex import renderLatex urls = dict( deck.s.all("select id, features from models where features != ''")) if not urls: return None mdir = deck.mediaDir(create=True) os.chdir(mdir) deck.startProgress() missing = {} for (id, fid, val, mid) in deck.s.all(""" select fields.id, factId, value, modelId from fields, facts where facts.id = fields.factId"""): # add latex tags val = renderLatex(deck, val, False) for (full, fname, repl) in mediaRefs(val): if not os.path.exists(os.path.join(mdir, fname)) and mid in urls: missing[fname] = mid success = 0 for c, file in enumerate(missing.keys()): deck.updateProgress(label=_("Downloading %(a)d of %(b)d...") % { 'a': c, 'b': len(missing), }) try: data = urllib2.urlopen(urls[missing[file]] + file).read() open(file, "wb").write(data) success += 1 except: pass deck.finishProgress() return len(missing), success
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(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 = renderLatex(deck, txt) txt = stripSounds(txt) return txt