# Search ---------------------------------------------------
-def print_search_stats(hits, searched):
- print("<p>%d hits out of %d pages searched.</p>" % (hits, searched))
+def search_stats(hits, searched):
+ return("%d hits out of %d pages searched.\n" % (hits, searched))
def handle_fullsearch(query, form):
needle = form['q'].value
if count:
hits.append((count, page_name))
- # The default comparison for tuples compares elements in order,
- # so this sorts by number of hits
+ # The default comparison for tuples compares elements in order, so this sorts by number of hits
hits.sort()
hits.reverse()
- print("<ul>")
+ out = ''
for (count, page_name) in hits:
- print('<li><p>' + link_tag(page_name))
- print(' . . . . ' + `count`)
- print(['match', 'matches'][count != 1])
- print('</p></li>')
- print("</ul>")
+ out += ' * [[' + page_name + ']] . . . ' + str(count) + ' ' + ['match', 'matches'][count != 1] + '\n'
- print_search_stats(len(hits), len(all_pages))
+ out += search_stats(len(hits), len(all_pages))
+ WikiFormatter(out).print_html()
def handle_titlesearch(query, form):
needle = form['q'].value
all_pages = page_list()
hits = list(filter(needle_re.search, all_pages))
- print("<ul>")
+ out = ''
for filename in hits:
- print('<li><p>' + link_tag(filename) + "</p></li>")
- print("</ul>")
+ out += ' * [[' + filename + ']]\n'
- print_search_stats(len(hits), len(all_pages))
+ out += search_stats(len(hits), len(all_pages))
+ WikiFormatter(out).print_html()
def handle_raw(pagename, form):
if not file_re.match(pagename):
return __version__
class WikiFormatter:
- """Object that turns Wiki markup into HTML.
-
- All formatting commands can be parsed one line at a time, though
- some state is carried over between lines.
- """
+ """Object that turns Wiki markup into HTML."""
def __init__(self, raw, kvargs=None):
self.raw = raw
self.kvargs = kvargs or {}