Using markdown from within perl script

Dhruba Bandopadhyay dhrubab at gmail.com
Fri Aug 20 14:51:36 EDT 2004


On Fri, 20 Aug 2004 14:20:22 -0400, John Gruber <gruber at fedora.net> wrote:
> Dhruba Bandopadhyay <dhrubab at gmail.com> wrote on 08/20/04 at 1:36pm:
> 
> > My question is can markdown be used from within a perl/cgi script?
> >
> > I'm trying to avoid using backticks and command line if I can and do
> > the conversion within a script.
> 
> As it stands now, you'd need to copy and paste it into your own
> script, or turn it into a Markdown.pm module by hand.

Hello,

I renamed Markdown.pl to markdown.cgi and added some cgi code of own
at the start that took some structured text from a web form and gave
back out xhtml by calling Markdown($text).  Essentially, I was
initially trying to reproduce a very simple version of the dingus that
you have.  This page can be viewed at:

http://dhruba.codewordt.co.uk/project/markdown.cgi

Then I tried some example structured text.  Some examples worked but
others didn't.  Is there something special I need to do or forgot to
do?

My personal code that was added to the file at the top is given below.
 Any help would be much appreciated.

With regards.
Dhruba.

<code>
use CGI qw/:standard/;
use CGI::Pretty;
use CGI::Safe qw/ :standard taint /;

my $section = "Markdown";
my $cgi = new CGI;
my $text = param('text');
my $html;

if ($text) { $html = &Markdown($text); }

print

    header,
    start_html($section),
    h1($section),
    p("Enter Structured Text."),
    start_form,
    p(
    textarea(
        -name => 'text',
        -rows => 8,
        -columns => 50
    )),
    p(
    submit,
    reset),
    end_form,
    p("Watch the HTML appear below."),
    p(
    textarea(
        -name => 'html',
        -default => $html,
        -rows => 8,
        -columns => 50,
        -readonly => 'readonly',
    )),
    p("Watch the HTML being interpreted below."),
    p($html),
    end_html;
</code>


More information about the Markdown-discuss mailing list