From bd0925f3671882d03d5f2d9006b29656257f0d6c Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Sun, 12 Jun 2016 22:06:10 +0200 Subject: Switch to PHP based markdown renderer (parsedown) Signed-off-by: Florian Pritz --- .gitmodules | 3 + README.md | 3 - application/controllers/file.php | 10 +-- application/third_party/parsedown | 1 + docker/Dockerfile | 2 +- install.php | 15 ---- scripts/Markdown.pl | 147 -------------------------------------- 7 files changed, 11 insertions(+), 170 deletions(-) create mode 160000 application/third_party/parsedown delete mode 100755 scripts/Markdown.pl diff --git a/.gitmodules b/.gitmodules index 8e18180fc..e9b88c03c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "application/third_party/QrCode"] path = application/third_party/QrCode url = https://github.com/endroid/QrCode.git +[submodule "application/third_party/parsedown"] + path = application/third_party/parsedown + url = https://github.com/erusev/parsedown.git diff --git a/README.md b/README.md index 289ead211..32674564f 100644 --- a/README.md +++ b/README.md @@ -40,9 +40,6 @@ not need to register to be allowed to post. * phar for tarball creation * mysql, mysqli, pgsql, pdo_mysql (any of those) for database access -* perl with the following CPAN Modules - * Text::Markdown for markdown rendering - * [pygmentize](http://pygments.org/) for code highlighting * [ansi2html](http://pypi.python.org/pypi/ansi2html) for shell output rendering (ANSI color codes) * [imagemagick](http://www.imagemagick.org/) for additional thumbnail generation diff --git a/application/controllers/file.php b/application/controllers/file.php index 7c49988bf..79d5395ae 100644 --- a/application/controllers/file.php +++ b/application/controllers/file.php @@ -320,14 +320,16 @@ class File extends MY_Controller { echo '
'."\n"; echo '
'."\n"; echo '
'."\n"; - // TODO: use exec safe and catch exception - $r = (new \libraries\ProcRunner(array(FCPATH.'scripts/Markdown.pl', $file)))->forbid_stderr()->exec(); - echo $r['stdout']; + + require_once(APPPATH."/third_party/parsedown/Parsedown.php"); + $parsedown = new Parsedown(); + echo $parsedown->text(file_get_contents($file)); + echo '
'; return array( "output" => ob_get_clean(), - "return_value" => $r["return_code"], + "return_value" => 0, ); } else { return get_instance()->_colorify($file, $lexer, $is_multipaste ? $filedata["id"] : false); diff --git a/application/third_party/parsedown b/application/third_party/parsedown new file mode 160000 index 000000000..490a8f35a --- /dev/null +++ b/application/third_party/parsedown @@ -0,0 +1 @@ +Subproject commit 490a8f35a4163f59230f53c34f1fbb22a864c01e diff --git a/docker/Dockerfile b/docker/Dockerfile index 70e82f9e2..8dd4e4e09 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -4,7 +4,7 @@ MAINTAINER Sebastian Rakel ENV DEBIAN_FRONTEND noninteractive RUN apt-get update -y && \ - apt-get install -y php5 php5-mysql php5-gd php5-imagick libtext-markdown-perl expect \ + apt-get install -y php5 php5-mysql php5-gd php5-imagick expect \ python-pygments imagemagick git python-pip realpath curl apt-transport-https RUN echo 'deb https://deb.nodesource.com/node_4.x trusty main' > /etc/apt/sources.list.d/nodesource.list diff --git a/install.php b/install.php index 1deb8cc2a..5287fbebb 100644 --- a/install.php +++ b/install.php @@ -29,21 +29,6 @@ $buf = ob_get_contents(); ob_end_clean(); $buf == "works" || $errors .= "passthru() failed\n"; -// test perl deps -$perldeps = array( - "Text::Markdown" -); -foreach ($perldeps as $dep) { - ob_start(); - passthru("perl 2>&1 -M'$dep' -e1"); - $buf = ob_get_contents(); - ob_end_clean(); - if ($buf != "") { - $errors .= " - failed to find perl module: $dep.\n"; - $errors .= $buf; - } -} - // test pygmentize ob_start(); passthru("pygmentize -V 2>&1", $buf); diff --git a/scripts/Markdown.pl b/scripts/Markdown.pl deleted file mode 100755 index 169b15fed..000000000 --- a/scripts/Markdown.pl +++ /dev/null @@ -1,147 +0,0 @@ -#!/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 -

This is a test.

- -

Absolutely nothing to see here. Just a test!

- -
    -
  • test
  • -
  • Yup, test.
  • -
- -If no file is specified, it will expect its input from STDIN: - - $ echo "A **simple** test" | markdown -

A simple test

- -=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
tag) to state they will not -be closed, by closing with C>. HTML 4-style will plainly output -the tag as it comes: - - $ echo '---' | markdown -
- $ echo '---' | markdown --html4tags -
- -=item help - -Shows this documentation - -=back - -=head1 AUTHOR - -Copyright 2004 John Gruber - -Copyright 2008 Tomas Doran - -The manpage was written by Gunnar Wolf for its use -in Debian systems, but can be freely used elsewhere. - -For full licensing information, please refer to -L's full documentation. - -=head1 SEE ALSO - -L, L - -=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(); -- cgit v1.2.3-24-g4f1b