Thursday, July 14, 2005
Usually I don't mind HTML one bit, but posting the code bits today made me realize something: HTML sucks for pre-indented text. Apparently there are only three options for white-space preservation in HTML/CSS: pre and nowrap:

normal
This value directs user agents to collapse sequences of whitespace, and break lines as necessary to fill line boxes. Additional line breaks may be created by occurrences of "\A" in generated content (e.g., for the BR element in HTML).
pre
This value prevents user agents from collapsing sequences of whitespace. Lines are only broken at newlines in the source, or at occurrences of "\A" in generated content.
nowrap
This value collapses whitespace as for 'normal', but suppresses line breaks within text except for those created by "\A" in generated content (e.g., for the BR element in HTML).

normal certainly isn't appropriate, because that would not preserve the indentation. pre is almost appropriate, however it disallowes the rendering engine to insert line-breaks, which means the div section the code is in may extend in width arbitrarily. nowrap is obviously inappropriate as well.

What I really need is something close to pre but which allows automatic line-breaks; problem is, to my knowledge there simply isn't anything of the sort!

If anyone has some good advice on how to add indented, syntax-highlit code blocks to my blog painlessly I would be much obliged. I know there are tools out there - I've tried one or two - but none gave me the sort of flexibility I require. I may just break up and write a parser/colorizer with a bit more customizability than what Drazen did (impressive though it is).

Saturday, July 16, 2005 2:21:01 PM (Jerusalem Standard Time, UTC+02:00)
Check out the automatic syntax highlighting they use on Monologue:
http://www.go-mono.com/monologue/
http://www.go-mono.com/monologue/prettyprint.js

It allows you to simply insert XMP tags with class="code-csharp" and perform paintColors() on BODY's onload and it'll automatically colorize.
Ilya
Sunday, July 17, 2005 8:09:36 AM (Jerusalem Standard Time, UTC+02:00)
They do trivial regular expression matching - this is hardly an ideal solution; it's quick and simple but not elegant or powerful by any means. I would prefer a customizable "pretty printer"-type parser (something like Eclipse's impressive Code Formatting option) which could do automatic indentation, colorization etc.

I'll look further into that.
Monday, July 18, 2005 12:58:53 AM (Jerusalem Standard Time, UTC+02:00)
A JS-based lex/yacc, anyone? :)
Really, this would probably be the right approach at the problem. Not an easy undertaking, but a useful and gratifying one.
Ilya
Monday, July 18, 2005 8:25:59 AM (Jerusalem Standard Time, UTC+02:00)
Did I say JavaScript? :-) If I do actually get around to doing that (which I doubt, given my free time constraints) I'll probably write it in java or mono-friendly C#. Time will tell.
Tuesday, July 19, 2005 12:38:02 AM (Jerusalem Standard Time, UTC+02:00)
BTW, don't knock JavaScript. It's a rather nifty language if you look beyond its' common uses. Think - prototype-based inheritance, functions are objects ...
Ilya
Name
E-mail
Home page

Comment (Some html is allowed: a@href@title, b, blockquote@cite, em, i, strike, strong, sub, super, u) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Live Comment Preview