# HG changeset patch # User Andreas Nolda # Date 1652261470 -7200 # Wed May 11 11:31:10 2022 +0200 # Node ID 1ae5775b4eabdcb6384b45b68d478eb39f5cbddd # Parent fb09589557fec4340c822e0296cd4aa6a538ac6e add option "-s" ("--spaces") diff --git a/ChangeLog.md b/ChangeLog.md --- a/ChangeLog.md +++ b/ChangeLog.md @@ -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: diff --git a/README.md b/README.md --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ [-p] [--pis] [-P] [--comments] [-q] [--quiet] + [-s] [--spaces] [-r ] [--regex ] @@ -45,15 +46,16 @@ 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 ` is set, the -[EXSLT function `: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 ` is set, +the [EXSLT function `: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 diff --git a/xgrep.py b/xgrep.py --- a/xgrep.py +++ b/xgrep.py @@ -8,7 +8,7 @@ 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 @@ 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 @@ 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