forrest-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Conal Tuohy <con...@paradise.net.nz>
Subject RE: [PATCH] for <source> elements that are too wide
Date Wed, 22 Oct 2003 20:28:06 GMT
Nicola Ken Barozzi wrote:

> Conal Tuohy wrote:
>
> > Some of the pages in the Cocoon HTML-format documentation
> are too wide to
> > display on screen, or print in portrait-orientation on
> paper, because of
> > <source> elements with very long lines.

> ...

> At some point, we already had a stylesheed that broke the
> source tag in
> many, but it used too much memory so we disabled it.

This template doesn't seem to use too much memory (I've not had any problems
with it) and though I haven't seen the template you disabled, I suspect my
template does less than the template you disabled: it does NOT actually
break lines of source: it merely transforms lines which are already
delimited by line-break characters into HTML paragraphs. However, by
transforming each line into a paragraph, it does allow the browser to wrap
lines which are very long. In order to prevent the browser making such
line-breaks within string literals, the template replaces spaces in string
literals with non-breaking spaces. So XML attribute values, and Java string
constants won't be broken by the browser.

> The fact is that wrapping is dependant on the language used, so it
> should really be done by a real parser. This means that IMHO it's
> correct to keep <pre> as is for default.

Although this template is not a sophisticated parser, it does in fact do a
reasonable job with both XML and Java source. I wrote it with both of these
in mind, particularly XML, since the particular itch I was scratching was
the Cocoon documentation, which is full of very wide sitemap etc snippets.
Generally line breaks are not significant in Java, but as it stands, this
template would allow a browser to wrap a Java // comment if it was very
wide, which would look wrong, I concede. Maybe I could adjust it to handle
// comments as well ...

On the other hand, if people copy and paste from an HTML page generated from
the template, the long lines would still exist  since they would still exist
as HTML paras.

> What should instead be done, is that this kind of source, for example:
>
>   <source type="java">
>     import...
>     class...
>   </source>
>
> gets transformed in highlighted java code. If someone does a
> patch for
> this, I'll insert it in Forrest in no time :-)

I realise that the <source> element could enclose any kind of source ... and
I'm reluctant to write a full Java parser in XSLT :-)

XML is a different story though: perhaps if I changed it to "sniff" XML
content in the source then it would be suitable? Perhaps:

<xsl:template match="source[starts-with(.,'&lt;') or @type='xml']">

I would even add XML highlighting to the template if that would make it
acceptable.

Cheers

Con


Mime
View raw message