#!/usr/bin/perl $u = shift @ARGV; # Download the requested page. $html = `lynx -dump -source "$u"`; # Print top print < View Source: $u

View Source: $u


EOF # main loop @classStack = (); $h = &popHTMLChar(); while ($h ne 'EOF') { # handle new lines if ($h eq "\n") { print "
\n"; } # handle entities elsif ($h eq '&') { &startClass('entity'); print '&'; } elsif ( ($h eq ';') && ($classStack[-1] eq 'entity') ) { print ';'; &endClass(); } # handle tags, comments, xml PIs and doctypes elsif ($h eq '<') { if ( substr($html, 0, 3) eq '!--' ) { &startClass('comment'); print '<'; } elsif ( substr($html, 0, 8) eq '!DOCTYPE' ) { &startClass('doctype'); print '<'; } elsif ( substr($html, 0, 4) eq '?xml' ) { &startClass('xmlpi'); print '<'; } else { &startClass('tag'); print '<'; &startClass('element'); } } elsif ( ( ($h eq ' ') || ($h eq '>') || ($h eq "\t") || ($h eq "\n") ) && ($classStack[-1] eq 'element') ) { &endClass(); if ($h eq '>') { print '>'; &endClass(); } elsif ($h eq "\t") { print '  '; } elsif ($h eq "\n") { print '
'; } else { print $h; } } elsif ($h eq '>') { print '>'; &endClass(); } # handle attribute values elsif ( ( ($h eq '"') || ($h eq "\'") ) && ($classStack[-1] eq 'tag') ) { &startClass('attribute'); print $h; } elsif ( ( ($h eq '"') || ($h eq "\'") ) && ($classStack[-1] eq 'attribute') ) { print $h; &endClass(); } elsif ($h eq ' ') { print ' '; } elsif ($h eq "\t") { print '  '; } else { print $h; } $h = &popHTMLChar(); } # Print foot print <

Made using html2highlight.pl 0.01. © 2003 Toby A Inkster. Concept inspired by nedit. Colours inspired by Mozilla's "View Source" function. Made using GNU nano 1.2.0. Powered by Perl.

EOF # popHTMLChar support function sub popHTMLChar { if (length($html) == 0) { return 'EOF'; } else { $c = substr($html, 0, 1); $html = substr($html, 1); return $c; } } # startClass support function sub startClass { $class = shift @_; print ''; push @classStack, $class; } # endClass support function sub endClass { print ''; pop @classStack; }