Category: | HTML Utility |
Author/Contact Info | patgas |
Description: | This script grabs an HTML file, and converts it into a VBScript Response.Write command for use in ASP pages. Allows custom levels of indenting, and does proper double-quote escaping. Simple, really, but I find myself using it all the time. |
# HTML2ASP # By patgas # April 30, 2001 # # Takes an HTML file, and converts it into a # Response.Write command for an ASP page. # # Usage: # perl html2asp.pl [input_file] [output_file] (command_indent) (HTM +L_indent) # # input_file and output_file are required. # command_indent inserts whitespace before the actual Response.Writ +e command. # HTML_indent inserts whitespace in the string argument to Response +.Write. my ($infile, $outfile, $indentCommand, $indentHTML) = @ARGV; die "Missing required argument: $!" if (!$infile || !$outfile); $indentCommand ||= "2"; $indentHTML ||= "0"; open(IN, $infile) or die "Can't open input file: $!"; open(OUT, ">$outfile") or die "Can't open output file: $!"; print "Starting... "; select(OUT); print "<%\n\n"; $indentCommand = ' ' x $indentCommand; $indentHTML = ' ' x $indentHTML; my @lines = <IN>; my $writeCommand = 1; while (@lines) { chomp(my $line = shift @lines); print $indentCommand; if ($writeCommand == 1) { print "Response.Write("; $writeCommand = 0; } else { print " "; } print $indentHTML; if ( $line ) { $line =~ s/\"/\"\"/g; print "\"$line\" & "; } print "vbNewLine"; if (@lines) { print " & _"; } else { print ")\n"; } print "\n"; } print "%>"; print STDOUT "Done."; close IN or die "Can't close input file: $!"; close OUT or die "Can't close output file: $!"; |
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: HTML To ASP Converter
by $code or die (Deacon) on Apr 30, 2001 at 23:54 UTC | |
by patgas (Friar) on May 01, 2001 at 00:54 UTC | |
by $code or die (Deacon) on May 01, 2001 at 01:35 UTC | |
by dze27 (Pilgrim) on May 01, 2001 at 19:20 UTC | |
by patgas (Friar) on May 01, 2001 at 02:00 UTC | |
Re: HTML To ASP Converter
by $code or die (Deacon) on Apr 30, 2001 at 23:25 UTC | |
by Anonymous Monk on Jan 09, 2005 at 09:46 UTC |
Back to
Code Catacombs