Compare commits

...

9 Commits

12 changed files with 121 additions and 75 deletions
Unified View
  1. +6
    -0
      .gitignore
  2. +3
    -0
      .gitmodules
  3. +15
    -9
      Makefile.PL
  4. +28
    -0
      PegMarkdown.xs
  5. +0
    -45
      XS.xs
  6. +29
    -0
      ext/Makefile.PL
  7. +26
    -13
      lib/Text/Markdown/PegMarkdown.pm
  8. +1
    -0
      peg-markdown
  9. +1
    -1
      t/Text-Markdown-PegMarkdown.t
  10. +1
    -1
      xt/MarkdownTest_1.0.3.t
  11. +3
    -3
      xt/MarkdownXS.pl
  12. +8
    -3
      xt/test.pl

+ 6
- 0
.gitignore View File

@ -5,3 +5,9 @@ XS.bs
XS.c XS.c
XS.o XS.o
pm_to_blib pm_to_blib
*.swp
ext/pm_to_blib
ext/*.o
ext/*.so
ext/Makefile
ext/Makefile.old

+ 3
- 0
.gitmodules View File

@ -0,0 +1,3 @@
[submodule "peg-markdown"]
path = peg-markdown
url = git://github.com/jgm/peg-markdown.git

+ 15
- 9
Makefile.PL View File

@ -2,16 +2,22 @@ use 5.008000;
use ExtUtils::MakeMaker; use ExtUtils::MakeMaker;
# See lib/ExtUtils/MakeMaker.pm for details of how to influence # See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written. # the contents of the Makefile that is written.
sub MY::postamble {
return <<'MAKE_FRAG';
$(MYEXTLIB):
(cd ext; make libpeg_markdown.$(DLEXT))
MAKE_FRAG
}
WriteMakefile( WriteMakefile(
NAME => 'Text::Markdown::XS',
VERSION_FROM => 'lib/Text/Markdown/XS.pm', # finds $VERSION
NAME => 'Text::Markdown::PegMarkdown',
VERSION_FROM => 'lib/Text/Markdown/PegMarkdown.pm', # finds $VERSION
PREREQ_PM => {}, # e.g., Module::Name => 1.1 PREREQ_PM => {}, # e.g., Module::Name => 1.1
($] >= 5.005 ? ## Add these new keywords supported since 5.005 ($] >= 5.005 ? ## Add these new keywords supported since 5.005
(ABSTRACT_FROM => 'lib/Text/Markdown/XS.pm', # retrieve abstract from module
AUTHOR => 'Masayoshi Sekimura <sekimura@>') : ()),
LIBS => ['-L/usr/local/lib -lmarkdown'], # e.g., '-lm'
DEFINE => '', # e.g., '-DHAVE_SOMETHING'
INC => '-I. -I/usr/local/include', # e.g., '-I. -I/usr/include/other'
# Un-comment this if you add C files to link with later:
# OBJECT => '$(O_FILES)', # link all the C files too
(ABSTRACT_FROM => 'lib/Text/Markdown/PegMarkdown.pm', # retrieve abstract from module
AUTHOR => 'Masayoshi Sekimura <sekimura@cpan.org>') : ()),
LIBS => [`pkg-config --libs glib-2.0`],
INC => '`pkg-config --cflags glib-2.0` -Ipeg-markdown',
MYEXTLIB => 'ext/libpeg_markdown.$(DLEXT)',
); );

+ 28
- 0
PegMarkdown.xs View File

@ -0,0 +1,28 @@
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "ppport.h"
#include <markdown_lib.h>
MODULE = Text::Markdown::PegMarkdown PACKAGE = Text::Markdown::PegMarkdown PREFIX = TextMarkdown_
PROTOTYPES: DISABLE
SV *
TextMarkdown__markdown(text)
char *text;
PREINIT:
SV* r = &PL_sv_undef;
char *out = NULL;
int extensions = 0;
int output_format = HTML_FORMAT;
CODE:
out = markdown_to_string(text, extensions, output_format);
r = newSVpvn(out, strlen(out));
Safefree(out);
RETVAL = r;
OUTPUT:
RETVAL

+ 0
- 45
XS.xs View File

@ -1,45 +0,0 @@
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "ppport.h"
#include <string.h>
#include <mkdio.h>
MODULE = Text::Markdown::XS PACKAGE = Text::Markdown::XS PREFIX = TextMarkdown_
PROTOTYPES: DISABLE
SV *
TextMarkdown_markdown(text)
char *text;
PREINIT:
SV* r = &PL_sv_undef;
int flags = MKD_NOHEADER|MKD_NOPANTS;
char *html = NULL;
int szhtml;
MMIOT *doc;
CODE:
if ( (doc = mkd_string(text, strlen(text), flags)) == 0 ) {
croak("failed at mkd_string");
}
if ( !mkd_compile(doc, flags) ) {
Safefree(doc);
croak("failed at mkd_compile");
}
if ( (szhtml = mkd_document(doc, &html)) == EOF ) {;
Safefree(doc);
croak("failed at mkd_document");
}
r = newSVpvn(html, szhtml);
sv_catpv(r, "\n");
Safefree(html);
Safefree(doc);
RETVAL = r;
OUTPUT:
RETVAL

+ 29
- 0
ext/Makefile.PL View File

@ -0,0 +1,29 @@
use 5.008000;
use ExtUtils::MakeMaker;
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
sub MY::postamble {
return <<'MAKE_FRAG';
MARKDOWN_OBJS=markdown_lib.o markdown_output.o markdown_parser.o
$(MARKDOWN_OBJS):
(cd ../peg-markdown; make)
@ for i in $@; do \
$(CP) ../peg-markdown/$$i .;\
done
libpeg_markdown.$(DLEXT): $(MARKDOWN_OBJS)
$(LD) $(LDDLFLAGS) -o libpeg_markdown.$(DLEXT) $(MARKDOWN_OBJS)
MAKE_FRAG
}
WriteMakefile(
NAME => 'libpeg_markdown',
PREREQ_PM => {}, # e.g., Module::Name => 1.1
LIBS => `pkg-config --libs glib-2.0`,
DEFINE => '', # e.g., '-DHAVE_SOMETHING'
INC => `pkg-config --cflags glib-2.0`,
# OBJECT => '$(O_FILES)', # link all the C files too
clean => { FILES => '*.so *.o'},
);

lib/Text/Markdown/XS.pm → lib/Text/Markdown/PegMarkdown.pm View File

@ -1,4 +1,4 @@
package Text::Markdown::XS;
package Text::Markdown::PegMarkdown;
use 5.008000; use 5.008000;
use strict; use strict;
@ -8,13 +8,6 @@ require Exporter;
our @ISA = qw(Exporter); our @ISA = qw(Exporter);
# Items to export into callers namespace by default. Note: do not export
# names by default without a very good reason. Use EXPORT_OK instead.
# Do not simply export all your public functions/methods/constants.
# This allows declaration use Text::Markdown::XS ':all';
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
# will save memory.
our %EXPORT_TAGS = ( 'all' => [ qw( our %EXPORT_TAGS = ( 'all' => [ qw(
markdown markdown
) ] ); ) ] );
@ -28,9 +21,29 @@ our @EXPORT = qw(
our $VERSION = '0.01'; our $VERSION = '0.01';
require XSLoader; require XSLoader;
XSLoader::load('Text::Markdown::XS', $VERSION);
XSLoader::load('Text::Markdown::PegMarkdown', $VERSION);
sub new {
return bless {}, 'Text::Markdown::PegMarkdown';
}
sub markdown {
my ($self, $text) = @_;
# Detect functional mode, and create an instance for this run..
unless (ref $self) {
if ( $self ne __PACKAGE__ ) {
my $ob = __PACKAGE__->new();
# $self is text, $text is options
return $ob->markdown($self, $text);
}
else {
croak('Calling ' . $self . '->markdown (as a class method) is not supported.');
}
}
return _markdown($text);
}
# Preloaded methods go here.
1; 1;
__END__ __END__
@ -38,16 +51,16 @@ __END__
=head1 NAME =head1 NAME
Text::Markdown::XS - Perl extension for blah blah blah
Text::Markdown::PegMarkdown - Perl extension for blah blah blah
=head1 SYNOPSIS =head1 SYNOPSIS
use Text::Markdown::XS;
use Text::Markdown::PegMarkdown;
blah blah blah blah blah blah
=head1 DESCRIPTION =head1 DESCRIPTION
Stub documentation for Text::Markdown::XS, created by h2xs. It looks like the
Stub documentation for Text::Markdown::PegMarkdown, created by h2xs. It looks like the
author of the extension was negligent enough to leave the stub author of the extension was negligent enough to leave the stub
unedited. unedited.

+ 1
- 0
peg-markdown

@ -0,0 +1 @@
Subproject commit 1c0c0782ef0a580bc5516cc24a64af76c92b9014

t/Text-Markdown-XS.t → t/Text-Markdown-PegMarkdown.t View File

@ -6,7 +6,7 @@
# change 'tests => 1' to 'tests => last_test_to_print'; # change 'tests => 1' to 'tests => last_test_to_print';
use Test::More tests => 1; use Test::More tests => 1;
BEGIN { use_ok('Text::Markdown::XS') };
BEGIN { use_ok('Text::Markdown::PegMarkdown') };
######################### #########################

+ 1
- 1
xt/MarkdownTest_1.0.3.t View File

@ -6,7 +6,7 @@
# change 'tests => 1' to 'tests => last_test_to_print'; # change 'tests => 1' to 'tests => last_test_to_print';
use Test::More qw(no_plan); use Test::More qw(no_plan);
BEGIN { use_ok('Text::Markdown::XS') };
BEGIN { use_ok('Text::Markdown::PegMarkdown') };
######################### #########################


+ 3
- 3
xt/MarkdownXS.pl View File

@ -3,7 +3,7 @@ use strict;
use warnings; use warnings;
use ExtUtils::testlib; use ExtUtils::testlib;
use Text::Markdown::XS qw(markdown);
use Text::Markdown::PegMarkdown qw(markdown);
=head1 NAME =head1 NAME
@ -118,10 +118,10 @@ if ($cli_opts{'help'}) {
} }
my $m; my $m;
if ($cli_opts{'html4tags'}) { # Use HTML tag style instead of XHTML if ($cli_opts{'html4tags'}) { # Use HTML tag style instead of XHTML
$m = Text::Markdown::XS->new(empty_element_suffix => '>');
$m = Text::Markdown::PegMarkdown->new(empty_element_suffix => '>');
} }
else { else {
$m = Text::Markdown::XS->new;
$m = Text::Markdown::PegMarkdown->new;
} }
sub main { sub main {


+ 8
- 3
xt/test.pl View File

@ -3,22 +3,27 @@
use ExtUtils::testlib; use ExtUtils::testlib;
use Text::Markdown 'markdown'; use Text::Markdown 'markdown';
use Text::Markdown::XS;
use Text::Markdown::PegMarkdown;
use Benchmark; use Benchmark;
use File::Slurp; use File::Slurp;
use Text::Diff; use Text::Diff;
my $text = read_file('xt/index.text'); my $text = read_file('xt/index.text');
my $a = Text::Markdown::XS::markdown($text);
my $a = Text::Markdown::PegMarkdown::markdown($text);
my $b = Text::Markdown::markdown($text); my $b = Text::Markdown::markdown($text);
$a =~ s{'}{'\\''}g; # escape ' chars for shell
$b =~ s{'}{'\\''}g;
$a = `echo '$a' | tidy --show-body-only 1 --quiet 1 --show-warnings 0`;
$b = `echo '$b' | tidy --show-body-only 1 --quiet 1 --show-warnings 0`;
unless ( $a eq $b ) { unless ( $a eq $b ) {
print diff \$a, \$b; print diff \$a, \$b;
#die "BOO"; #die "BOO";
} }
my $count = 1000; my $count = 1000;
timethese($count, { timethese($count, {
'B_Text::Markdown::XS' => sub { Text::Markdown::XS::markdown($text) },
'B_Text::Markdown::PegMarkdown' => sub { Text::Markdown::PegMarkdown::markdown($text) },
'A_Text::Markdown' => sub { Text::Markdown::markdown($text) }, 'A_Text::Markdown' => sub { Text::Markdown::markdown($text) },
}); });


Loading…
Cancel
Save