Commit 154c0889 authored by Guido van Rossum's avatar Guido van Rossum

Refactor cmd_view(): move line formatting to a helper method.

parent 9c3848b3
...@@ -31,23 +31,25 @@ class WikiPage: ...@@ -31,23 +31,25 @@ class WikiPage:
line = line.rstrip() line = line.rstrip()
if not line: if not line:
print "<p>" print "<p>"
continue else:
words = re.split('(\W+)', line) print self.formatline(line)
for i in range(len(words)):
word = words[i]
if self.iswikiword(word):
if os.path.isfile(self.mkfile(word)):
word = self.mklink("view", word, word)
else:
word = self.mklink("new", word, word + "*")
else:
word = escape(word)
words[i] = word
print "".join(words)
print "<hr>" print "<hr>"
print "<p>", self.mklink("edit", self.name, "Edit this page") + ";" print "<p>", self.mklink("edit", self.name, "Edit this page") + ";"
print self.mklink("view", "FrontPage", "go to front page") + "." print self.mklink("view", "FrontPage", "go to front page") + "."
def formatline(self, line):
words = []
for word in re.split('(\W+)', line):
if self.iswikiword(word):
if os.path.isfile(self.mkfile(word)):
word = self.mklink("view", word, word)
else:
word = self.mklink("new", word, word + "*")
else:
word = escape(word)
words.append(word)
return "".join(words)
def cmd_edit(self, form, label="Change"): def cmd_edit(self, form, label="Change"):
print "<h1>", label, self.name, "</h1>" print "<h1>", label, self.name, "</h1>"
print '<form method="POST" action="%s">' % self.scripturl print '<form method="POST" action="%s">' % self.scripturl
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment