cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Conal Tuohy <>
Subject RE: Another attempt at wrapping code lines
Date Sat, 15 Nov 2003 05:26:19 GMT
Hi Sylvain

I've checked out your new attempt "docnbsp.xsl" and compared with the other
approaches in the text-wrap sample.

Your attempt is definitely superior to the current approach ("no special
handling" in the sample) implemented by raw.xsl, which uses just HTML <pre>.
The raw.xsl often leads to infeasibly long lines, which have the effect of
making the entire web page too wide to print, or view without horizontal

Your attempt is also better than the split.xsl result in that it maintains
the original lines of source and allows the browser to break lines where
necessary to fit into the HTML container width. It's more appropriate for
the browser to make decisions on line lengths. If your browser is wide
enough and/or you have a small enough font, then no line break will ever
happen. So you can still copy and paste snippets of source code from the
docs and immediately use it (this is important in my opinion).

So I think docnbsp is the best candidate for a detault <source>-handling

The part of the text-wrap sample which I did, "wrap2para", uses a similar
approach to yours in that it retains each line of the original source (as
HTML <p>...</p>, rather than as <code>...</code><br>, but pretty
My xsl also replaced all spaces inside double-quotes with &nbsp; to prevent
the browser wrapping inside quoted strings, which is a similar idea. But
others pointed out that to make these decisions optimally you need to know
the type of the <source> e.g. xml, java, etc.

I also think that for <source> containing quoted XML a fixed-width font is
not important, and a variable-width font would be much more readable, as
well as narrower which wwould greatly reduce the need for line-breaks in the
first place. I realise this can't be done in general, because part of the
contract of <source> is that it is generally rendered in a fixed-width font,
but I think if it can be made to apply only to e.g. XML or Java, then it
would be OK.

I've also been working on another template, based on wrap2para, which only
matches <source> elements which start with &lt; and ends with &gt;, and then
adds XML syntax highlighting. I'll merge and upload a patch shortly. It uses
a FSM in XSLT to parse the quoted XML markup. I've got it running on my
machine at home in the meantime, installed as the stylesheet driving the
Cocoon docs, so it handles everything under:

Take a look! I haven't checked every page, but it works for the ones I've
read, and in particular, it's a big improvement for the modules page which
was really wide:

... but I think it's more readable and better even for the narrow <source>.
I like syntax highlighting :-)

So my suggestion is, that we should make your docnbsp.xsl the default source
handler, and my highlightmarkup.xsl the handler specifically for source
containing XML.

Any other types of source should also be dealt with by more specific
stylesheets. Nicola Ken Barozzi suggested a syntax highlighter for Java on
the Forrest list, but I was more keen to do XML first since the "itch" that
I was scratching was precisely the Cocoon docs, which have mostly
XML-flavoured <source>; sitemap snippets, xslt, basically every kind of xml
namespace... I think Java would be only about the same complexity though:
for highlighting, say, comments, keywords, strings, numbers, and punctuation
symbols. It's not necessary to do a deep parse, just a simple tokenising



> -----Original Message-----
> From: Sylvain Wallez []
> Sent: Saturday, 15 November 2003 04:57
> To:
> Subject: Another attempt at wrapping code lines
> Hi all,
> I looked at David's "text-wrap" sample and added another
> attempt: every
> sequence of two consecutive spaces is replaced by a
> non-breaking space
> and a regular space.
> This keeps the text indentation that would be obtained with a <pre>
> while still allowing line wrapping.
> I tried to find a CSS trick to add a mark at the beginning of a
> continuation line, but CSS only has ":first-line" and no
> ":other-lines".
> Please have a look at it, it seems to be to be a good
> compromise between
> keeping code indentation and readability of wrapped lines.
> Sylvain
> --
> Sylvain Wallez                                  Anyware Technologies
> { XML, Java, Cocoon, OpenSource }*{ Training, Consulting, Projects }
> Orixo, the opensource XML business alliance  -

View raw message