[jdom-interest] XHTML issues
Bradley S. Huffman
hip at cs.okstate.edu
Wed Aug 13 10:48:59 PDT 2003
Jason Hunter writes:
> Elliotte Rusty Harold wrote:
>
> > At 11:21 PM +0100 7/25/03, Rachel Greenham wrote:
> >
> >
> >> The other issue I had by the way was that EntityRefs are being printed
> >> out with surrounding newlines if newlines is true on the XMLOutputter.
> >> This has the effect that they get surrounded by a visible space when
> >> displayed in a browser. When you're using entities for quote marks,
> >> apostrophes, and accented letters (most of the time in fact) this is
> >> obviously not wanted. However, setting the XMLOutputter to not
> >> generate newlines makes the source very unpleasant and difficult to
> >> look at manually (eg: a 30,000 word story crushed to 66 logical lines,
> >> most of those in a <pre> block, for instance).
> >
> > Hmm, that really sounds like a bug. Entity references should not be
> > surrounded by newlines even when indenting for the reasons you cite. Has
> > anyone fixed this yet? If not, I could give it a shot.
>
> No one's patched a bug like this, and I'd welcome you doing so. One
> thought is to first make sure it's not whitespace being added for other
> reasons.
Here's a first attempt at a patch but I don't have time right now to test and
debug it, or verify it is a sufficient solution. But if someone else has time
this afternoon and wants to play with it, it's a start.
Brad
*** XMLOutputter.old Wed Aug 13 12:17:27 2003
--- XMLOutputter.java Wed Aug 13 12:24:20 2003
***************
*** 1145,1153 ****
next = content.get(index);
//
! // Handle consecutive CDATA and Text nodes all at once
//
! if (next instanceof Text) {
first = skipLeadingWhite(content, index);
// Set index to next node for loop
index = nextNonText(content, first);
--- 1145,1153 ----
next = content.get(index);
//
! // Handle consecutive CDATA, Text, and EntityRef nodes all at once
//
! if ((next instanceof Text) || (next instanceof EntityRef)) {
first = skipLeadingWhite(content, index);
// Set index to next node for loop
index = nextNonText(content, first);
***************
*** 1224,1230 ****
// Get the unmangled version of the text
// we are about to print
! next = ((Text) node).getText();
// This may save a little time
if (next == null || "".equals(next)) {
--- 1224,1239 ----
// Get the unmangled version of the text
// we are about to print
! if (node instanceof Text) {
! next = ((Text) node).getText();
! }
! else if (node instanceof EntityRef) {
! next = "&" + ((EntityRef) node).getValue() + ";";
! }
! else {
! throw new IllegalStateException("should of seen only " +
! "CDATA, Text, or EntityRef");
! }
// This may save a little time
if (next == null || "".equals(next)) {
***************
*** 1438,1444 ****
int index = start;
int size = content.size();
while (index < size) {
! if (!(content.get(index) instanceof Text)) {
return index;
}
index++;
--- 1447,1454 ----
int index = start;
int size = content.size();
while (index < size) {
! Object node = content.get(index);
! if ( !((node instanceof Text) || (node instanceof EntityRef))) {
return index;
}
index++;
More information about the jdom-interest
mailing list