display | more...

E2 Source Code Formatter

This script will reformat your entire node containing source code as long as you've used <pre></pre> and/or <code></code> pairs. This script takes a text file containing an entire node as its input, HTML and all. It won't work if you nest <pre></pre> or <code></code> pairs. It also doesn't handle <code> inside <pre> or vice versa, but unless you're noding about <pre> or <code> none of those should ever happen.

Usage example: ./source.prl node.e2 > node.e2.out

#!/usr/bin/perl
use strict;

my @open  = qw(<pre> <code>);
my @close = qw(</pre> </code>);

open(IN, $ARGV[0]);
my @node = <IN>;
close(IN);

my $node = join('__JOIN__STRING__', @node);
for my $i (0..1) {
    $node =~ s/($open[$i])/__PADDING__STRING__\1/g;
    @node =  split($open[$i], $node);

    for my $j (0..$#node) {
        if($j == 0) {
            push(@node, shift(@node));
        } else {
            my ($left, $right) = split($close[$i], shift(@node));
            $left =~ s/&/&amp;/g;
            $left =~ s/</&lt;/g;
            $left =~ s/>/&gt;/g;
            $left =~ s/\[/&#91;/g;
            $left =~ s/\]/&#93;/g;
            $left =~ s/\t/    /g;
            push(@node, $left . $close[$i] . $right);
        }
    }

    $node =  join($open[$i], @node);
    $node =~ s/__PADDING__STRING__//g;
}

@node = split('__JOIN__STRING__', $node);
print foreach (@node);


E2 Offline Node Preview

For those of us without QBASIC (I don't know when Microsoft quit distibuting it, but my installation of Windows XP Professional doesn't have it), here is a Windows Scripting Host/Perl offline node previewer. If you're looking for a Windows-friendly version of Perl, Active Perl1 is free, and it works well for me. This script currently uses a table width of 600, but that's easy to change (even if you don't know Perl). Just change the 600 in <table width="600"...> to whatever you'd prefer, and you're good to go. If you'd prefer to use a browser other than Internet Explorer (which I preview nodes in so it doesn't interfere with browsing with Mozilla Firefox), it's a one line change in the second to last line. Just replace iexplore with your favorite browser's executable.

Usage example: cscript node_preview.wsf node.txt

<Job ID="Offline_Node_Preview">
<script language=PerlScript>
# File name: node_preview.wsf
# Usage: cscript node_preview.wsf <file>

open(IN,$WScript->Arguments(0)) or die "Couldn't open input\n";
open(OUT,'>C:\\tempNode.html') or die "Couldn't open output\n";

print OUT<<'HEADER';
<html>
<head>
<style type="text/css">
body, p, td, li {font: normal normal normal 10pt Arial;}
a {color: #003366;}
</style>
<title>Offline Node Preview</title>
</head>
<body>
<table width="600" border="1" cellpadding="5">
<tr>
<td>
HEADER

@node = <IN>;
$node = join('__JOIN__STRING__', @node);
@node = split(/\[/, $node);
for $i (0..$#node) {
    unless($i == 0) {
        ($link, $rest) = split(/\]/, $node[$i]);
        $link =~ /(.+)/ unless($link =~ /(.+)\|(.+)/);
        $link  = '<a href="http://www.everything2.org/?node=';
        $link .= $1;
        $link .= '">';
        $link .= $1 unless(($2 ne '') and ($link .= $2));
        $link .= '</a>';
        $node[$i] = $link . $rest;
    }
}
$node = join('', @node);
@node = split('__JOIN__STRING__', $node);
print OUT foreach (@node);

print OUT<<'FOOTER';
</td>
</tr>
</table>
</body>
</html>
FOOTER

close(OUT);
close(IN);

$WshShell = $WScript->CreateObject('WScript.Shell');
$WshShell->Run('iexplore C:\\tempNode.html', 1, true);
system('del C:\\tempNode.html');
</script>
</Job>

1 - Active Perl is available for download at http://www.activestate.com/Products/ActivePerl/