2011-04-15 08:36:46 +00:00
|
|
|
/* markdown.h - generic markdown parser */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2009, Natacha Porté
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef UPSKIRT_MARKDOWN_H
|
|
|
|
#define UPSKIRT_MARKDOWN_H
|
|
|
|
|
|
|
|
#include "buffer.h"
|
2011-06-09 00:58:06 +00:00
|
|
|
#include "autolink.h"
|
2011-04-15 08:36:46 +00:00
|
|
|
|
2011-06-02 21:54:18 +00:00
|
|
|
#define UPSKIRT_VERSION "1.15.2"
|
2011-05-11 17:07:28 +00:00
|
|
|
#define UPSKIRT_VER_MAJOR 1
|
2011-06-02 00:21:41 +00:00
|
|
|
#define UPSKIRT_VER_MINOR 15
|
2011-06-02 21:54:18 +00:00
|
|
|
#define UPSKIRT_VER_REVISION 2
|
2011-05-11 17:07:28 +00:00
|
|
|
|
2011-04-15 08:36:46 +00:00
|
|
|
/********************
|
|
|
|
* TYPE DEFINITIONS *
|
|
|
|
********************/
|
|
|
|
|
2011-08-04 14:22:38 +00:00
|
|
|
/* mkd_autolink - type of autolink */
|
2011-04-15 08:36:46 +00:00
|
|
|
enum mkd_autolink {
|
|
|
|
MKDA_NOT_AUTOLINK, /* used internally when it is not an autolink*/
|
2011-04-25 19:18:10 +00:00
|
|
|
MKDA_NORMAL, /* normal http/http/ftp/mailto/etc link */
|
|
|
|
MKDA_EMAIL, /* e-mail link without explit mailto: */
|
2011-04-15 08:36:46 +00:00
|
|
|
};
|
|
|
|
|
2011-08-09 04:11:42 +00:00
|
|
|
enum mkd_tableflags {
|
|
|
|
MKD_TABLE_ALIGN_L = 1,
|
|
|
|
MKD_TABLE_ALIGN_R = 2,
|
|
|
|
MKD_TABLE_ALIGN_CENTER = 3,
|
|
|
|
MKD_TABLE_ALIGNMASK = 3,
|
|
|
|
MKD_TABLE_HEADER = 4
|
|
|
|
};
|
|
|
|
|
2011-04-15 08:36:46 +00:00
|
|
|
enum mkd_extensions {
|
2011-04-30 00:54:29 +00:00
|
|
|
MKDEXT_NO_INTRA_EMPHASIS = (1 << 0),
|
2011-04-15 08:36:46 +00:00
|
|
|
MKDEXT_TABLES = (1 << 1),
|
|
|
|
MKDEXT_FENCED_CODE = (1 << 2),
|
|
|
|
MKDEXT_AUTOLINK = (1 << 3),
|
|
|
|
MKDEXT_STRIKETHROUGH = (1 << 4),
|
2011-04-18 19:16:59 +00:00
|
|
|
MKDEXT_LAX_HTML_BLOCKS = (1 << 5),
|
2011-05-06 19:04:27 +00:00
|
|
|
MKDEXT_SPACE_HEADERS = (1 << 6),
|
2011-07-25 00:15:43 +00:00
|
|
|
MKDEXT_SUPERSCRIPT = (1 << 7),
|
2011-04-15 08:36:46 +00:00
|
|
|
};
|
|
|
|
|
2011-08-04 14:22:38 +00:00
|
|
|
/* sd_callbacks - functions for rendering parsed data */
|
|
|
|
struct sd_callbacks {
|
2011-04-15 08:36:46 +00:00
|
|
|
/* block level callbacks - NULL skips the block */
|
2011-04-16 14:48:32 +00:00
|
|
|
void (*blockcode)(struct buf *ob, struct buf *text, struct buf *lang, void *opaque);
|
2011-04-15 08:36:46 +00:00
|
|
|
void (*blockquote)(struct buf *ob, struct buf *text, void *opaque);
|
|
|
|
void (*blockhtml)(struct buf *ob, struct buf *text, void *opaque);
|
|
|
|
void (*header)(struct buf *ob, struct buf *text, int level, void *opaque);
|
|
|
|
void (*hrule)(struct buf *ob, void *opaque);
|
|
|
|
void (*list)(struct buf *ob, struct buf *text, int flags, void *opaque);
|
|
|
|
void (*listitem)(struct buf *ob, struct buf *text, int flags, void *opaque);
|
|
|
|
void (*paragraph)(struct buf *ob, struct buf *text, void *opaque);
|
|
|
|
void (*table)(struct buf *ob, struct buf *header, struct buf *body, void *opaque);
|
|
|
|
void (*table_row)(struct buf *ob, struct buf *text, void *opaque);
|
|
|
|
void (*table_cell)(struct buf *ob, struct buf *text, int flags, void *opaque);
|
|
|
|
|
|
|
|
|
|
|
|
/* span level callbacks - NULL or return 0 prints the span verbatim */
|
|
|
|
int (*autolink)(struct buf *ob, struct buf *link, enum mkd_autolink type, void *opaque);
|
|
|
|
int (*codespan)(struct buf *ob, struct buf *text, void *opaque);
|
2011-04-22 11:35:32 +00:00
|
|
|
int (*double_emphasis)(struct buf *ob, struct buf *text, void *opaque);
|
|
|
|
int (*emphasis)(struct buf *ob, struct buf *text, void *opaque);
|
2011-04-15 08:36:46 +00:00
|
|
|
int (*image)(struct buf *ob, struct buf *link, struct buf *title, struct buf *alt, void *opaque);
|
|
|
|
int (*linebreak)(struct buf *ob, void *opaque);
|
|
|
|
int (*link)(struct buf *ob, struct buf *link, struct buf *title, struct buf *content, void *opaque);
|
|
|
|
int (*raw_html_tag)(struct buf *ob, struct buf *tag, void *opaque);
|
2011-04-22 11:35:32 +00:00
|
|
|
int (*triple_emphasis)(struct buf *ob, struct buf *text, void *opaque);
|
|
|
|
int (*strikethrough)(struct buf *ob, struct buf *text, void *opaque);
|
2011-07-25 00:15:43 +00:00
|
|
|
int (*superscript)(struct buf *ob, struct buf *text, void *opaque);
|
2011-04-15 08:36:46 +00:00
|
|
|
|
|
|
|
/* low level callbacks - NULL copies input directly into the output */
|
|
|
|
void (*entity)(struct buf *ob, struct buf *entity, void *opaque);
|
|
|
|
void (*normal_text)(struct buf *ob, struct buf *text, void *opaque);
|
|
|
|
|
|
|
|
/* header and footer */
|
|
|
|
void (*doc_header)(struct buf *ob, void *opaque);
|
|
|
|
void (*doc_footer)(struct buf *ob, void *opaque);
|
|
|
|
};
|
|
|
|
|
|
|
|
/*********
|
|
|
|
* FLAGS *
|
|
|
|
*********/
|
|
|
|
|
|
|
|
/* list/listitem flags */
|
|
|
|
#define MKD_LIST_ORDERED 1
|
|
|
|
#define MKD_LI_BLOCK 2 /* <li> containing block data */
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* EXPORTED FUNCTIONS *
|
|
|
|
**********************/
|
|
|
|
|
2011-07-18 21:27:33 +00:00
|
|
|
/* sd_markdown * parses the input buffer and renders it into the output buffer */
|
2011-04-15 08:36:46 +00:00
|
|
|
extern void
|
2011-08-04 14:22:38 +00:00
|
|
|
sd_markdown(struct buf *ob, const struct buf *ib, unsigned int extensions, const struct sd_callbacks *rndr, void *opaque);
|
2011-04-15 08:36:46 +00:00
|
|
|
|
2011-07-18 21:27:33 +00:00
|
|
|
/* sd_version * returns the library version as major.minor.rev */
|
2011-05-11 17:07:28 +00:00
|
|
|
extern void
|
2011-07-18 21:27:33 +00:00
|
|
|
sd_version(int *major, int *minor, int *revision);
|
2011-05-11 17:07:28 +00:00
|
|
|
|
2011-04-15 08:36:46 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* vim: set filetype=c: */
|