From 3e297efad8e6dbb7622cedd68a2457f00dd09080 Mon Sep 17 00:00:00 2001 From: eliott Date: Sat, 29 Dec 2007 16:42:55 -0800 Subject: Massive retab fest. Also added vim command comment to the end of files. --- wiki/models.py | 23 ++++++----- wiki/templatetags/wikitags.py | 95 ++++++++++++++++++++++--------------------- wiki/views.py | 3 ++ 3 files changed, 65 insertions(+), 56 deletions(-) (limited to 'wiki') diff --git a/wiki/models.py b/wiki/models.py index 2b8b16fc..85f0726c 100644 --- a/wiki/models.py +++ b/wiki/models.py @@ -2,15 +2,18 @@ from django.contrib.auth.models import User class Wikipage(models.Model): - """Wiki page storage""" - title = models.CharField(maxlength=255) - content = models.TextField() - last_author = models.ForeignKey(User) - class Meta: - db_table = 'wikipages' + """Wiki page storage""" + title = models.CharField(maxlength=255) + content = models.TextField() + last_author = models.ForeignKey(User) + class Meta: + db_table = 'wikipages' - def editurl(self): - return "/wiki/edit/" + self.title + "/" + def editurl(self): + return "/wiki/edit/" + self.title + "/" + + def __repr__(self): + return self.title + +# vim: set ts=4 sw=4 et: - def __repr__(self): - return self.title diff --git a/wiki/templatetags/wikitags.py b/wiki/templatetags/wikitags.py index e8a8a035..c8c1cd38 100644 --- a/wiki/templatetags/wikitags.py +++ b/wiki/templatetags/wikitags.py @@ -6,52 +6,55 @@ register = Library() class WikiProcessor: - def run(self, lines): - in_table = False - for i in range(len(lines)): - # Linebreaks - lines[i] = re.sub("%%", "
", lines[i]) - # Internal Links - lines[i] = re.sub("\(\(([A-z0-9 :/-]+)\)\)", "\\1", lines[i]) - # Small Text - lines[i] = re.sub("----([^----]+)----", "\\1", lines[i]) - lines[i] = re.sub("--([^--]+)--", "\\1", lines[i]) - # TT text - lines[i] = re.sub("\{\{([^}\}]+)\}\}", "\\1", lines[i]) - # Tables - m = re.match("(\|\|)", lines[i]) - if m: - count = len(re.findall("(\|\|+)", lines[i])) - first = True - m2 = re.search("(\|\|+)", lines[i]) - while m2 and count: - count -= 1 - colspan = len(m2.group(1)) / 2 - if first: - repl = "" % (colspan) - first = False - elif count == 0: - repl = "" - else: - repl = "" % (colspan) - lines[i] = re.sub("(\|\|+)", repl, lines[i], 1) - # find the next chunk - m2 = re.search("(\|\|+)", lines[i]) - lines[i] = "" + lines[i] + "" - if not in_table: - lines[i] = "" + lines[i] - in_table = True - elif in_table: - lines[i] = "
" + lines[i] - in_table = False - # close leftover table, if open - if in_table: - lines[len(lines)] = lines[len(lines)] + "" - return lines + def run(self, lines): + in_table = False + for i in range(len(lines)): + # Linebreaks + lines[i] = re.sub("%%", "
", lines[i]) + # Internal Links + lines[i] = re.sub("\(\(([A-z0-9 :/-]+)\)\)", "\\1", lines[i]) + # Small Text + lines[i] = re.sub("----([^----]+)----", "\\1", lines[i]) + lines[i] = re.sub("--([^--]+)--", "\\1", lines[i]) + # TT text + lines[i] = re.sub("\{\{([^}\}]+)\}\}", "\\1", lines[i]) + # Tables + m = re.match("(\|\|)", lines[i]) + if m: + count = len(re.findall("(\|\|+)", lines[i])) + first = True + m2 = re.search("(\|\|+)", lines[i]) + while m2 and count: + count -= 1 + colspan = len(m2.group(1)) / 2 + if first: + repl = "" % (colspan) + first = False + elif count == 0: + repl = "" + else: + repl = "" % (colspan) + lines[i] = re.sub("(\|\|+)", repl, lines[i], 1) + # find the next chunk + m2 = re.search("(\|\|+)", lines[i]) + lines[i] = "" + lines[i] + "" + if not in_table: + lines[i] = "" + lines[i] + in_table = True + elif in_table: + lines[i] = "
" + lines[i] + in_table = False + # close leftover table, if open + if in_table: + lines[len(lines)] = lines[len(lines)] + "" + return lines @register.filter def wikify(value): - md = markdown.Markdown(value) - md.preprocessors.insert(0, WikiProcessor()) - html = md.toString() - return html + md = markdown.Markdown(value) + md.preprocessors.insert(0, WikiProcessor()) + html = md.toString() + return html + +# vim: set ts=4 sw=4 et: + diff --git a/wiki/views.py b/wiki/views.py index 9f7bd78d..796f5f98 100644 --- a/wiki/views.py +++ b/wiki/views.py @@ -59,3 +59,6 @@ def delete(request): return HttpResponseRedirect("/wiki/") page.delete() return HttpResponseRedirect("/wiki/") + +# vim: set ts=4 sw=4 et: + -- cgit v1.2.3-54-g00ecf