From 465199e5822dfa85ca4fddb8bf0ae79641e0aa4e Mon Sep 17 00:00:00 2001 From: Bernie Innocenti Date: Mon, 22 Mar 2010 23:37:53 -0300 Subject: [PATCH] Use wiki to format search pages (saves 12 lines) --- geekigeeki.py | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/geekigeeki.py b/geekigeeki.py index 0fdd421..b3eed3c 100755 --- a/geekigeeki.py +++ b/geekigeeki.py @@ -177,8 +177,8 @@ def link_inline_glob(pattern, descr=None, kvargs={}): # Search --------------------------------------------------- -def print_search_stats(hits, searched): - print("

%d hits out of %d pages searched.

" % (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 @@ -193,20 +193,16 @@ def handle_fullsearch(query, form): 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("") + 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 @@ -216,12 +212,12 @@ def handle_titlesearch(query, form): all_pages = page_list() hits = list(filter(needle_re.search, all_pages)) - print("") + 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): @@ -282,11 +278,7 @@ def _macro_VERSION(*args, **kvargs): 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 {} -- 2.25.1