HTML de-uglifier in 2 lines of perl
[email protected] (Phil Carmody)
| Newsgroups | perl.golf |
|---|---|
| Message-ID | <[email protected]> |
#!/usr/bin/perl -n
chomp;if($#p>=0&&s/^(\"?>)//){$p[-1].="$1\n";print(join($w<70?' ':"\n",@p));@p=($_);$w=0}
else{push@p,$_}$w+=length;}{print(join("\n",@p))if($#p>=0);
I wrote that because docbook2html produces ugly HTML:
<<<
<HTML
><HEAD
><TITLE
>A World Wide Web Interface to CTAN</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
"></HEAD
><BODY
...
>>>
and I wanted (IMHO) prettier HTML:
<<<
<HEAD>
<TITLE>
A World Wide Web Interface to CTAN</TITLE>
<META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+">
</HEAD>
<BODY
...
>>>
The script also tries to join multiple attributes onto the same line,
as long as the line wouldn't be too long (70 chars) as I also find that
improves the readability of HTML (by reducing the noise level).
As I suck at perl, I reckon that something only half the length of that
might be possible.
Don't spend more than 2 minutes on it. I didn't!
Phil
=====
Given that Dubya has control of a such vast arsenal, I'm sure
the most pressing issue on his mind is :
Which bombs would Jesus drop? (-- "mm")
________________________________________________________________________
Want to chat instantly with your online friends? Get the FREE Yahoo!
Messenger http://mail.messenger.yahoo.co.uk