2014-02-06 18:40:41 +00:00
|
|
|
/* document.h - generic markdown parser */
|
2011-04-15 08:36:46 +00:00
|
|
|
|
2014-02-06 18:40:41 +00:00
|
|
|
#ifndef HOEDOWN_DOCUMENT_H
|
|
|
|
#define HOEDOWN_DOCUMENT_H
|
2011-04-15 08:36:46 +00:00
|
|
|
|
|
|
|
#include "buffer.h"
|
2011-06-09 00:58:06 +00:00
|
|
|
#include "autolink.h"
|
2011-04-15 08:36:46 +00:00
|
|
|
|
2012-04-04 19:15:29 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2014-02-08 19:02:36 +00:00
|
|
|
/*********
|
|
|
|
* FLAGS *
|
|
|
|
*********/
|
|
|
|
|
|
|
|
enum hoedown_extensions {
|
2014-02-13 20:25:37 +00:00
|
|
|
/* block-level extensions */
|
2014-03-23 18:56:05 +00:00
|
|
|
HOEDOWN_EXT_TABLES = (1 << 0),
|
|
|
|
HOEDOWN_EXT_FENCED_CODE = (1 << 1),
|
|
|
|
HOEDOWN_EXT_FOOTNOTES = (1 << 2),
|
2014-02-13 20:25:37 +00:00
|
|
|
|
|
|
|
/* span-level extensions */
|
2014-03-23 18:56:05 +00:00
|
|
|
HOEDOWN_EXT_AUTOLINK = (1 << 3),
|
|
|
|
HOEDOWN_EXT_STRIKETHROUGH = (1 << 4),
|
|
|
|
HOEDOWN_EXT_UNDERLINE = (1 << 5),
|
|
|
|
HOEDOWN_EXT_HIGHLIGHT = (1 << 6),
|
|
|
|
HOEDOWN_EXT_QUOTE = (1 << 7),
|
|
|
|
HOEDOWN_EXT_SUPERSCRIPT = (1 << 8),
|
2014-02-13 20:25:37 +00:00
|
|
|
|
|
|
|
/* other flags */
|
2014-03-23 18:56:05 +00:00
|
|
|
HOEDOWN_EXT_LAX_SPACING = (1 << 9),
|
|
|
|
HOEDOWN_EXT_NO_INTRA_EMPHASIS = (1 << 10),
|
|
|
|
HOEDOWN_EXT_SPACE_HEADERS = (1 << 11),
|
2014-02-13 20:25:37 +00:00
|
|
|
|
|
|
|
/* negative flags */
|
|
|
|
HOEDOWN_EXT_DISABLE_INDENTED_CODE = (1 << 12)
|
2014-02-08 19:02:36 +00:00
|
|
|
};
|
|
|
|
|
2014-02-13 20:27:55 +00:00
|
|
|
#define HOEDOWN_EXT_BLOCK (\
|
|
|
|
HOEDOWN_EXT_TABLES |\
|
|
|
|
HOEDOWN_EXT_FENCED_CODE |\
|
|
|
|
HOEDOWN_EXT_FOOTNOTES )
|
|
|
|
|
|
|
|
#define HOEDOWN_EXT_SPAN (\
|
|
|
|
HOEDOWN_EXT_AUTOLINK |\
|
|
|
|
HOEDOWN_EXT_STRIKETHROUGH |\
|
|
|
|
HOEDOWN_EXT_UNDERLINE |\
|
|
|
|
HOEDOWN_EXT_HIGHLIGHT |\
|
|
|
|
HOEDOWN_EXT_QUOTE |\
|
|
|
|
HOEDOWN_EXT_SUPERSCRIPT )
|
|
|
|
|
|
|
|
#define HOEDOWN_EXT_FLAGS (\
|
2014-03-04 21:48:58 +00:00
|
|
|
HOEDOWN_EXT_LAX_SPACING |\
|
2014-03-23 18:56:05 +00:00
|
|
|
HOEDOWN_EXT_NO_INTRA_EMPHASIS |\
|
|
|
|
HOEDOWN_EXT_SPACE_HEADERS )
|
2014-02-13 20:27:55 +00:00
|
|
|
|
2014-03-04 21:48:58 +00:00
|
|
|
#define HOEDOWN_EXT_NEGATIVE (\
|
2014-02-13 20:27:55 +00:00
|
|
|
HOEDOWN_EXT_DISABLE_INDENTED_CODE )
|
|
|
|
|
2014-02-08 19:02:36 +00:00
|
|
|
/* list/listitem flags */
|
|
|
|
enum hoedown_listflags {
|
|
|
|
HOEDOWN_LIST_ORDERED = (1 << 0),
|
2014-06-11 04:01:30 +00:00
|
|
|
HOEDOWN_LI_BLOCK = (1 << 1) /* <li> containing block data */
|
2014-02-08 19:02:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum hoedown_tableflags {
|
2014-02-13 20:30:50 +00:00
|
|
|
HOEDOWN_TABLE_ALIGN_LEFT = 1,
|
|
|
|
HOEDOWN_TABLE_ALIGN_RIGHT = 2,
|
2014-02-08 19:02:36 +00:00
|
|
|
HOEDOWN_TABLE_ALIGN_CENTER = 3,
|
|
|
|
HOEDOWN_TABLE_ALIGNMASK = 3,
|
|
|
|
HOEDOWN_TABLE_HEADER = 4
|
|
|
|
};
|
|
|
|
|
|
|
|
/* hoedown_autolink - type of autolink */
|
|
|
|
enum hoedown_autolink {
|
|
|
|
HOEDOWN_AUTOLINK_NONE, /* used internally when it is not an autolink*/
|
|
|
|
HOEDOWN_AUTOLINK_NORMAL, /* normal http/http/ftp/mailto/etc link */
|
|
|
|
HOEDOWN_AUTOLINK_EMAIL /* e-mail link without explit mailto: */
|
|
|
|
};
|
|
|
|
|
2011-04-15 08:36:46 +00:00
|
|
|
/********************
|
|
|
|
* TYPE DEFINITIONS *
|
|
|
|
********************/
|
|
|
|
|
2013-10-06 14:31:42 +00:00
|
|
|
/* hoedown_renderer - functions for rendering parsed data */
|
|
|
|
struct hoedown_renderer {
|
2014-02-10 08:57:01 +00:00
|
|
|
/* state object */
|
|
|
|
void *opaque;
|
|
|
|
|
2011-04-15 08:36:46 +00:00
|
|
|
/* block level callbacks - NULL skips the block */
|
2013-10-01 03:02:48 +00:00
|
|
|
void (*blockcode)(hoedown_buffer *ob, const hoedown_buffer *text, const hoedown_buffer *lang, void *opaque);
|
|
|
|
void (*blockquote)(hoedown_buffer *ob, const hoedown_buffer *text, void *opaque);
|
|
|
|
void (*blockhtml)(hoedown_buffer *ob,const hoedown_buffer *text, void *opaque);
|
|
|
|
void (*header)(hoedown_buffer *ob, const hoedown_buffer *text, int level, void *opaque);
|
|
|
|
void (*hrule)(hoedown_buffer *ob, void *opaque);
|
2014-02-09 11:49:32 +00:00
|
|
|
void (*list)(hoedown_buffer *ob, const hoedown_buffer *text, unsigned int flags, void *opaque);
|
|
|
|
void (*listitem)(hoedown_buffer *ob, const hoedown_buffer *text, unsigned int flags, void *opaque);
|
2013-10-01 03:02:48 +00:00
|
|
|
void (*paragraph)(hoedown_buffer *ob, const hoedown_buffer *text, void *opaque);
|
|
|
|
void (*table)(hoedown_buffer *ob, const hoedown_buffer *header, const hoedown_buffer *body, void *opaque);
|
|
|
|
void (*table_row)(hoedown_buffer *ob, const hoedown_buffer *text, void *opaque);
|
2014-02-09 11:49:32 +00:00
|
|
|
void (*table_cell)(hoedown_buffer *ob, const hoedown_buffer *text, unsigned int flags, void *opaque);
|
2013-10-01 03:02:48 +00:00
|
|
|
void (*footnotes)(hoedown_buffer *ob, const hoedown_buffer *text, void *opaque);
|
|
|
|
void (*footnote_def)(hoedown_buffer *ob, const hoedown_buffer *text, unsigned int num, void *opaque);
|
2011-04-15 08:36:46 +00:00
|
|
|
|
|
|
|
/* span level callbacks - NULL or return 0 prints the span verbatim */
|
2013-10-01 03:02:48 +00:00
|
|
|
int (*autolink)(hoedown_buffer *ob, const hoedown_buffer *link, enum hoedown_autolink type, void *opaque);
|
|
|
|
int (*codespan)(hoedown_buffer *ob, const hoedown_buffer *text, void *opaque);
|
|
|
|
int (*double_emphasis)(hoedown_buffer *ob, const hoedown_buffer *text, void *opaque);
|
|
|
|
int (*emphasis)(hoedown_buffer *ob, const hoedown_buffer *text, void *opaque);
|
|
|
|
int (*underline)(hoedown_buffer *ob, const hoedown_buffer *text, void *opaque);
|
|
|
|
int (*highlight)(hoedown_buffer *ob, const hoedown_buffer *text, void *opaque);
|
|
|
|
int (*quote)(hoedown_buffer *ob, const hoedown_buffer *text, void *opaque);
|
|
|
|
int (*image)(hoedown_buffer *ob, const hoedown_buffer *link, const hoedown_buffer *title, const hoedown_buffer *alt, void *opaque);
|
|
|
|
int (*linebreak)(hoedown_buffer *ob, void *opaque);
|
|
|
|
int (*link)(hoedown_buffer *ob, const hoedown_buffer *link, const hoedown_buffer *title, const hoedown_buffer *content, void *opaque);
|
|
|
|
int (*raw_html_tag)(hoedown_buffer *ob, const hoedown_buffer *tag, void *opaque);
|
|
|
|
int (*triple_emphasis)(hoedown_buffer *ob, const hoedown_buffer *text, void *opaque);
|
|
|
|
int (*strikethrough)(hoedown_buffer *ob, const hoedown_buffer *text, void *opaque);
|
|
|
|
int (*superscript)(hoedown_buffer *ob, const hoedown_buffer *text, void *opaque);
|
|
|
|
int (*footnote_ref)(hoedown_buffer *ob, unsigned int num, void *opaque);
|
2011-04-15 08:36:46 +00:00
|
|
|
|
|
|
|
/* low level callbacks - NULL copies input directly into the output */
|
2013-10-01 03:02:48 +00:00
|
|
|
void (*entity)(hoedown_buffer *ob, const hoedown_buffer *entity, void *opaque);
|
|
|
|
void (*normal_text)(hoedown_buffer *ob, const hoedown_buffer *text, void *opaque);
|
2011-04-15 08:36:46 +00:00
|
|
|
|
|
|
|
/* header and footer */
|
2013-10-01 03:02:48 +00:00
|
|
|
void (*doc_header)(hoedown_buffer *ob, void *opaque);
|
|
|
|
void (*doc_footer)(hoedown_buffer *ob, void *opaque);
|
2011-04-15 08:36:46 +00:00
|
|
|
};
|
|
|
|
|
2013-10-06 14:31:42 +00:00
|
|
|
typedef struct hoedown_renderer hoedown_renderer;
|
2013-10-01 03:02:48 +00:00
|
|
|
|
2014-02-06 19:16:23 +00:00
|
|
|
struct hoedown_document;
|
2011-09-01 03:02:26 +00:00
|
|
|
|
2014-02-06 19:16:23 +00:00
|
|
|
typedef struct hoedown_document hoedown_document;
|
2013-10-01 03:02:48 +00:00
|
|
|
|
2011-04-15 08:36:46 +00:00
|
|
|
/**********************
|
|
|
|
* EXPORTED FUNCTIONS *
|
|
|
|
**********************/
|
|
|
|
|
2014-02-06 19:16:23 +00:00
|
|
|
extern hoedown_document *
|
|
|
|
hoedown_document_new(
|
2014-02-13 18:04:08 +00:00
|
|
|
const hoedown_renderer *renderer,
|
2011-09-01 03:02:26 +00:00
|
|
|
unsigned int extensions,
|
2014-02-13 18:04:08 +00:00
|
|
|
size_t max_nesting);
|
2011-09-01 03:02:26 +00:00
|
|
|
|
|
|
|
extern void
|
2014-02-07 14:01:29 +00:00
|
|
|
hoedown_document_render(hoedown_document *doc, hoedown_buffer *ob, const uint8_t *document, size_t doc_size);
|
2011-09-01 03:02:26 +00:00
|
|
|
|
2011-04-15 08:36:46 +00:00
|
|
|
extern void
|
2014-02-06 19:16:23 +00:00
|
|
|
hoedown_document_free(hoedown_document *doc);
|
2011-04-15 08:36:46 +00:00
|
|
|
|
2012-04-04 19:15:29 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-02-06 18:40:41 +00:00
|
|
|
#endif /** HOEDOWN_DOCUMENT_H **/
|