card tsv exporter

This commit is contained in:
Damien Elmes 2012-12-21 21:32:21 +09:00
parent 873811a56e
commit 011cbde3b9
2 changed files with 24 additions and 30 deletions

View file

@ -22,9 +22,10 @@ class Exporter(object):
file.close() file.close()
def escapeText(self, text): def escapeText(self, text):
"Escape newlines and tabs, and strip Anki HTML." "Escape newlines, tabs and CSS."
text = text.replace("\n", "<br>") text = text.replace("\n", "<br>")
text = text.replace("\t", " " * 8) text = text.replace("\t", " " * 8)
text = re.sub("(?i)<style>.*?</style>", "", text)
return text return text
def cardIds(self): def cardIds(self):
@ -39,37 +40,27 @@ class Exporter(object):
###################################################################### ######################################################################
class TextCardExporter(Exporter): class TextCardExporter(Exporter):
pass
# key = _("Text files (*.txt)") key = _("Cards in Plain Text")
# ext = ".txt" ext = ".txt"
hideTags = True
# def __init__(self, col): def __init__(self, col):
# Exporter.__init__(self, col) Exporter.__init__(self, col)
# def doExport(self, file): def doExport(self, file):
# ids = self.cardIds() ids = sorted(self.cardIds())
# strids = ids2str(ids) strids = ids2str(ids)
# cards = self.col.db.all(""" def esc(s):
# select cards.question, cards.answer, cards.id from cards # strip off the repeated question in answer if exists
# where cards.id in %s s = re.sub("(?si)^.*<hr id=answer>\n*", "", s)
# order by cards.created""" % strids) return self.escapeText(s)
# self.cardTags = dict(self.col.db.all(""" out = ""
# select cards.id, notes.tags from cards, notes for cid in ids:
# where cards.noteId = notes.id c = self.col.getCard(cid)
# and cards.id in %s out += esc(c.q())
# order by cards.created""" % strids)) out += "\t" + esc(c.a()) + "\n"
# out = u"\n".join(["%s\t%s%s" % ( file.write(out.encode("utf-8"))
# self.escapeText(c[0], removeFields=True),
# self.escapeText(c[1], removeFields=True),
# self.tags(c[2]))
# for c in cards])
# if out:
# out += "\n"
# file.write(out.encode("utf-8"))
# def tags(self, id):
# return "\t" + ", ".join(parseTags(self.cardTags[id]))
# Notes as TSV # Notes as TSV
###################################################################### ######################################################################
@ -294,6 +285,7 @@ def exporters():
exps = [ exps = [
id(AnkiPackageExporter), id(AnkiPackageExporter),
id(TextNoteExporter), id(TextNoteExporter),
id(TextCardExporter),
] ]
runHook("exportersList", exps) runHook("exportersList", exps)
return exps return exps

View file

@ -33,9 +33,11 @@ class ExportDialog(QDialog):
def exporterChanged(self, idx): def exporterChanged(self, idx):
self.exporter = exporters()[idx][1](self.col) self.exporter = exporters()[idx][1](self.col)
self.isApkg = hasattr(self.exporter, "includeSched") self.isApkg = hasattr(self.exporter, "includeSched")
self.hideTags = hasattr(self.exporter, "hideTags")
self.frm.includeSched.setShown(self.isApkg) self.frm.includeSched.setShown(self.isApkg)
self.frm.includeMedia.setShown(self.isApkg) self.frm.includeMedia.setShown(self.isApkg)
self.frm.includeTags.setShown(not self.isApkg) self.frm.includeTags.setShown(
not self.isApkg and not self.hideTags)
def accept(self): def accept(self):
self.exporter.includeSched = ( self.exporter.includeSched = (