add option "-s" ("--spaces")
3 files changed, 18 insertions(+), 10 deletions(-)

M ChangeLog.md
M README.md
M xgrep.py
M ChangeLog.md +2 -0
@@ 1,6 1,8 @@ 
 2022-05-11:
 
 * add options `-p` (`--pis`) and `-P` (`--comments`)
+* add option `-s` (`--spaces`)
+* bump version to 2.10
 
 
 2020-04-26:

          
M README.md +11 -9
@@ 34,6 34,7 @@ Usage:
              [-p] [--pis]
              [-P] [--comments]
              [-q] [--quiet]
+             [-s] [--spaces]
              [-r <ns>] [--regex <ns>]
              <XPath expression>
              <XML file(s)>

          
@@ 45,15 46,16 @@ Usage:
 Normally, `xgrep.py` outputs the matching parts of the XML files together with
 their file names and the XPath expression. The option `-m` outputs only the
 matching parts, without file names or XPath expressions; with `-M`, the matching
-parts are prefixed with the corresponding file name. If `-r <ns>` is set, the
-[EXSLT function `<ns>:test()`](http://exslt.org/regexp/functions/test/) can be
-used in the XPath expression for matching regular expressions. The option `-i`
-indents the matching parts, and the option `-N` includes namespace declarations.
-Matching parts can be abbreviated to their first line by means of the option
-`-a`. Processing instructions and comments in the XML files are ignored unless
-the `-p` and `-P` options are used. The `-C` option preserves color and
-formatting codes when piping output
-through [GNU less](http://www.gnu.org/software/less/) or similar programs.
+parts are prefixed with the corresponding file name. If `-r <ns>` is set,
+the [EXSLT function `<ns>:test()`](http://exslt.org/regexp/functions/test/) can
+be used in the XPath expression for matching regular expressions. The option
+`-i` indents the matching parts, and the option `-N` includes namespace
+declarations. Matching parts can be abbreviated to their first line by means of
+the option `-a`. The option `-s` normalises whitespace to spaces in the output.
+Processing instructions and comments in the XML files are ignored unless the
+`-p` and `-P` options are used. The `-C` option preserves color and formatting
+codes when piping output through [GNU less](http://www.gnu.org/software/less/)
+or similar programs.
 
 The options `-c`, `-l`, `-L`, `-n`, and `-q` mimic the behaviour of
 [GNU grep](http://www.gnu.org/software/grep/). The latter option suppresses any

          
M xgrep.py +5 -1
@@ 8,7 8,7 @@ import re
 from blessings import Terminal
 from lxml import etree
 
-version = 2.9
+version = 2.10
 
 parser = argparse.ArgumentParser()
 parser.add_argument("expr",

          
@@ 43,6 43,8 @@ parser.add_argument("-q", "--quiet", act
                     help="only return exit status")
 parser.add_argument("-r", "--regex", metavar="ns",
                     help="namespace prefix for EXSLT regular expressions")
+parser.add_argument("-s", "--spaces", action="store_true",
+                    help="normalize whitespace to spaces")
 parser.add_argument("-v", "--version", action="version",
                     version="{0} {1}".format(parser.prog, version))
 args = parser.parse_args()

          
@@ 89,6 91,8 @@ def serialize_match(match):
         string = lines[0]
         if len(lines) > 1:
             string += " " + term.bright_black("...")
+    if args.spaces:
+        string = re.sub("\s+", " ", string)
     if string.endswith("\n"):
         string = string[:-1]
     return string