X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/e2d4fbf230c90dcf3e904351a70d399426478352..78e13f577ab9db6cb8cc181833e351ab792cebe9:/apps/catalogue/management/edumed.py diff --git a/apps/catalogue/management/edumed.py b/apps/catalogue/management/edumed.py index ffad2ec1..55269d1e 100644 --- a/apps/catalogue/management/edumed.py +++ b/apps/catalogue/management/edumed.py @@ -15,7 +15,7 @@ class Tagger: def line(self, position): return self.lines[position] - ignore = [ re.compile(r"^[\[][PA][\]] - [^ ]+$") ] + ignore = [re.compile(r"^[\[][PA][\]] - [^ ]+$")] empty_line = re.compile(r"^\s+$") def skip_empty(self, position): @@ -26,7 +26,6 @@ class Tagger: position += 1 return position - def tag(self, position): """ Return None -- means that we can't tag it in any way @@ -36,6 +35,11 @@ Return None -- means that we can't tag it in any way def wrap(self, tagname, content): return u"<%s>%s" % (tagname, content, tagname) + @staticmethod + def anymatches(regex): + return lambda x: regex.match(x) + + class Section(Tagger): looks_like = re.compile(r"^[IVX]+[.]\s+(.*)$") @@ -87,11 +91,14 @@ class Informacje(Tagger): class List(Tagger): + point = re.compile(r"^[\s]*([-*])") + def tag(self, pos): self.items = [] while True: l = self.line(pos) - if l and l[0] in ('-', '*'): + m = self.point.match(l) + if l and m: self.items.append(l[1:].strip()) pos += 1 else: @@ -100,10 +107,10 @@ class List(Tagger): return pos def __unicode__(self): - s = "\n" + s = '' for i in self.items: - s += "%s\n" % i - s += "\n" + s += "\n%s" % i + s += "\n\n" return s