From: Bernie Innocenti Date: Tue, 23 Mar 2010 02:37:53 +0000 (-0300) Subject: Use wiki to format search pages (saves 12 lines) X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=465199e5822dfa85ca4fddb8bf0ae79641e0aa4e;p=geekigeeki.git Use wiki to format search pages (saves 12 lines) --- 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 {}