diff --git a/anki/exporting.py b/anki/exporting.py index 5e18f73a8..837d81fd5 100644 --- a/anki/exporting.py +++ b/anki/exporting.py @@ -22,9 +22,10 @@ class Exporter(object): file.close() def escapeText(self, text): - "Escape newlines and tabs, and strip Anki HTML." + "Escape newlines, tabs and CSS." text = text.replace("\n", "
") text = text.replace("\t", " " * 8) + text = re.sub("(?i)", "", text) return text def cardIds(self): @@ -39,37 +40,27 @@ class Exporter(object): ###################################################################### class TextCardExporter(Exporter): - pass -# key = _("Text files (*.txt)") -# ext = ".txt" + key = _("Cards in Plain Text") + ext = ".txt" + hideTags = True -# def __init__(self, col): -# Exporter.__init__(self, col) + def __init__(self, col): + Exporter.__init__(self, col) -# def doExport(self, file): -# ids = self.cardIds() -# strids = ids2str(ids) -# cards = self.col.db.all(""" -# select cards.question, cards.answer, cards.id from cards -# where cards.id in %s -# order by cards.created""" % strids) -# self.cardTags = dict(self.col.db.all(""" -# select cards.id, notes.tags from cards, notes -# where cards.noteId = notes.id -# and cards.id in %s -# order by cards.created""" % strids)) -# out = u"\n".join(["%s\t%s%s" % ( -# 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])) + def doExport(self, file): + ids = sorted(self.cardIds()) + strids = ids2str(ids) + def esc(s): + # strip off the repeated question in answer if exists + s = re.sub("(?si)^.*
\n*", "", s) + return self.escapeText(s) + out = "" + for cid in ids: + c = self.col.getCard(cid) + out += esc(c.q()) + out += "\t" + esc(c.a()) + "\n" + file.write(out.encode("utf-8")) # Notes as TSV ###################################################################### @@ -294,6 +285,7 @@ def exporters(): exps = [ id(AnkiPackageExporter), id(TextNoteExporter), + id(TextCardExporter), ] runHook("exportersList", exps) return exps diff --git a/aqt/exporting.py b/aqt/exporting.py index 2d1605762..28fef7c7e 100644 --- a/aqt/exporting.py +++ b/aqt/exporting.py @@ -33,9 +33,11 @@ class ExportDialog(QDialog): def exporterChanged(self, idx): self.exporter = exporters()[idx][1](self.col) self.isApkg = hasattr(self.exporter, "includeSched") + self.hideTags = hasattr(self.exporter, "hideTags") self.frm.includeSched.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): self.exporter.includeSched = (