Storeroom of unused parts

(This is a mish-mash of stuff that didn't fit on other pages. Think of it as a storeroom.)

More detailed instructions

Set up your Perl environment

cd ~
mkdir -p bin/perllib/FrogUtils
# Set environment variable so that Perl can find the library files
export PERL5LIB=$HOME/bin/perllib

Defining PERL5LIB in Windows
Defining PERL5LIB in Windows

Sample code

With that out of the way, here is a sample Perl script that uses MarkdownW.pm and SmartyPantsW.pm

#!/usr/bin/perl

# Markdown.pl 1.01 converted to be a real package.
use FrogUtils::MarkdownW;
# SmartyPants.pl 1.51 converted to be a real package.
use FrogUtils::SmartyPantsW;

use strict; 

my $infile = "MarkdownTest.md";
my $outfile = "MarkdownTest.html";

if ( -f $InFile ) {
    open (FILE, $InFile);
    # Read the whole file into $Text
    my $Text = join('', <FILE>);
    close FILE;
    chomp $cfile;
} else { print "'$InFile' not found.\n"; exit -1; }

$Text = PreFilter($Text);
my $Body = Markdown($Text);
my $smartypants_attr = "1";  # See SmartyPants docs.
$Body = SmartyPants($Body, $smartypants_attr, undef); 
$Text = PostFilter($Text);

my $Head = AddHead();
my $Tail = AddTail();

open (OUT, ">$OutFile") || die "Cannot open $OutFile";
print OUT $Head;
print OUT $Body;
print OUT $Tail;
print OUT "\n";
close OUT;

# Is run before text has been through Markdown
# (So it formatted in 100% Markdown)
sub PreFilter {
    my $s = shift;

    # Your additional filtering code goes here.

    $return $;
}

# Is run after text has been through Markdown.
# (So it is now 100% HTML.)
sub PostFilter {
    my $s = shift;

    # Your additional filtering code goes here.
    
    # Converts '%b%' to '<b>'  to sidestep Markdown trickiness
    $s =~ s|%b%|<b>|sgi;  # Bold
    $s =~ s|%/b%|/<b>|sgi;
    $s =~ s|%i%|<i>|sgi;  # Italic
    $s =~ s|%/i%|/<i>|sgi;
    my $replacement = "<!-- ";
    $s =~ s|%#%|$replacement|sgi;     # Inline comment
    $replacement = " -->";
    $s =~ s|%/#%|$replacement|sgi;

    return $s;
}

sub AddHead {
    my $s = "<!DOCTYPE html>\n";    # AKA HTML5
    $s .= "<html><head>\n";
    $s .= "<title>Markdown and SmartyPants</title>\n";
    $s .= "<head>\n";
    $s .= "<body>\n";
    return $s;
}

sub AddTail {
    my $s = "</body></html>\n";
    return $s;
}