#include "EXTERN.h"
|
|
#include "perl.h"
|
|
#include "XSUB.h"
|
|
|
|
#include "ppport.h"
|
|
|
|
#include <string.h>
|
|
#include <mkdio.h>
|
|
#include <cstring.h>
|
|
|
|
typedef struct line {
|
|
Cstring text;
|
|
struct line *next;
|
|
int dle;
|
|
} Line;
|
|
|
|
typedef struct paragraph {
|
|
struct paragraph *next; /* next paragraph */
|
|
struct paragraph *down; /* recompiled contents of this paragraph */
|
|
struct line *text; /* all the text in this paragraph */
|
|
char *ident; /* %id% tag for QUOTE */
|
|
enum { WHITESPACE=0, CODE, QUOTE, MARKUP,
|
|
HTML, STYLE, DL, UL, OL, AL, LISTITEM,
|
|
HDR, HR } typ;
|
|
enum { IMPLICIT=0, PARA, CENTER} align;
|
|
int hnumber; /* <Hn> for typ == HDR */
|
|
} Paragraph;
|
|
|
|
typedef struct document {
|
|
Line *headers; /* title -> author(s) -> date */
|
|
ANCHOR(Line) content; /* uncompiled text, not valid after compile() */
|
|
Paragraph *code; /* intermediate code generated by compile() */
|
|
int compiled; /* set after mkd_compile() */
|
|
int html; /* set after (internal) htmlify() */
|
|
int tabstop; /* for properly expanding tabs (ick) */
|
|
MMIOT *ctx; /* backend buffers, flags, and structures */
|
|
char *base; /* url basename for url fragments */
|
|
} Document;
|
|
|
|
MODULE = Text::Markdown::Discount PACKAGE = Text::Markdown::Discount PREFIX = TextMarkdown_
|
|
|
|
PROTOTYPES: DISABLE
|
|
|
|
SV *
|
|
TextMarkdown__markdown(text, uflags)
|
|
char *text;
|
|
int uflags;
|
|
PREINIT:
|
|
SV* r = &PL_sv_undef;
|
|
int flags = MKD_TABSTOP | MKD_NOHEADER;
|
|
char *html = NULL;
|
|
int szhtml;
|
|
Document *doc;
|
|
CODE:
|
|
if ( uflags ) {
|
|
flags |= uflags;
|
|
}
|
|
|
|
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");
|
|
|
|
mkd_cleanup(doc);
|
|
RETVAL = r;
|
|
OUTPUT:
|
|
RETVAL
|