-
Notifications
You must be signed in to change notification settings - Fork 18
/
Discount.xs
79 lines (68 loc) · 2.7 KB
/
Discount.xs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "ppport.h"
#include <string.h>
#include <mkdio.h>
MODULE = Text::Markdown::Discount PACKAGE = Text::Markdown::Discount PREFIX = TextMarkdown_
PROTOTYPES: DISABLE
BOOT:
HV* stash = gv_stashpvn("Text::Markdown::Discount", strlen("Text::Markdown::Discount"), TRUE);
newCONSTSUB(stash, "MKD_NOLINKS", newSViv(MKD_NOLINKS));
newCONSTSUB(stash, "MKD_NOIMAGE", newSViv(MKD_NOIMAGE));
newCONSTSUB(stash, "MKD_NOPANTS", newSViv(MKD_NOPANTS));
newCONSTSUB(stash, "MKD_NOHTML", newSViv(MKD_NOHTML));
newCONSTSUB(stash, "MKD_STRICT", newSViv(MKD_STRICT));
newCONSTSUB(stash, "MKD_TAGTEXT", newSViv(MKD_TAGTEXT));
newCONSTSUB(stash, "MKD_NO_EXT", newSViv(MKD_NO_EXT));
newCONSTSUB(stash, "MKD_CDATA", newSViv(MKD_CDATA));
newCONSTSUB(stash, "MKD_NOSUPERSCRIPT", newSViv(MKD_NOSUPERSCRIPT));
newCONSTSUB(stash, "MKD_NORELAXED", newSViv(MKD_NORELAXED));
newCONSTSUB(stash, "MKD_NOTABLES", newSViv(MKD_NOTABLES));
newCONSTSUB(stash, "MKD_NOSTRIKETHROUGH", newSViv(MKD_NOSTRIKETHROUGH));
newCONSTSUB(stash, "MKD_TOC", newSViv(MKD_TOC));
newCONSTSUB(stash, "MKD_1_COMPAT", newSViv(MKD_1_COMPAT));
newCONSTSUB(stash, "MKD_AUTOLINK", newSViv(MKD_AUTOLINK));
newCONSTSUB(stash, "MKD_SAFELINK", newSViv(MKD_SAFELINK));
newCONSTSUB(stash, "MKD_NOHEADER", newSViv(MKD_NOHEADER));
newCONSTSUB(stash, "MKD_TABSTOP", newSViv(MKD_TABSTOP));
newCONSTSUB(stash, "MKD_NODIVQUOTE", newSViv(MKD_NODIVQUOTE));
newCONSTSUB(stash, "MKD_NOALPHALIST", newSViv(MKD_NOALPHALIST));
newCONSTSUB(stash, "MKD_NODLIST", newSViv(MKD_NODLIST));
newCONSTSUB(stash, "MKD_EXTRA_FOOTNOTE", newSViv(MKD_EXTRA_FOOTNOTE));
SV *
TextMarkdown__markdown(sv_str, flags)
SV *sv_str
int flags;
PREINIT:
bool is_utf8 = SvUTF8(sv_str) != 0; // SvUTF8 doesn't typecast consistently to bool across various archs
char *text = SvPV_nolen(sv_str);
SV* r = &PL_sv_undef;
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) ) {
mkd_cleanup(doc);
croak("failed at mkd_compile");
}
if ( (szhtml = mkd_document(doc, &html)) == EOF ) {;
mkd_cleanup(doc);
croak("failed at mkd_document");
}
r = newSVpvn(html, szhtml);
sv_catpv(r, "\n");
if (is_utf8) {
sv_utf8_decode(r);
}
mkd_cleanup(doc);
RETVAL = r;
OUTPUT:
RETVAL
void
TextMarkdown_with_html5_tags()
CODE:
mkd_with_html5_tags();