Skip to content

Commit

Permalink
Merge pull request #5 from Songmu/feature/utf8
Browse files Browse the repository at this point in the history
care utf8 flags
  • Loading branch information
sekimura committed Jul 9, 2013
2 parents ef29f65 + 540945b commit 2444f55
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Discount.xs
Expand Up @@ -37,10 +37,12 @@ BOOT:
newCONSTSUB(stash, "MKD_EXTRA_FOOTNOTE", newSViv(MKD_EXTRA_FOOTNOTE));

SV *
TextMarkdown__markdown(text, flags)
char *text;
TextMarkdown__markdown(sv_str, flags)
SV *sv_str
int flags;
PREINIT:
bool is_utf8 = SvUTF8(sv_str);
char *text = SvPV_nolen(sv_str);
SV* r = &PL_sv_undef;
char *html = NULL;
int szhtml;
Expand All @@ -62,6 +64,9 @@ TextMarkdown__markdown(text, flags)

r = newSVpvn(html, szhtml);
sv_catpv(r, "\n");
if (is_utf8) {
sv_utf8_decode(r);
}

mkd_cleanup(doc);
RETVAL = r;
Expand Down
20 changes: 20 additions & 0 deletions t/12.utf8.t
@@ -0,0 +1,20 @@
use strict;
use warnings;
use utf8;
use Test::More tests => 4;
use Text::Markdown::Discount;

{
my $perl_string = '# あ';
my $html = Text::Markdown::Discount::markdown($perl_string);
like $html, qr!<h1>あ</h1>!;
ok utf8::is_utf8($html);
}

{
no utf8;
my $byte = '# あ';
my $html = Text::Markdown::Discount::markdown($byte);
like $html, qr!<h1>あ</h1>!;
ok !utf8::is_utf8($html);
}

0 comments on commit 2444f55

Please sign in to comment.