Subject: | Feature Request with patch: cvs-friendly pretty-print option |
Date: | Wed, 14 Feb 2007 23:21:38 +0200 |
To: | bug-XML-Twig [...] rt.cpan.org |
From: | Sjur Moshagen <sjurnm [...] mac.com> |
Hello,
Twig produces a number of useful output formats, but not exactly what
is needed to adhere to the guidelines outlined at http://
www.oracle.com/webapps/online-help/jdeveloper/10.1.3/state/content/
navId.4/navSetId._/vtTopicFile.teamworking%7Cscs%
7Cscs_u_writingversioncontrollablexml~html/ - Writing Version
Controllable XML.
Specifically, the following combination of options isn't available in
my version (which is not the completely newest, but according to the
changelog, this feature has not yet been added):
* attributes, in sorted order, on separate lines from their element
* indented output (easier human readability)
* wrapped lines
All of them are available in one or more of the existing pp formats,
but not all three combined. The attached patch adds a new pp option
indented_a (_a as in attribute), with alias cvs, which provides this
output style.
The rationale behind this output style is to reduce the number of
irrelevant diffs when xml documents are stored in a version control
system like CVS. As with most other output styles, this one is NOT
guaranteed to keep the document valid according to the DTD. Use at
your own risk:-)
The patched version was tested on a small XML document, and seemed to
perform as expected, but should probably be tested on larger
documents before the change is commited.
The patch is made against the following version:
# $Id: Twig_pm.slow,v 1.303 2006/05/26 08:07:14 mrodrigu Exp $
It was made and tested on the following system:
Mac OS X 10.4.8
This is perl, v5.8.6 built for darwin-thread-multi-2level
(with 3 registered patches, see perl -V for more detail)
As I don't know how the bug tracker handles e-mail attachements, I
also paste in the patch at the end of this e-mail (it is short).
Best regards,
Sjur
6842c6842
< my ($NSGMLS, $NICE, $INDENTED, $INDENTEDC, $WRAPPED, $RECORD1,
$RECORD2)= (1..7);
---
Show quoted text
> my ($NSGMLS, $NICE, $INDENTED, $INDENTEDA, $INDENTEDC, $WRAPPED,
$RECORD1, $RECORD2)=
(1..8);
6850a6851,6855
Show quoted text > indented_a => $INDENTEDA, # nice, indented, and with
attributes on separate
Show quoted text > # lines as the nsgmls style, as
well as wrapped
Show quoted text > # lines - to make the xml friendly
against line-
Show quoted text > # oriented diffs
> cvs => $INDENTEDA, # alias for indented_a
6950c6955
< if( $pretty == $WRAPPED)
---
Show quoted text > if( ($pretty == $WRAPPED) || ($pretty == $INDENTEDA) )
7111c7116,7123
< $tag .= $pretty==$NSGMLS ? "\n" : ' ';
---
Show quoted text > $tag .= ( ($pretty==$NSGMLS) || ($pretty==
$INDENTEDA) ) ? "\n" : ' ';
Show quoted text >
> if( $pretty==$INDENTEDA)
> { my $indent= $elt->level;
> my $prefix='';
> $prefix= $INDENT x $indent;
> $tag .= $prefix . ' ';
> }
7164c7176
< elsif( ($pretty==$INDENTED) || ($pretty==$INDENTEDC) ||
($pretty==$WRAPPED))
---
Show quoted text > elsif( ($pretty==$INDENTED) || ($pretty==$INDENTEDA) ||
($pretty==$INDENTEDC) || (
$pretty==$WRAPPED))
7240c7252
< elsif( ($pretty==$INDENTED) || ($pretty==$WRAPPED) )
---
Show quoted text > elsif( ($pretty==$INDENTED) || ($pretty==$INDENTEDA) ||
($pretty==$INDENTEDC) || (
$pretty==$WRAPPED) )
7411c7423
< if( $pretty== $WRAPPED && !$xml_space_preserve)
---
Show quoted text > if( ($pretty== $WRAPPED || $pretty== $INDENTEDA) && !
$xml_space_preserve)
Message body is not shown because sender requested not to inline it.