<?xml version="1.0" encoding="windows-1252"?>
<node id="76679" title="HTML To ASP Converter" created="2001-04-30 17:48:35" updated="2005-08-15 10:36:19">
<type id="1748">
sourcecode</type>
<author id="66740">
patgas</author>
<data>
<field name="doctext">
&lt;code&gt;
# 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) (HTML_indent)
#    
#    input_file and output_file are required.
#    command_indent inserts whitespace before the actual Response.Write 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, "&gt;$outfile") or die "Can't open output file: $!";

print "Starting... ";

select(OUT);

print "&lt;%\n\n";

$indentCommand = ' ' x $indentCommand;
$indentHTML = ' ' x $indentHTML;

my @lines = &lt;IN&gt;;
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\" &amp; ";
    }

    print "vbNewLine";

    if (@lines) {
        print " &amp; _";
    }
    else {
        print ")\n";
    }

    print "\n";
}

print "%&gt;";
print STDOUT "Done.";

close IN or die "Can't close input file: $!";
close OUT or die "Can't close output file: $!";
&lt;/code&gt;</field>
<field name="codedescription">
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.</field>
<field name="codecategory">
HTML Utility</field>
<field name="codeauthor">
[patgas]</field>
</data>
</node>
