From f4a35e9b0317e3d6ddd1d4028d788797215da1a3 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Fri, 26 Nov 2010 01:48:54 +0900 Subject: [PATCH] support tags: at the top of file to import; fix comment stripping --- anki/importing/csvfile.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/anki/importing/csvfile.py b/anki/importing/csvfile.py index 5714886de..db0ed611e 100644 --- a/anki/importing/csvfile.py +++ b/anki/importing/csvfile.py @@ -75,9 +75,15 @@ class TextImporter(Importer): self.fileobj = open(self.file, "rbU") self.data = self.fileobj.read() self.data = self.data.lstrip(codecs.BOM_UTF8) - self.data = re.sub("^ *#.*", "", self.data) - self.data = [x for x in self.data.split("\n") if x] + def sub(s): + return re.sub( + "^\#.*", "", re.sub( + "^ +", "", s)) + self.data = [sub(x) for x in self.data.split("\n") if sub(x)] if self.data: + if self.data[0].startswith("tags:"): + self.tagsToAdd = self.data[0][5:] + del self.data[0] self.updateDelimiter() if not self.dialect and not self.delimiter: raise ImportFormatError(