diff options
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/Markdown.pl | 147 | ||||
-rwxr-xr-x | scripts/ansi2html | 20 | ||||
-rwxr-xr-x | scripts/mimetype | 38 |
3 files changed, 205 insertions, 0 deletions
diff --git a/scripts/Markdown.pl b/scripts/Markdown.pl new file mode 100755 index 000000000..169b15fed --- /dev/null +++ b/scripts/Markdown.pl @@ -0,0 +1,147 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Text::Markdown qw(markdown); + +=head1 NAME + +Markdown.pl - Convert Markdown syntax to (X)HTML + +=head1 DESCRIPTION + +This program is distributed as part of Perl's Text::Markdown module, +illustrating sample usage. + +Markdown can be invoked on any file containing Markdown-syntax, and +will produce the corresponding (X)HTML on STDOUT: + + $ cat file.txt + This is a *test*. + + Absolutely _nothing_ to see here. _Just a **test**_! + + * test + * Yup, test. + $ Markdown.pl file.txt + <p>This is a <em>test</em>.</p> + + <p>Absolutely <em>nothing</em> to see here. <em>Just a <strong>test</strong></em>!</p> + + <ul> + <li>test</li> + <li>Yup, test.</li> + </ul> + +If no file is specified, it will expect its input from STDIN: + + $ echo "A **simple** test" | markdown + <p>A <strong>simple</strong> test</p> + +=head1 OPTIONS + +=over + +=item version + +Shows the full information for this version + +=item shortversion + +Shows only the version number + +=item html4tags + +Produce HTML 4-style tags instead of XHTML - XHTML requires elements +that do not wrap a block (i.e. the C<hr> tag) to state they will not +be closed, by closing with C</E<gt>>. HTML 4-style will plainly output +the tag as it comes: + + $ echo '---' | markdown + <hr /> + $ echo '---' | markdown --html4tags + <hr> + +=item help + +Shows this documentation + +=back + +=head1 AUTHOR + +Copyright 2004 John Gruber + +Copyright 2008 Tomas Doran + +The manpage was written by Gunnar Wolf <gwolf@debian.org> for its use +in Debian systems, but can be freely used elsewhere. + +For full licensing information, please refer to +L<Text::Markdown.pm>'s full documentation. + +=head1 SEE ALSO + +L<Text::Markdown>, L<http://daringfireball.net/projects/markdown/> + +=cut + +#### Check for command-line switches: ################# +my %cli_opts; +use Getopt::Long; +Getopt::Long::Configure('pass_through'); +GetOptions(\%cli_opts, + 'version', + 'shortversion', + 'html4tags', + 'help', +); +if ($cli_opts{'version'}) { # Version info + print "\nThis is Markdown, version $Text::Markdown::VERSION.\n"; + print "Copyright 2004 John Gruber\n"; + print "Copyright 2008 Tomas Doran\n"; + print "Parts contributed by several other people."; + print "http://daringfireball.net/projects/markdown/\n\n"; + exit 0; +} +if ($cli_opts{'shortversion'}) { # Just the version number string. + print $Text::Markdown::VERSION; + exit 0; +} +if ($cli_opts{'help'}) { + for my $dir (split m/:/, $ENV{PATH}) { + my $cmd = "$dir/perldoc"; + exec($cmd, $0) if (-f $cmd and -x $cmd); + } + die "perldoc could not be found in your path - Cannot show help, sorry\n"; +} +my $m; +if ($cli_opts{'html4tags'}) { # Use HTML tag style instead of XHTML + $m = Text::Markdown->new(empty_element_suffix => '>'); +} +else { + $m = Text::Markdown->new; +} + +sub main { + my (@fns) = @_; + + my $f; + if (scalar @fns) { + foreach my $fn (@fns) { + die("Cannot find file $fn") unless (-r $fn); + + my $fh; + open($fh, '<', $fn) or die; + $f = join('', <$fh>); + close($fh) or die; + } + } + else { # STDIN + local $/; # Slurp the whole file + $f = <>; + } + + return $m->markdown($f); +} + +print main(@ARGV) unless caller(); diff --git a/scripts/ansi2html b/scripts/ansi2html new file mode 100755 index 000000000..e33e24630 --- /dev/null +++ b/scripts/ansi2html @@ -0,0 +1,20 @@ +#!/usr/bin/perl +use strict; +use HTML::FromANSI (); + +my $h = HTML::FromANSI->new( + fill_cols => 0, + font_face => "", + style => "", + tt => 0 +); + +open IN, "<", $ARGV[0] or die "cannot read $ARGV[0]: $!"; + +$h->add_text(<IN>); +my $html = $h->html; +$html =~ s/background: black; //g; +$html =~ s/color: white; /color: black /g; +$html =~ s/<br>/\n/g; + +print $html; diff --git a/scripts/mimetype b/scripts/mimetype new file mode 100755 index 000000000..3c0c17e9b --- /dev/null +++ b/scripts/mimetype @@ -0,0 +1,38 @@ +#!/usr/bin/perl +use warnings; +use strict; +use File::MimeInfo::Magic qw(mimetype globs); + +exit 1 unless @ARGV == 2; + +my $filename = $ARGV[0]; +my $file = $ARGV[1]; +my $type = ""; +my $file_type = ""; + +exit 1 unless -f $file; + +$type = globs($filename); + +# globbing takes priority over all other +if (!$type) { + $type = mimetype($file); + if ($type eq "application/octet-stream") { + # application/octet-stream normally means the detection failed + # use the output of file in this case + $file_type = `file -b --mime-type $file`; + chomp $file_type; + $type = $file_type; + if ($type eq "text/plain") { + # detect ascii with color codes + $file_type = `file -b $file`; + chomp $file_type; + if ($file_type eq "ASCII text, with escape sequences") { + $type = "text/plain-ascii"; + } + } + } +} + +print "$type\n"; + |