Various methods to handle long lines of text

Sometimes the lines inside <source> elements are too wide, which can make the resulting pages too wide to view on screen or to print. The width of the long source line causes the whole page layout to be that same width. A web page that is wider than the screen is a complete bastard to read - you have to scroll right and left all the time. And printing in landscape orientation is not very nice either. (See Issue report COCOON-841.)

If everyone followed code conventions for Java and XML then this would not happen. However, there is no way to guarantee that.

Of course, there is the workaround solution to edit the offending source elements to specifically break long lines. Not good for automated solutions or separation of concerns.

We need to find a way to consistently split lines that are too wide. Here are demonstrations of various solutions. Each one has pros and cons. Please help to enhance these solutions so that one can soon be implemented. (See Notes below.)

The following examples are deliberately extreme to ensure that the issues are triggered.

Using no special handling

No special handling was done for the <source> elements. The content is wrapped with a <pre> element. Note the long right-left scrollbar.

Using the "split.xsl" stylesheet

All <source> elements had their long lines wrapped at a defined width (72) by the included split.xsl stylesheet. Lines with no whitespace (such as long URLs) are forcefully split at 72 characters. The content is wrapped with a <pre> element.

Note: In past Cocoons this stylesheet has been reported to be a memory hog on certain JVMs. How does it go for you?

Using the "wrap2para.xsl" stylesheet

Only <source> elements that contain an xml content model had their lines handled by the included wrap2para.xsl stylesheet. It does not intend to address all cases of source, only type=xml source. Lines are each wrapped with a styled <p> element.

Using the "docnbsp.xsl" stylesheet

Sequences of two consecutive spaces are replaced by a non-breaking space and a regular space. Each line is encased in a <code><br/> This method keeps the text indentation that would be obtained with a <pre> while still allowing line wrapping by the browser. This utilises the exslt extension for strings.

Other notes

Suggested enhancements include: using the @type attribute; "content sniff"; ...

There may be some other solutions. Suggestions include the Chaperon Block and maybe the Slop Block.

See the issue report (COCOON-841) and the links to the cocoon-dev and forrest-dev mail discussion.

Some testcase documents ...