Compare commits

...

2 Commits

Author SHA1 Message Date
  Masayoshi Sekimura e80b6debba added discount.patch and call mkd_shlib_destructor if with_html5 option is disabled 11 years ago
  Masayoshi Sekimura 2fd73a236a API desigin review for with_html5 option 11 years ago
5 changed files with 84 additions and 8 deletions
Split View
  1. +8
    -1
      Discount.xs
  2. +1
    -1
      Makefile.PL
  3. +27
    -0
      discount.patch
  4. +13
    -6
      lib/Text/Markdown/Discount.pm
  5. +35
    -0
      t/13.html5.t

+ 8
- 1
Discount.xs View File

@ -37,9 +37,10 @@ BOOT:
newCONSTSUB(stash, "MKD_EXTRA_FOOTNOTE", newSViv(MKD_EXTRA_FOOTNOTE));
SV *
TextMarkdown__markdown(sv_str, flags)
TextMarkdown__markdown(sv_str, flags, with_html5)
SV *sv_str
int flags;
int with_html5;
PREINIT:
bool is_utf8 = SvUTF8(sv_str) != 0; // SvUTF8 doesn't typecast consistently to bool across various archs
char *text = SvPV_nolen(sv_str);
@ -48,6 +49,12 @@ TextMarkdown__markdown(sv_str, flags)
int szhtml;
MMIOT *doc;
CODE:
if ( with_html5 ) {
mkd_with_html5_tags(1); // force load
} else {
mkd_shlib_destructor();
}
if ( (doc = mkd_string(text, strlen(text), flags)) == 0 ) {
croak("failed at mkd_string");
}


+ 1
- 1
Makefile.PL View File

@ -61,7 +61,7 @@ sub MY::postamble {
return sprintf('
$(MYEXTLIB):
%s
', qq{( cd $extdir; CC='cc -fPIC' sh configure.sh; make )\n});
', qq{( patch -p0 < discount.patch; cd $extdir; CC='cc -fPIC' sh configure.sh; make )\n});
}
WriteMakefile(


+ 27
- 0
discount.patch View File

@ -0,0 +1,27 @@
--- discount/html5.c.orig 2013-08-05 12:24:40.000000000 -0700
+++ discount/html5.c 2013-08-05 12:25:02.000000000 -0700
@@ -3,11 +3,11 @@
#include "tags.h"
void
-mkd_with_html5_tags()
+mkd_with_html5_tags(int force)
{
static int populated = 0;
- if ( populated ) return;
+ if ( populated && !force ) return;
populated = 1;
mkd_define_tag("ASIDE", 0);
--- discount/tags.c.orig 2013-08-05 12:24:40.000000000 -0700
+++ discount/tags.c 2013-08-05 12:25:02.000000000 -0700
@@ -26,6 +26,8 @@
* either the standard or extra tag tables.
*/
if ( !(p = mkd_search_tags(id, strlen(id))) ) {
+ if ( S(extratags) == 0 )
+ CREATE(extratags);
p = &EXPAND(extratags);
p->id = id;
p->size = strlen(id);

+ 13
- 6
lib/Text/Markdown/Discount.pm View File

@ -35,23 +35,30 @@ sub new {
}
sub markdown {
my ($self, $text, $flags) = @_;
my ($self, $text, $flags, $opts) = @_;
if (not defined $flags) {
$flags = MKD_NOHEADER()|MKD_NOPANTS();
}
if (not defined $opts or ref($opts) ne 'HASH') {
$opts = {};
}
my $with_html5 = $opts->{with_html5} ? 1 : 0;
# 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, $flags);
return $ob->markdown($self, $text, $flags, $with_html5);
}
else {
croak('Calling ' . $self . '->markdown (as a class method) is not supported.');
}
}
if (not defined $flags) {
$flags = MKD_NOHEADER()|MKD_NOPANTS();
}
return _markdown($text, $flags);
return _markdown($text, $flags, $with_html5);
}


+ 35
- 0
t/13.html5.t View File

@ -0,0 +1,35 @@
use strict;
use warnings;
use utf8;
use Test::More tests => 6;
use Text::Markdown::Discount;
is(
strip(Text::Markdown::Discount::markdown("<section>foo</section>", undef, {with_html5 => 0})),
"<p><section>foo</section></p>");
is(
strip(Text::Markdown::Discount::markdown("<section>foo</section>", undef, {with_html5 => 1})),
"<section>foo</section>");
is(
strip(Text::Markdown::Discount::markdown("<section>foo</section>", undef, {with_html5 => 0})),
"<p><section>foo</section></p>");
is(
strip(Text::Markdown::Discount->new()->markdown("<section>foo</section>", undef, {with_html5 => 0})),
"<p><section>foo</section></p>");
is(
strip(Text::Markdown::Discount->new()->markdown("<section>foo</section>", undef, {with_html5 => 1})),
"<section>foo</section>");
is(
strip(Text::Markdown::Discount->new()->markdown("<section>foo</section>", undef, {with_html5 => 0})),
"<p><section>foo</section></p>");
sub strip {
my $str = shift;
$str =~ s/\s*//g;
return $str;
}

Loading…
Cancel
Save