[Assorted-commits] SF.net SVN: assorted:[1484] shell-tools/trunk/src/hdr-grep.py
Brought to you by:
yangzhang
From: <yan...@us...> - 2009-10-14 04:58:28
|
Revision: 1484 http://assorted.svn.sourceforge.net/assorted/?rev=1484&view=rev Author: yangzhang Date: 2009-10-14 04:58:22 +0000 (Wed, 14 Oct 2009) Log Message: ----------- hdr-grep also searches titles Modified Paths: -------------- shell-tools/trunk/src/hdr-grep.py Modified: shell-tools/trunk/src/hdr-grep.py =================================================================== --- shell-tools/trunk/src/hdr-grep.py 2009-10-14 04:52:45 UTC (rev 1483) +++ shell-tools/trunk/src/hdr-grep.py 2009-10-14 04:58:22 UTC (rev 1484) @@ -1,10 +1,10 @@ #!/usr/bin/env python """ -Prints the titles of sections in stdin whose bodies contain the given query -text (case-insensitive). Assumes input is markdown-/pandoc-formatted and only -looks for level-1 and -2 headers (lines that are underlined with at least 3 = -or - characters). +Given a markdown-/pandoc-formatted document on stdin, print the titles of +sections whose titles or bodies contain the given query text +(case-insensitive). Only looks for underlined level-1 and -2 headers (lines +that are underlined with at least 3 = or - characters). """ from commons.seqs import pairwise @@ -15,6 +15,9 @@ for prev, line in pairwise(line.rstrip() for line in sys.stdin): if len(line) >= 3 and set(line) in [set('-'), set('=')]: hdr = prev - elif hdr is not None and query.lower() in line.lower(): + haystack = prev + else: + haystack = line + if hdr is not None and query.lower() in haystack.lower(): print hdr hdr = None This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |