diff --git a/examples/hoedown.c b/examples/hoedown.c index 918c30f..2e13aa1 100644 --- a/examples/hoedown.c +++ b/examples/hoedown.c @@ -16,7 +16,7 @@ main(int argc, char **argv) FILE *in = stdin; hoedown_renderer *renderer; - struct hoedown_markdown *markdown; + hoedown_markdown *markdown; /* opening the file if given from the command line */ if (argc > 1) { diff --git a/src/html.c b/src/html.c index b997c9c..57f742e 100755 --- a/src/html.c +++ b/src/html.c @@ -9,7 +9,7 @@ #define USE_XHTML(opt) (opt->flags & HOEDOWN_HTML_USE_XHTML) -struct hoedown_html_renderopt { +struct rndr_state { struct { int header_count; int current_level; @@ -23,7 +23,7 @@ struct hoedown_html_renderopt { void (*link_attributes)(hoedown_buffer *ob, const hoedown_buffer *url, void *self); }; -typedef struct hoedown_html_renderopt hoedown_html_renderopt; +typedef struct rndr_state rndr_state; int hoedown_html_is_tag(const uint8_t *tag_data, size_t tag_size, const char *tagname) @@ -74,12 +74,12 @@ static inline void escape_href(hoedown_buffer *ob, const uint8_t *source, size_t static int rndr_autolink(hoedown_buffer *ob, const hoedown_buffer *link, enum hoedown_autolink type, void *opaque) { - hoedown_html_renderopt *options = opaque; + rndr_state *state = opaque; if (!link || !link->size) return 0; - if ((options->flags & HOEDOWN_HTML_SAFELINK) != 0 && + if ((state->flags & HOEDOWN_HTML_SAFELINK) != 0 && !hoedown_autolink_is_safe(link->data, link->size) && type != HOEDOWN_AUTOLINK_EMAIL) return 0; @@ -89,9 +89,9 @@ rndr_autolink(hoedown_buffer *ob, const hoedown_buffer *link, enum hoedown_autol HOEDOWN_BUFPUTSL(ob, "mailto:"); escape_href(ob, link->data, link->size); - if (options->link_attributes) { + if (state->link_attributes) { hoedown_buffer_putc(ob, '\"'); - options->link_attributes(ob, link, opaque); + state->link_attributes(ob, link, opaque); hoedown_buffer_putc(ob, '>'); } else { HOEDOWN_BUFPUTSL(ob, "\">"); @@ -116,13 +116,13 @@ rndr_autolink(hoedown_buffer *ob, const hoedown_buffer *link, enum hoedown_autol static void rndr_blockcode(hoedown_buffer *ob, const hoedown_buffer *text, const hoedown_buffer *lang, void *opaque) { - hoedown_html_renderopt *options = opaque; + rndr_state *state = opaque; if (ob->size) hoedown_buffer_putc(ob, '\n'); if (lang && lang->size) { size_t i, cls = 0; - if (options->flags & HOEDOWN_HTML_PRETTIFY) { + if (state->flags & HOEDOWN_HTML_PRETTIFY) { HOEDOWN_BUFPUTSL(ob, "
");
- } else if (options->flags & HOEDOWN_HTML_PRETTIFY) {
+ } else if (state->flags & HOEDOWN_HTML_PRETTIFY) {
HOEDOWN_BUFPUTSL(ob, "");
} else {
HOEDOWN_BUFPUTSL(ob, "");
@@ -171,8 +171,8 @@ rndr_blockquote(hoedown_buffer *ob, const hoedown_buffer *text, void *opaque)
static int
rndr_codespan(hoedown_buffer *ob, const hoedown_buffer *text, void *opaque)
{
- hoedown_html_renderopt *options = opaque;
- if (options->flags & HOEDOWN_HTML_PRETTIFY)
+ rndr_state *state = opaque;
+ if (state->flags & HOEDOWN_HTML_PRETTIFY)
HOEDOWN_BUFPUTSL(ob, "");
else
HOEDOWN_BUFPUTSL(ob, "");
@@ -258,21 +258,21 @@ rndr_quote(hoedown_buffer *ob, const hoedown_buffer *text, void *opaque)
static int
rndr_linebreak(hoedown_buffer *ob, void *opaque)
{
- hoedown_html_renderopt *options = opaque;
- hoedown_buffer_puts(ob, USE_XHTML(options) ? "
\n" : "
\n");
+ rndr_state *state = opaque;
+ hoedown_buffer_puts(ob, USE_XHTML(state) ? "
\n" : "
\n");
return 1;
}
static void
rndr_header(hoedown_buffer *ob, const hoedown_buffer *text, int level, void *opaque)
{
- hoedown_html_renderopt *options = opaque;
+ rndr_state *state = opaque;
if (ob->size)
hoedown_buffer_putc(ob, '\n');
- if ((options->flags & HOEDOWN_HTML_TOC) && (level <= options->toc_data.nesting_level))
- hoedown_buffer_printf(ob, "", level, options->toc_data.header_count++);
+ if ((state->flags & HOEDOWN_HTML_TOC) && (level <= state->toc_data.nesting_level))
+ hoedown_buffer_printf(ob, "", level, state->toc_data.header_count++);
else
hoedown_buffer_printf(ob, "", level);
@@ -283,9 +283,9 @@ rndr_header(hoedown_buffer *ob, const hoedown_buffer *text, int level, void *opa
static int
rndr_link(hoedown_buffer *ob, const hoedown_buffer *link, const hoedown_buffer *title, const hoedown_buffer *content, void *opaque)
{
- hoedown_html_renderopt *options = opaque;
+ rndr_state *state = opaque;
- if (link != NULL && (options->flags & HOEDOWN_HTML_SAFELINK) != 0 && !hoedown_autolink_is_safe(link->data, link->size))
+ if (link != NULL && (state->flags & HOEDOWN_HTML_SAFELINK) != 0 && !hoedown_autolink_is_safe(link->data, link->size))
return 0;
HOEDOWN_BUFPUTSL(ob, "data, title->size);
}
- if (options->link_attributes) {
+ if (state->link_attributes) {
hoedown_buffer_putc(ob, '\"');
- options->link_attributes(ob, link, opaque);
+ state->link_attributes(ob, link, opaque);
hoedown_buffer_putc(ob, '>');
} else {
HOEDOWN_BUFPUTSL(ob, "\">");
@@ -337,7 +337,7 @@ rndr_listitem(hoedown_buffer *ob, const hoedown_buffer *text, int flags, void *o
static void
rndr_paragraph(hoedown_buffer *ob, const hoedown_buffer *text, void *opaque)
{
- hoedown_html_renderopt *options = opaque;
+ rndr_state *state = opaque;
size_t i = 0;
if (ob->size) hoedown_buffer_putc(ob, '\n');
@@ -351,7 +351,7 @@ rndr_paragraph(hoedown_buffer *ob, const hoedown_buffer *text, void *opaque)
return;
HOEDOWN_BUFPUTSL(ob, "");
- if (options->flags & HOEDOWN_HTML_HARD_WRAP) {
+ if (state->flags & HOEDOWN_HTML_HARD_WRAP) {
size_t org;
while (i < text->size) {
org = i;
@@ -405,15 +405,15 @@ rndr_triple_emphasis(hoedown_buffer *ob, const hoedown_buffer *text, void *opaqu
static void
rndr_hrule(hoedown_buffer *ob, void *opaque)
{
- hoedown_html_renderopt *options = opaque;
+ rndr_state *state = opaque;
if (ob->size) hoedown_buffer_putc(ob, '\n');
- hoedown_buffer_puts(ob, USE_XHTML(options) ? "
\n" : "
\n");
+ hoedown_buffer_puts(ob, USE_XHTML(state) ? "
\n" : "
\n");
}
static int
rndr_image(hoedown_buffer *ob, const hoedown_buffer *link, const hoedown_buffer *title, const hoedown_buffer *alt, void *opaque)
{
- hoedown_html_renderopt *options = opaque;
+ rndr_state *state = opaque;
if (!link || !link->size) return 0;
HOEDOWN_BUFPUTSL(ob, "data, title->size); }
- hoedown_buffer_puts(ob, USE_XHTML(options) ? "\"/>" : "\">");
+ hoedown_buffer_puts(ob, USE_XHTML(state) ? "\"/>" : "\">");
return 1;
}
static int
rndr_raw_html(hoedown_buffer *ob, const hoedown_buffer *text, void *opaque)
{
- hoedown_html_renderopt *options = opaque;
+ rndr_state *state = opaque;
/* HTML_ESCAPE overrides SKIP_HTML, SKIP_STYLE, SKIP_LINKS and SKIP_IMAGES
* It doens't see if there are any valid tags, just escape all of them. */
- if((options->flags & HOEDOWN_HTML_ESCAPE) != 0) {
+ if((state->flags & HOEDOWN_HTML_ESCAPE) != 0) {
escape_html(ob, text->data, text->size);
return 1;
}
- if ((options->flags & HOEDOWN_HTML_SKIP_HTML) != 0)
+ if ((state->flags & HOEDOWN_HTML_SKIP_HTML) != 0)
return 1;
- if ((options->flags & HOEDOWN_HTML_SKIP_STYLE) != 0 &&
+ if ((state->flags & HOEDOWN_HTML_SKIP_STYLE) != 0 &&
hoedown_html_is_tag(text->data, text->size, "style"))
return 1;
- if ((options->flags & HOEDOWN_HTML_SKIP_LINKS) != 0 &&
+ if ((state->flags & HOEDOWN_HTML_SKIP_LINKS) != 0 &&
hoedown_html_is_tag(text->data, text->size, "a"))
return 1;
- if ((options->flags & HOEDOWN_HTML_SKIP_IMAGES) != 0 &&
+ if ((state->flags & HOEDOWN_HTML_SKIP_IMAGES) != 0 &&
hoedown_html_is_tag(text->data, text->size, "img"))
return 1;
@@ -540,11 +540,11 @@ rndr_normal_text(hoedown_buffer *ob, const hoedown_buffer *text, void *opaque)
static void
rndr_footnotes(hoedown_buffer *ob, const hoedown_buffer *text, void *opaque)
{
- hoedown_html_renderopt *options = opaque;
+ rndr_state *state = opaque;
if (ob->size) hoedown_buffer_putc(ob, '\n');
HOEDOWN_BUFPUTSL(ob, "\n");
- hoedown_buffer_puts(ob, USE_XHTML(options) ? "
\n" : "
\n");
+ hoedown_buffer_puts(ob, USE_XHTML(state) ? "
\n" : "
\n");
HOEDOWN_BUFPUTSL(ob, "\n");
if (text)
@@ -593,33 +593,33 @@ rndr_footnote_ref(hoedown_buffer *ob, unsigned int num, void *opaque)
static void
toc_header(hoedown_buffer *ob, const hoedown_buffer *text, int level, void *opaque)
{
- hoedown_html_renderopt *options = opaque;
+ rndr_state *state = opaque;
- if (level <= options->toc_data.nesting_level) {
+ if (level <= state->toc_data.nesting_level) {
/* set the level offset if this is the first header
* we're parsing for the document */
- if (options->toc_data.current_level == 0)
- options->toc_data.level_offset = level - 1;
+ if (state->toc_data.current_level == 0)
+ state->toc_data.level_offset = level - 1;
- level -= options->toc_data.level_offset;
+ level -= state->toc_data.level_offset;
- if (level > options->toc_data.current_level) {
- while (level > options->toc_data.current_level) {
+ if (level > state->toc_data.current_level) {
+ while (level > state->toc_data.current_level) {
HOEDOWN_BUFPUTSL(ob, "\n- \n");
- options->toc_data.current_level++;
+ state->toc_data.current_level++;
}
- } else if (level < options->toc_data.current_level) {
+ } else if (level < state->toc_data.current_level) {
HOEDOWN_BUFPUTSL(ob, "
\n");
- while (level < options->toc_data.current_level) {
+ while (level < state->toc_data.current_level) {
HOEDOWN_BUFPUTSL(ob, "
\n\n");
- options->toc_data.current_level--;
+ state->toc_data.current_level--;
}
HOEDOWN_BUFPUTSL(ob,"- \n");
} else {
HOEDOWN_BUFPUTSL(ob,"
\n- \n");
}
- hoedown_buffer_printf(ob, "", options->toc_data.header_count++);
+ hoedown_buffer_printf(ob, "", state->toc_data.header_count++);
if (text) escape_html(ob, text->data, text->size);
HOEDOWN_BUFPUTSL(ob, "\n");
}
@@ -636,11 +636,11 @@ toc_link(hoedown_buffer *ob, const hoedown_buffer *link, const hoedown_buffer *t
static void
toc_finalize(hoedown_buffer *ob, void *opaque)
{
- hoedown_html_renderopt *options = opaque;
+ rndr_state *state = opaque;
- while (options->toc_data.current_level > 0) {
+ while (state->toc_data.current_level > 0) {
HOEDOWN_BUFPUTSL(ob, "
\n\n");
- options->toc_data.current_level--;
+ state->toc_data.current_level--;
}
}
@@ -687,25 +687,25 @@ hoedown_html_toc_renderer_new(int nesting_level)
NULL
};
- hoedown_html_renderopt *options;
- hoedown_renderer *renderer;
+ rndr_state *state;
+ hoedown_renderer *renderer;
- /* Prepare the options pointer */
- options = malloc(sizeof(hoedown_html_renderopt));
- if (!options) return NULL;
- memset(options, 0x0, sizeof(hoedown_html_renderopt));
+ /* Prepare the state pointer */
+ state = malloc(sizeof(rndr_state));
+ if (!state) return NULL;
+ memset(state, 0x0, sizeof(rndr_state));
if (nesting_level > 0) {
- options->flags |= HOEDOWN_HTML_TOC;
- options->toc_data.nesting_level = nesting_level;
+ state->flags |= HOEDOWN_HTML_TOC;
+ state->toc_data.nesting_level = nesting_level;
}
/* Prepare the renderer */
renderer = malloc(sizeof(hoedown_renderer));
- if (!renderer) {free(options); return NULL;}
+ if (!renderer) {free(state); return NULL;}
memcpy(renderer, &cb_default, sizeof(hoedown_renderer));
- renderer->opaque = options;
+ renderer->opaque = state;
return renderer;
}
@@ -752,24 +752,24 @@ hoedown_html_renderer_new(unsigned int render_flags, int nesting_level)
NULL
};
- hoedown_html_renderopt *options;
- hoedown_renderer *renderer;
+ rndr_state *state;
+ hoedown_renderer *renderer;
- /* Prepare the options pointer */
- options = malloc(sizeof(hoedown_html_renderopt));
- if (!options) return NULL;
- memset(options, 0x0, sizeof(hoedown_html_renderopt));
+ /* Prepare the state pointer */
+ state = malloc(sizeof(rndr_state));
+ if (!state) return NULL;
+ memset(state, 0x0, sizeof(rndr_state));
- options->flags = render_flags;
+ state->flags = render_flags;
if (nesting_level > 0) {
- options->flags |= HOEDOWN_HTML_TOC;
- options->toc_data.nesting_level = nesting_level;
+ state->flags |= HOEDOWN_HTML_TOC;
+ state->toc_data.nesting_level = nesting_level;
}
/* Prepare the renderer */
renderer = malloc(sizeof(hoedown_renderer));
- if (!renderer) {free(options); return NULL;}
+ if (!renderer) {free(state); return NULL;}
memcpy(renderer, &cb_default, sizeof(hoedown_renderer));
if (render_flags & HOEDOWN_HTML_SKIP_IMAGES)
@@ -783,7 +783,7 @@ hoedown_html_renderer_new(unsigned int render_flags, int nesting_level)
if (render_flags & HOEDOWN_HTML_SKIP_HTML || render_flags & HOEDOWN_HTML_ESCAPE)
renderer->blockhtml = NULL;
- renderer->opaque = options;
+ renderer->opaque = state;
return renderer;
}
diff --git a/src/markdown.c b/src/markdown.c
index 2a0cdab..d9ef90b 100644
--- a/src/markdown.c
+++ b/src/markdown.c
@@ -64,20 +64,20 @@ struct footnote_list {
/* data is the pointer of the beginning of the span */
/* offset is the number of valid chars before data */
typedef size_t
-(*char_trigger)(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t offset, size_t size);
+(*char_trigger)(hoedown_buffer *ob, hoedown_markdown *md, uint8_t *data, size_t offset, size_t size);
-static size_t char_emphasis(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t offset, size_t size);
-static size_t char_quote(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t offset, size_t size);
-static size_t char_linebreak(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t offset, size_t size);
-static size_t char_codespan(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t offset, size_t size);
-static size_t char_escape(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t offset, size_t size);
-static size_t char_entity(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t offset, size_t size);
-static size_t char_langle_tag(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t offset, size_t size);
-static size_t char_autolink_url(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t offset, size_t size);
-static size_t char_autolink_email(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t offset, size_t size);
-static size_t char_autolink_www(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t offset, size_t size);
-static size_t char_link(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t offset, size_t size);
-static size_t char_superscript(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t offset, size_t size);
+static size_t char_emphasis(hoedown_buffer *ob, hoedown_markdown *md, uint8_t *data, size_t offset, size_t size);
+static size_t char_quote(hoedown_buffer *ob, hoedown_markdown *md, uint8_t *data, size_t offset, size_t size);
+static size_t char_linebreak(hoedown_buffer *ob, hoedown_markdown *md, uint8_t *data, size_t offset, size_t size);
+static size_t char_codespan(hoedown_buffer *ob, hoedown_markdown *md, uint8_t *data, size_t offset, size_t size);
+static size_t char_escape(hoedown_buffer *ob, hoedown_markdown *md, uint8_t *data, size_t offset, size_t size);
+static size_t char_entity(hoedown_buffer *ob, hoedown_markdown *md, uint8_t *data, size_t offset, size_t size);
+static size_t char_langle_tag(hoedown_buffer *ob, hoedown_markdown *md, uint8_t *data, size_t offset, size_t size);
+static size_t char_autolink_url(hoedown_buffer *ob, hoedown_markdown *md, uint8_t *data, size_t offset, size_t size);
+static size_t char_autolink_email(hoedown_buffer *ob, hoedown_markdown *md, uint8_t *data, size_t offset, size_t size);
+static size_t char_autolink_www(hoedown_buffer *ob, hoedown_markdown *md, uint8_t *data, size_t offset, size_t size);
+static size_t char_link(hoedown_buffer *ob, hoedown_markdown *md, uint8_t *data, size_t offset, size_t size);
+static size_t char_superscript(hoedown_buffer *ob, hoedown_markdown *md, uint8_t *data, size_t offset, size_t size);
enum markdown_char_t {
MD_CHAR_NONE = 0,
@@ -111,9 +111,9 @@ static char_trigger markdown_char_ptrs[] = {
&char_quote
};
-/* render • structure containing one particular render */
+/* render • structure containing state for a parser instance */
struct hoedown_markdown {
- hoedown_renderer cb;
+ hoedown_renderer md;
struct link_ref *refs[REF_TABLE_SIZE];
struct footnote_list footnotes_found;
@@ -130,11 +130,11 @@ struct hoedown_markdown {
***************************/
static inline hoedown_buffer *
-rndr_newbuf(hoedown_markdown *rndr, int type)
+newbuf(hoedown_markdown *md, int type)
{
static const size_t buf_size[2] = {256, 64};
hoedown_buffer *work = NULL;
- hoedown_stack *pool = &rndr->work_bufs[type];
+ hoedown_stack *pool = &md->work_bufs[type];
if (pool->size < pool->asize &&
pool->item[pool->size] != NULL) {
@@ -149,9 +149,9 @@ rndr_newbuf(hoedown_markdown *rndr, int type)
}
static inline void
-rndr_popbuf(hoedown_markdown *rndr, int type)
+popbuf(hoedown_markdown *md, int type)
{
- rndr->work_bufs[type].size--;
+ md->work_bufs[type].size--;
}
static void
@@ -428,26 +428,26 @@ tag_length(uint8_t *data, size_t size, enum hoedown_autolink *autolink)
/* parse_inline • parses inline markdown elements */
static void
-parse_inline(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t size)
+parse_inline(hoedown_buffer *ob, hoedown_markdown *md, uint8_t *data, size_t size)
{
size_t i = 0, end = 0;
uint8_t action = 0;
hoedown_buffer work = { 0, 0, 0, 0 };
- if (rndr->work_bufs[BUFFER_SPAN].size +
- rndr->work_bufs[BUFFER_BLOCK].size > rndr->max_nesting)
+ if (md->work_bufs[BUFFER_SPAN].size +
+ md->work_bufs[BUFFER_BLOCK].size > md->max_nesting)
return;
while (i < size) {
/* copying inactive chars into the output */
- while (end < size && (action = rndr->active_char[data[end]]) == 0) {
+ while (end < size && (action = md->active_char[data[end]]) == 0) {
end++;
}
- if (rndr->cb.normal_text) {
+ if (md->md.normal_text) {
work.data = data + i;
work.size = end - i;
- rndr->cb.normal_text(ob, &work, rndr->cb.opaque);
+ md->md.normal_text(ob, &work, md->md.opaque);
}
else
hoedown_buffer_put(ob, data + i, end - i);
@@ -455,7 +455,7 @@ parse_inline(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t s
if (end >= size) break;
i = end;
- end = markdown_char_ptrs[(int)action](ob, rndr, data + i, i, size - i);
+ end = markdown_char_ptrs[(int)action](ob, md, data + i, i, size - i);
if (!end) /* no action from the callback */
end = i + 1;
else {
@@ -559,7 +559,7 @@ find_emph_char(uint8_t *data, size_t size, uint8_t c)
/* parse_emph1 • parsing single emphase */
/* closed by a symbol not preceded by whitespace and not followed by symbol */
static size_t
-parse_emph1(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t size, uint8_t c)
+parse_emph1(hoedown_buffer *ob, hoedown_markdown *md, uint8_t *data, size_t size, uint8_t c)
{
size_t i = 0, len;
hoedown_buffer *work = 0;
@@ -576,20 +576,20 @@ parse_emph1(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t si
if (data[i] == c && !_isspace(data[i - 1])) {
- if (rndr->ext_flags & HOEDOWN_EXT_NO_INTRA_EMPHASIS) {
+ if (md->ext_flags & HOEDOWN_EXT_NO_INTRA_EMPHASIS) {
if (i + 1 < size && isalnum(data[i + 1]))
continue;
}
- work = rndr_newbuf(rndr, BUFFER_SPAN);
- parse_inline(work, rndr, data, i);
+ work = newbuf(md, BUFFER_SPAN);
+ parse_inline(work, md, data, i);
- if (rndr->ext_flags & HOEDOWN_EXT_UNDERLINE && c == '_')
- r = rndr->cb.underline(ob, work, rndr->cb.opaque);
+ if (md->ext_flags & HOEDOWN_EXT_UNDERLINE && c == '_')
+ r = md->md.underline(ob, work, md->md.opaque);
else
- r = rndr->cb.emphasis(ob, work, rndr->cb.opaque);
+ r = md->md.emphasis(ob, work, md->md.opaque);
- rndr_popbuf(rndr, BUFFER_SPAN);
+ popbuf(md, BUFFER_SPAN);
return r ? i + 1 : 0;
}
}
@@ -599,7 +599,7 @@ parse_emph1(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t si
/* parse_emph2 • parsing single emphase */
static size_t
-parse_emph2(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t size, uint8_t c)
+parse_emph2(hoedown_buffer *ob, hoedown_markdown *md, uint8_t *data, size_t size, uint8_t c)
{
size_t i = 0, len;
hoedown_buffer *work = 0;
@@ -611,17 +611,17 @@ parse_emph2(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t si
i += len;
if (i + 1 < size && data[i] == c && data[i + 1] == c && i && !_isspace(data[i - 1])) {
- work = rndr_newbuf(rndr, BUFFER_SPAN);
- parse_inline(work, rndr, data, i);
+ work = newbuf(md, BUFFER_SPAN);
+ parse_inline(work, md, data, i);
if (c == '~')
- r = rndr->cb.strikethrough(ob, work, rndr->cb.opaque);
+ r = md->md.strikethrough(ob, work, md->md.opaque);
else if (c == '=')
- r = rndr->cb.highlight(ob, work, rndr->cb.opaque);
+ r = md->md.highlight(ob, work, md->md.opaque);
else
- r = rndr->cb.double_emphasis(ob, work, rndr->cb.opaque);
+ r = md->md.double_emphasis(ob, work, md->md.opaque);
- rndr_popbuf(rndr, BUFFER_SPAN);
+ popbuf(md, BUFFER_SPAN);
return r ? i + 2 : 0;
}
i++;
@@ -632,7 +632,7 @@ parse_emph2(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t si
/* parse_emph3 • parsing single emphase */
/* finds the first closing tag, and delegates to the other emph */
static size_t
-parse_emph3(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t size, uint8_t c)
+parse_emph3(hoedown_buffer *ob, hoedown_markdown *md, uint8_t *data, size_t size, uint8_t c)
{
size_t i = 0, len;
int r;
@@ -646,24 +646,24 @@ parse_emph3(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t si
if (data[i] != c || _isspace(data[i - 1]))
continue;
- if (i + 2 < size && data[i + 1] == c && data[i + 2] == c && rndr->cb.triple_emphasis) {
+ if (i + 2 < size && data[i + 1] == c && data[i + 2] == c && md->md.triple_emphasis) {
/* triple symbol found */
- hoedown_buffer *work = rndr_newbuf(rndr, BUFFER_SPAN);
+ hoedown_buffer *work = newbuf(md, BUFFER_SPAN);
- parse_inline(work, rndr, data, i);
- r = rndr->cb.triple_emphasis(ob, work, rndr->cb.opaque);
- rndr_popbuf(rndr, BUFFER_SPAN);
+ parse_inline(work, md, data, i);
+ r = md->md.triple_emphasis(ob, work, md->md.opaque);
+ popbuf(md, BUFFER_SPAN);
return r ? i + 3 : 0;
} else if (i + 1 < size && data[i + 1] == c) {
/* double symbol found, handing over to emph1 */
- len = parse_emph1(ob, rndr, data - 2, size + 2, c);
+ len = parse_emph1(ob, md, data - 2, size + 2, c);
if (!len) return 0;
else return len - 2;
} else {
/* single symbol found, handing over to emph2 */
- len = parse_emph2(ob, rndr, data - 1, size + 1, c);
+ len = parse_emph2(ob, md, data - 1, size + 1, c);
if (!len) return 0;
else return len - 1;
}
@@ -673,12 +673,12 @@ parse_emph3(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t si
/* char_emphasis • single and double emphasis parsing */
static size_t
-char_emphasis(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t offset, size_t size)
+char_emphasis(hoedown_buffer *ob, hoedown_markdown *md, uint8_t *data, size_t offset, size_t size)
{
uint8_t c = data[0];
size_t ret;
- if (rndr->ext_flags & HOEDOWN_EXT_NO_INTRA_EMPHASIS) {
+ if (md->ext_flags & HOEDOWN_EXT_NO_INTRA_EMPHASIS) {
if (offset > 0 && !_isspace(data[-1]) && data[-1] != '>' && data[-1] != '(')
return 0;
}
@@ -686,21 +686,21 @@ char_emphasis(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t
if (size > 2 && data[1] != c) {
/* whitespace cannot follow an opening emphasis;
* strikethrough only takes two characters '~~' */
- if (c == '~' || c == '=' || _isspace(data[1]) || (ret = parse_emph1(ob, rndr, data + 1, size - 1, c)) == 0)
+ if (c == '~' || c == '=' || _isspace(data[1]) || (ret = parse_emph1(ob, md, data + 1, size - 1, c)) == 0)
return 0;
return ret + 1;
}
if (size > 3 && data[1] == c && data[2] != c) {
- if (_isspace(data[2]) || (ret = parse_emph2(ob, rndr, data + 2, size - 2, c)) == 0)
+ if (_isspace(data[2]) || (ret = parse_emph2(ob, md, data + 2, size - 2, c)) == 0)
return 0;
return ret + 2;
}
if (size > 4 && data[1] == c && data[2] == c && data[3] != c) {
- if (c == '~' || c == '=' || _isspace(data[3]) || (ret = parse_emph3(ob, rndr, data + 3, size - 3, c)) == 0)
+ if (c == '~' || c == '=' || _isspace(data[3]) || (ret = parse_emph3(ob, md, data + 3, size - 3, c)) == 0)
return 0;
return ret + 3;
@@ -712,7 +712,7 @@ char_emphasis(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t
/* char_linebreak • '\n' preceded by two spaces (assuming linebreak != 0) */
static size_t
-char_linebreak(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t offset, size_t size)
+char_linebreak(hoedown_buffer *ob, hoedown_markdown *md, uint8_t *data, size_t offset, size_t size)
{
if (offset < 2 || data[-1] != ' ' || data[-2] != ' ')
return 0;
@@ -721,13 +721,13 @@ char_linebreak(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t
while (ob->size && ob->data[ob->size - 1] == ' ')
ob->size--;
- return rndr->cb.linebreak(ob, rndr->cb.opaque) ? 1 : 0;
+ return md->md.linebreak(ob, md->md.opaque) ? 1 : 0;
}
/* char_codespan • '`' parsing a code span (assuming codespan != 0) */
static size_t
-char_codespan(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t offset, size_t size)
+char_codespan(hoedown_buffer *ob, hoedown_markdown *md, uint8_t *data, size_t offset, size_t size)
{
size_t end, nb = 0, i, f_begin, f_end;
@@ -757,10 +757,10 @@ char_codespan(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t
/* real code span */
if (f_begin < f_end) {
hoedown_buffer work = { data + f_begin, f_end - f_begin, 0, 0 };
- if (!rndr->cb.codespan(ob, &work, rndr->cb.opaque))
+ if (!md->md.codespan(ob, &work, md->md.opaque))
end = 0;
} else {
- if (!rndr->cb.codespan(ob, 0, rndr->cb.opaque))
+ if (!md->md.codespan(ob, 0, md->md.opaque))
end = 0;
}
@@ -769,7 +769,7 @@ char_codespan(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t
/* char_quote • '"' parsing a quote */
static size_t
-char_quote(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t offset, size_t size)
+char_quote(hoedown_buffer *ob, hoedown_markdown *md, uint8_t *data, size_t offset, size_t size)
{
size_t end, nq = 0, i, f_begin, f_end;
@@ -799,10 +799,10 @@ char_quote(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t off
/* real quote */
if (f_begin < f_end) {
hoedown_buffer work = { data + f_begin, f_end - f_begin, 0, 0 };
- if (!rndr->cb.quote(ob, &work, rndr->cb.opaque))
+ if (!md->md.quote(ob, &work, md->md.opaque))
end = 0;
} else {
- if (!rndr->cb.quote(ob, 0, rndr->cb.opaque))
+ if (!md->md.quote(ob, 0, md->md.opaque))
end = 0;
}
@@ -812,7 +812,7 @@ char_quote(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t off
/* char_escape • '\\' backslash escape */
static size_t
-char_escape(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t offset, size_t size)
+char_escape(hoedown_buffer *ob, hoedown_markdown *md, uint8_t *data, size_t offset, size_t size)
{
static const char *escape_chars = "\\`*_{}[]()#+-.!:|&<>^~";
hoedown_buffer work = { 0, 0, 0, 0 };
@@ -821,10 +821,10 @@ char_escape(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t of
if (strchr(escape_chars, data[1]) == NULL)
return 0;
- if (rndr->cb.normal_text) {
+ if (md->md.normal_text) {
work.data = data + 1;
work.size = 1;
- rndr->cb.normal_text(ob, &work, rndr->cb.opaque);
+ md->md.normal_text(ob, &work, md->md.opaque);
}
else hoedown_buffer_putc(ob, data[1]);
} else if (size == 1) {
@@ -837,7 +837,7 @@ char_escape(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t of
/* char_entity • '&' escaped when it doesn't belong to an entity */
/* valid entities are assumed to be anything matching ?[A-Za-z0-9]+; */
static size_t
-char_entity(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t offset, size_t size)
+char_entity(hoedown_buffer *ob, hoedown_markdown *md, uint8_t *data, size_t offset, size_t size)
{
size_t end = 1;
hoedown_buffer work = { 0, 0, 0, 0 };
@@ -853,10 +853,10 @@ char_entity(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t of
else
return 0; /* lone '&' */
- if (rndr->cb.entity) {
+ if (md->md.entity) {
work.data = data;
work.size = end;
- rndr->cb.entity(ob, &work, rndr->cb.opaque);
+ md->md.entity(ob, &work, md->md.opaque);
}
else hoedown_buffer_put(ob, data, end);
@@ -865,7 +865,7 @@ char_entity(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t of
/* char_langle_tag • '<' when tags or autolinks are allowed */
static size_t
-char_langle_tag(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t offset, size_t size)
+char_langle_tag(hoedown_buffer *ob, hoedown_markdown *md, uint8_t *data, size_t offset, size_t size)
{
enum hoedown_autolink altype = HOEDOWN_AUTOLINK_NONE;
size_t end = tag_length(data, size, &altype);
@@ -873,16 +873,16 @@ char_langle_tag(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_
int ret = 0;
if (end > 2) {
- if (rndr->cb.autolink && altype != HOEDOWN_AUTOLINK_NONE) {
- hoedown_buffer *u_link = rndr_newbuf(rndr, BUFFER_SPAN);
+ if (md->md.autolink && altype != HOEDOWN_AUTOLINK_NONE) {
+ hoedown_buffer *u_link = newbuf(md, BUFFER_SPAN);
work.data = data + 1;
work.size = end - 2;
unscape_text(u_link, &work);
- ret = rndr->cb.autolink(ob, u_link, altype, rndr->cb.opaque);
- rndr_popbuf(rndr, BUFFER_SPAN);
+ ret = md->md.autolink(ob, u_link, altype, md->md.opaque);
+ popbuf(md, BUFFER_SPAN);
}
- else if (rndr->cb.raw_html_tag)
- ret = rndr->cb.raw_html_tag(ob, &work, rndr->cb.opaque);
+ else if (md->md.raw_html_tag)
+ ret = md->md.raw_html_tag(ob, &work, md->md.opaque);
}
if (!ret) return 0;
@@ -890,80 +890,80 @@ char_langle_tag(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_
}
static size_t
-char_autolink_www(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t offset, size_t size)
+char_autolink_www(hoedown_buffer *ob, hoedown_markdown *md, uint8_t *data, size_t offset, size_t size)
{
hoedown_buffer *link, *link_url, *link_text;
size_t link_len, rewind;
- if (!rndr->cb.link || rndr->in_link_body)
+ if (!md->md.link || md->in_link_body)
return 0;
- link = rndr_newbuf(rndr, BUFFER_SPAN);
+ link = newbuf(md, BUFFER_SPAN);
if ((link_len = hoedown_autolink__www(&rewind, link, data, offset, size, HOEDOWN_AUTOLINK_SHORT_DOMAINS)) > 0) {
- link_url = rndr_newbuf(rndr, BUFFER_SPAN);
+ link_url = newbuf(md, BUFFER_SPAN);
HOEDOWN_BUFPUTSL(link_url, "http://");
hoedown_buffer_put(link_url, link->data, link->size);
ob->size -= rewind;
- if (rndr->cb.normal_text) {
- link_text = rndr_newbuf(rndr, BUFFER_SPAN);
- rndr->cb.normal_text(link_text, link, rndr->cb.opaque);
- rndr->cb.link(ob, link_url, NULL, link_text, rndr->cb.opaque);
- rndr_popbuf(rndr, BUFFER_SPAN);
+ if (md->md.normal_text) {
+ link_text = newbuf(md, BUFFER_SPAN);
+ md->md.normal_text(link_text, link, md->md.opaque);
+ md->md.link(ob, link_url, NULL, link_text, md->md.opaque);
+ popbuf(md, BUFFER_SPAN);
} else {
- rndr->cb.link(ob, link_url, NULL, link, rndr->cb.opaque);
+ md->md.link(ob, link_url, NULL, link, md->md.opaque);
}
- rndr_popbuf(rndr, BUFFER_SPAN);
+ popbuf(md, BUFFER_SPAN);
}
- rndr_popbuf(rndr, BUFFER_SPAN);
+ popbuf(md, BUFFER_SPAN);
return link_len;
}
static size_t
-char_autolink_email(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t offset, size_t size)
+char_autolink_email(hoedown_buffer *ob, hoedown_markdown *md, uint8_t *data, size_t offset, size_t size)
{
hoedown_buffer *link;
size_t link_len, rewind;
- if (!rndr->cb.autolink || rndr->in_link_body)
+ if (!md->md.autolink || md->in_link_body)
return 0;
- link = rndr_newbuf(rndr, BUFFER_SPAN);
+ link = newbuf(md, BUFFER_SPAN);
if ((link_len = hoedown_autolink__email(&rewind, link, data, offset, size, 0)) > 0) {
ob->size -= rewind;
- rndr->cb.autolink(ob, link, HOEDOWN_AUTOLINK_EMAIL, rndr->cb.opaque);
+ md->md.autolink(ob, link, HOEDOWN_AUTOLINK_EMAIL, md->md.opaque);
}
- rndr_popbuf(rndr, BUFFER_SPAN);
+ popbuf(md, BUFFER_SPAN);
return link_len;
}
static size_t
-char_autolink_url(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t offset, size_t size)
+char_autolink_url(hoedown_buffer *ob, hoedown_markdown *md, uint8_t *data, size_t offset, size_t size)
{
hoedown_buffer *link;
size_t link_len, rewind;
- if (!rndr->cb.autolink || rndr->in_link_body)
+ if (!md->md.autolink || md->in_link_body)
return 0;
- link = rndr_newbuf(rndr, BUFFER_SPAN);
+ link = newbuf(md, BUFFER_SPAN);
if ((link_len = hoedown_autolink__url(&rewind, link, data, offset, size, 0)) > 0) {
ob->size -= rewind;
- rndr->cb.autolink(ob, link, HOEDOWN_AUTOLINK_NORMAL, rndr->cb.opaque);
+ md->md.autolink(ob, link, HOEDOWN_AUTOLINK_NORMAL, md->md.opaque);
}
- rndr_popbuf(rndr, BUFFER_SPAN);
+ popbuf(md, BUFFER_SPAN);
return link_len;
}
/* char_link • '[': parsing a link or an image */
static size_t
-char_link(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t offset, size_t size)
+char_link(hoedown_buffer *ob, hoedown_markdown *md, uint8_t *data, size_t offset, size_t size)
{
int is_img = (offset && data[-1] == '!'), level;
size_t i = 1, txt_e, link_b = 0, link_e = 0, title_b = 0, title_e = 0;
@@ -971,12 +971,12 @@ char_link(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t offs
hoedown_buffer *link = 0;
hoedown_buffer *title = 0;
hoedown_buffer *u_link = 0;
- size_t org_work_size = rndr->work_bufs[BUFFER_SPAN].size;
+ size_t org_work_size = md->work_bufs[BUFFER_SPAN].size;
int text_has_nl = 0, ret = 0;
int in_title = 0, qtype = 0;
/* checking whether the correct renderer exists */
- if ((is_img && !rndr->cb.image) || (!is_img && !rndr->cb.link))
+ if ((is_img && !md->md.image) || (!is_img && !md->md.link))
goto cleanup;
/* looking for the matching closing bracket */
@@ -1004,7 +1004,7 @@ char_link(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t offs
i++;
/* footnote link */
- if (rndr->ext_flags & HOEDOWN_EXT_FOOTNOTES && data[1] == '^') {
+ if (md->ext_flags & HOEDOWN_EXT_FOOTNOTES && data[1] == '^') {
hoedown_buffer id = { 0, 0, 0, 0 };
struct footnote_ref *fr;
@@ -1014,19 +1014,19 @@ char_link(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t offs
id.data = data + 2;
id.size = txt_e - 2;
- fr = find_footnote_ref(&rndr->footnotes_found, id.data, id.size);
+ fr = find_footnote_ref(&md->footnotes_found, id.data, id.size);
/* mark footnote used */
if (fr && !fr->is_used) {
- if(!add_footnote_ref(&rndr->footnotes_used, fr))
+ if(!add_footnote_ref(&md->footnotes_used, fr))
goto cleanup;
fr->is_used = 1;
- fr->num = rndr->footnotes_used.count;
+ fr->num = md->footnotes_used.count;
}
/* render */
- if (fr && rndr->cb.footnote_ref)
- ret = rndr->cb.footnote_ref(ob, fr->num, rndr->cb.opaque);
+ if (fr && md->md.footnote_ref)
+ ret = md->md.footnote_ref(ob, fr->num, md->md.opaque);
goto cleanup;
}
@@ -1105,12 +1105,12 @@ char_link(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t offs
/* building escaped link and title */
if (link_e > link_b) {
- link = rndr_newbuf(rndr, BUFFER_SPAN);
+ link = newbuf(md, BUFFER_SPAN);
hoedown_buffer_put(link, data + link_b, link_e - link_b);
}
if (title_e > title_b) {
- title = rndr_newbuf(rndr, BUFFER_SPAN);
+ title = newbuf(md, BUFFER_SPAN);
hoedown_buffer_put(title, data + title_b, title_e - title_b);
}
@@ -1132,7 +1132,7 @@ char_link(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t offs
/* finding the link_ref */
if (link_b == link_e) {
if (text_has_nl) {
- hoedown_buffer *b = rndr_newbuf(rndr, BUFFER_SPAN);
+ hoedown_buffer *b = newbuf(md, BUFFER_SPAN);
size_t j;
for (j = 1; j < txt_e; j++) {
@@ -1153,7 +1153,7 @@ char_link(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t offs
id.size = link_e - link_b;
}
- lr = find_link_ref(rndr->refs, id.data, id.size);
+ lr = find_link_ref(md->refs, id.data, id.size);
if (!lr)
goto cleanup;
@@ -1170,7 +1170,7 @@ char_link(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t offs
/* crafting the id */
if (text_has_nl) {
- hoedown_buffer *b = rndr_newbuf(rndr, BUFFER_SPAN);
+ hoedown_buffer *b = newbuf(md, BUFFER_SPAN);
size_t j;
for (j = 1; j < txt_e; j++) {
@@ -1188,7 +1188,7 @@ char_link(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t offs
}
/* finding the link_ref */
- lr = find_link_ref(rndr->refs, id.data, id.size);
+ lr = find_link_ref(md->refs, id.data, id.size);
if (!lr)
goto cleanup;
@@ -1202,20 +1202,20 @@ char_link(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t offs
/* building content: img alt is escaped, link content is parsed */
if (txt_e > 1) {
- content = rndr_newbuf(rndr, BUFFER_SPAN);
+ content = newbuf(md, BUFFER_SPAN);
if (is_img) {
hoedown_buffer_put(content, data + 1, txt_e - 1);
} else {
/* disable autolinking when parsing inline the
* content of a link */
- rndr->in_link_body = 1;
- parse_inline(content, rndr, data + 1, txt_e - 1);
- rndr->in_link_body = 0;
+ md->in_link_body = 1;
+ parse_inline(content, md, data + 1, txt_e - 1);
+ md->in_link_body = 0;
}
}
if (link) {
- u_link = rndr_newbuf(rndr, BUFFER_SPAN);
+ u_link = newbuf(md, BUFFER_SPAN);
unscape_text(u_link, link);
}
@@ -1224,24 +1224,24 @@ char_link(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t offs
if (ob->size && ob->data[ob->size - 1] == '!')
ob->size -= 1;
- ret = rndr->cb.image(ob, u_link, title, content, rndr->cb.opaque);
+ ret = md->md.image(ob, u_link, title, content, md->md.opaque);
} else {
- ret = rndr->cb.link(ob, u_link, title, content, rndr->cb.opaque);
+ ret = md->md.link(ob, u_link, title, content, md->md.opaque);
}
/* cleanup */
cleanup:
- rndr->work_bufs[BUFFER_SPAN].size = (int)org_work_size;
+ md->work_bufs[BUFFER_SPAN].size = (int)org_work_size;
return ret ? i : 0;
}
static size_t
-char_superscript(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t offset, size_t size)
+char_superscript(hoedown_buffer *ob, hoedown_markdown *md, uint8_t *data, size_t offset, size_t size)
{
size_t sup_start, sup_len;
hoedown_buffer *sup;
- if (!rndr->cb.superscript)
+ if (!md->md.superscript)
return 0;
if (size < 2)
@@ -1265,10 +1265,10 @@ char_superscript(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size
if (sup_len - sup_start == 0)
return (sup_start == 2) ? 3 : 0;
- sup = rndr_newbuf(rndr, BUFFER_SPAN);
- parse_inline(sup, rndr, data + sup_start, sup_len - sup_start);
- rndr->cb.superscript(ob, sup, rndr->cb.opaque);
- rndr_popbuf(rndr, BUFFER_SPAN);
+ sup = newbuf(md, BUFFER_SPAN);
+ parse_inline(sup, md, data + sup_start, sup_len - sup_start);
+ md->md.superscript(ob, sup, md->md.opaque);
+ popbuf(md, BUFFER_SPAN);
return (sup_start == 2) ? sup_len + 1 : sup_len;
}
@@ -1411,12 +1411,12 @@ is_codefence(uint8_t *data, size_t size, hoedown_buffer *syntax)
/* is_atxheader • returns whether the line is a hash-prefixed header */
static int
-is_atxheader(hoedown_markdown *rndr, uint8_t *data, size_t size)
+is_atxheader(hoedown_markdown *md, uint8_t *data, size_t size)
{
if (data[0] != '#')
return 0;
- if (rndr->ext_flags & HOEDOWN_EXT_SPACE_HEADERS) {
+ if (md->ext_flags & HOEDOWN_EXT_SPACE_HEADERS) {
size_t level = 0;
while (level < size && level < 6 && data[level] == '#')
@@ -1541,19 +1541,19 @@ prefix_uli(uint8_t *data, size_t size)
/* parse_block • parsing of one block, returning next uint8_t to parse */
-static void parse_block(hoedown_buffer *ob, hoedown_markdown *rndr,
+static void parse_block(hoedown_buffer *ob, hoedown_markdown *md,
uint8_t *data, size_t size);
/* parse_blockquote • handles parsing of a blockquote fragment */
static size_t
-parse_blockquote(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t size)
+parse_blockquote(hoedown_buffer *ob, hoedown_markdown *md, uint8_t *data, size_t size)
{
size_t beg, end = 0, pre, work_size = 0;
uint8_t *work_data = 0;
hoedown_buffer *out = 0;
- out = rndr_newbuf(rndr, BUFFER_BLOCK);
+ out = newbuf(md, BUFFER_BLOCK);
beg = 0;
while (beg < size) {
for (end = beg + 1; end < size && data[end - 1] != '\n'; end++);
@@ -1580,19 +1580,19 @@ parse_blockquote(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size
beg = end;
}
- parse_block(out, rndr, work_data, work_size);
- if (rndr->cb.blockquote)
- rndr->cb.blockquote(ob, out, rndr->cb.opaque);
- rndr_popbuf(rndr, BUFFER_BLOCK);
+ parse_block(out, md, work_data, work_size);
+ if (md->md.blockquote)
+ md->md.blockquote(ob, out, md->md.opaque);
+ popbuf(md, BUFFER_BLOCK);
return end;
}
static size_t
-parse_htmlblock(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t size, int do_render);
+parse_htmlblock(hoedown_buffer *ob, hoedown_markdown *md, uint8_t *data, size_t size, int do_render);
/* parse_blockquote • handles parsing of a regular paragraph */
static size_t
-parse_paragraph(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t size)
+parse_paragraph(hoedown_buffer *ob, hoedown_markdown *md, uint8_t *data, size_t size)
{
size_t i = 0, end = 0;
int level = 0;
@@ -1607,7 +1607,7 @@ parse_paragraph(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_
if ((level = is_headerline(data + i, size - i)) != 0)
break;
- if (is_atxheader(rndr, data + i, size - i) ||
+ if (is_atxheader(md, data + i, size - i) ||
is_hrule(data + i, size - i) ||
prefix_quote(data + i, size - i)) {
end = i;
@@ -1623,7 +1623,7 @@ parse_paragraph(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_
* let's check to see if there's some kind of block starting
* here
*/
- if ((rndr->ext_flags & HOEDOWN_EXT_LAX_SPACING) && !isalnum(data[i])) {
+ if ((md->ext_flags & HOEDOWN_EXT_LAX_SPACING) && !isalnum(data[i])) {
if (prefix_oli(data + i, size - i) ||
prefix_uli(data + i, size - i)) {
end = i;
@@ -1631,14 +1631,14 @@ parse_paragraph(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_
}
/* see if an html block starts here */
- if (data[i] == '<' && rndr->cb.blockhtml &&
- parse_htmlblock(ob, rndr, data + i, size - i, 0)) {
+ if (data[i] == '<' && md->md.blockhtml &&
+ parse_htmlblock(ob, md, data + i, size - i, 0)) {
end = i;
break;
}
/* see if a code fence starts here */
- if ((rndr->ext_flags & HOEDOWN_EXT_FENCED_CODE) != 0 &&
+ if ((md->ext_flags & HOEDOWN_EXT_FENCED_CODE) != 0 &&
is_codefence(data + i, size - i, NULL) != 0) {
end = i;
break;
@@ -1653,11 +1653,11 @@ parse_paragraph(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_
work.size--;
if (!level) {
- hoedown_buffer *tmp = rndr_newbuf(rndr, BUFFER_BLOCK);
- parse_inline(tmp, rndr, work.data, work.size);
- if (rndr->cb.paragraph)
- rndr->cb.paragraph(ob, tmp, rndr->cb.opaque);
- rndr_popbuf(rndr, BUFFER_BLOCK);
+ hoedown_buffer *tmp = newbuf(md, BUFFER_BLOCK);
+ parse_inline(tmp, md, work.data, work.size);
+ if (md->md.paragraph)
+ md->md.paragraph(ob, tmp, md->md.opaque);
+ popbuf(md, BUFFER_BLOCK);
} else {
hoedown_buffer *header_work;
@@ -1674,26 +1674,26 @@ parse_paragraph(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_
work.size -= 1;
if (work.size > 0) {
- hoedown_buffer *tmp = rndr_newbuf(rndr, BUFFER_BLOCK);
- parse_inline(tmp, rndr, work.data, work.size);
+ hoedown_buffer *tmp = newbuf(md, BUFFER_BLOCK);
+ parse_inline(tmp, md, work.data, work.size);
- if (rndr->cb.paragraph)
- rndr->cb.paragraph(ob, tmp, rndr->cb.opaque);
+ if (md->md.paragraph)
+ md->md.paragraph(ob, tmp, md->md.opaque);
- rndr_popbuf(rndr, BUFFER_BLOCK);
+ popbuf(md, BUFFER_BLOCK);
work.data += beg;
work.size = i - beg;
}
else work.size = i;
}
- header_work = rndr_newbuf(rndr, BUFFER_SPAN);
- parse_inline(header_work, rndr, work.data, work.size);
+ header_work = newbuf(md, BUFFER_SPAN);
+ parse_inline(header_work, md, work.data, work.size);
- if (rndr->cb.header)
- rndr->cb.header(ob, header_work, (int)level, rndr->cb.opaque);
+ if (md->md.header)
+ md->md.header(ob, header_work, (int)level, md->md.opaque);
- rndr_popbuf(rndr, BUFFER_SPAN);
+ popbuf(md, BUFFER_SPAN);
}
return end;
@@ -1701,7 +1701,7 @@ parse_paragraph(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_
/* parse_fencedcode • handles parsing of a block-level code fragment */
static size_t
-parse_fencedcode(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t size)
+parse_fencedcode(hoedown_buffer *ob, hoedown_markdown *md, uint8_t *data, size_t size)
{
size_t beg, end;
hoedown_buffer *work = 0;
@@ -1710,7 +1710,7 @@ parse_fencedcode(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size
beg = is_codefence(data, size, &lang);
if (beg == 0) return 0;
- work = rndr_newbuf(rndr, BUFFER_BLOCK);
+ work = newbuf(md, BUFFER_BLOCK);
while (beg < size) {
size_t fence_end;
@@ -1737,20 +1737,20 @@ parse_fencedcode(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size
if (work->size && work->data[work->size - 1] != '\n')
hoedown_buffer_putc(work, '\n');
- if (rndr->cb.blockcode)
- rndr->cb.blockcode(ob, work, lang.size ? &lang : NULL, rndr->cb.opaque);
+ if (md->md.blockcode)
+ md->md.blockcode(ob, work, lang.size ? &lang : NULL, md->md.opaque);
- rndr_popbuf(rndr, BUFFER_BLOCK);
+ popbuf(md, BUFFER_BLOCK);
return beg;
}
static size_t
-parse_blockcode(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t size)
+parse_blockcode(hoedown_buffer *ob, hoedown_markdown *md, uint8_t *data, size_t size)
{
size_t beg, end, pre;
hoedown_buffer *work = 0;
- work = rndr_newbuf(rndr, BUFFER_BLOCK);
+ work = newbuf(md, BUFFER_BLOCK);
beg = 0;
while (beg < size) {
@@ -1778,17 +1778,17 @@ parse_blockcode(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_
hoedown_buffer_putc(work, '\n');
- if (rndr->cb.blockcode)
- rndr->cb.blockcode(ob, work, NULL, rndr->cb.opaque);
+ if (md->md.blockcode)
+ md->md.blockcode(ob, work, NULL, md->md.opaque);
- rndr_popbuf(rndr, BUFFER_BLOCK);
+ popbuf(md, BUFFER_BLOCK);
return beg;
}
/* parse_listitem • parsing of a single list item */
/* assuming initial prefix is already removed */
static size_t
-parse_listitem(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t size, int *flags)
+parse_listitem(hoedown_buffer *ob, hoedown_markdown *md, uint8_t *data, size_t size, int *flags)
{
hoedown_buffer *work = 0, *inter = 0;
size_t beg = 0, end, pre, sublist = 0, orgpre = 0, i;
@@ -1811,8 +1811,8 @@ parse_listitem(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t
end++;
/* getting working buffers */
- work = rndr_newbuf(rndr, BUFFER_SPAN);
- inter = rndr_newbuf(rndr, BUFFER_SPAN);
+ work = newbuf(md, BUFFER_SPAN);
+ inter = newbuf(md, BUFFER_SPAN);
/* putting the first line into the working buffer */
hoedown_buffer_put(work, data + beg, end - beg);
@@ -1841,7 +1841,7 @@ parse_listitem(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t
pre = i;
- if (rndr->ext_flags & HOEDOWN_EXT_FENCED_CODE) {
+ if (md->ext_flags & HOEDOWN_EXT_FENCED_CODE) {
if (is_codefence(data + beg + i, end - beg - i, NULL) != 0)
in_fence = !in_fence;
}
@@ -1898,57 +1898,57 @@ parse_listitem(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t
if (*flags & HOEDOWN_LI_BLOCK) {
/* intermediate render of block li */
if (sublist && sublist < work->size) {
- parse_block(inter, rndr, work->data, sublist);
- parse_block(inter, rndr, work->data + sublist, work->size - sublist);
+ parse_block(inter, md, work->data, sublist);
+ parse_block(inter, md, work->data + sublist, work->size - sublist);
}
else
- parse_block(inter, rndr, work->data, work->size);
+ parse_block(inter, md, work->data, work->size);
} else {
/* intermediate render of inline li */
if (sublist && sublist < work->size) {
- parse_inline(inter, rndr, work->data, sublist);
- parse_block(inter, rndr, work->data + sublist, work->size - sublist);
+ parse_inline(inter, md, work->data, sublist);
+ parse_block(inter, md, work->data + sublist, work->size - sublist);
}
else
- parse_inline(inter, rndr, work->data, work->size);
+ parse_inline(inter, md, work->data, work->size);
}
/* render of li itself */
- if (rndr->cb.listitem)
- rndr->cb.listitem(ob, inter, *flags, rndr->cb.opaque);
+ if (md->md.listitem)
+ md->md.listitem(ob, inter, *flags, md->md.opaque);
- rndr_popbuf(rndr, BUFFER_SPAN);
- rndr_popbuf(rndr, BUFFER_SPAN);
+ popbuf(md, BUFFER_SPAN);
+ popbuf(md, BUFFER_SPAN);
return beg;
}
/* parse_list • parsing ordered or unordered list block */
static size_t
-parse_list(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t size, int flags)
+parse_list(hoedown_buffer *ob, hoedown_markdown *md, uint8_t *data, size_t size, int flags)
{
hoedown_buffer *work = 0;
size_t i = 0, j;
- work = rndr_newbuf(rndr, BUFFER_BLOCK);
+ work = newbuf(md, BUFFER_BLOCK);
while (i < size) {
- j = parse_listitem(work, rndr, data + i, size - i, &flags);
+ j = parse_listitem(work, md, data + i, size - i, &flags);
i += j;
if (!j || (flags & HOEDOWN_LI_END))
break;
}
- if (rndr->cb.list)
- rndr->cb.list(ob, work, flags, rndr->cb.opaque);
- rndr_popbuf(rndr, BUFFER_BLOCK);
+ if (md->md.list)
+ md->md.list(ob, work, flags, md->md.opaque);
+ popbuf(md, BUFFER_BLOCK);
return i;
}
/* parse_atxheader • parsing of atx-style headers */
static size_t
-parse_atxheader(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t size)
+parse_atxheader(hoedown_buffer *ob, hoedown_markdown *md, uint8_t *data, size_t size)
{
size_t level = 0;
size_t i, end, skip;
@@ -1968,14 +1968,14 @@ parse_atxheader(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_
end--;
if (end > i) {
- hoedown_buffer *work = rndr_newbuf(rndr, BUFFER_SPAN);
+ hoedown_buffer *work = newbuf(md, BUFFER_SPAN);
- parse_inline(work, rndr, data + i, end - i);
+ parse_inline(work, md, data + i, end - i);
- if (rndr->cb.header)
- rndr->cb.header(ob, work, (int)level, rndr->cb.opaque);
+ if (md->md.header)
+ md->md.header(ob, work, (int)level, md->md.opaque);
- rndr_popbuf(rndr, BUFFER_SPAN);
+ popbuf(md, BUFFER_SPAN);
}
return skip;
@@ -1983,21 +1983,21 @@ parse_atxheader(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_
/* parse_footnote_def • parse a single footnote definition */
static void
-parse_footnote_def(hoedown_buffer *ob, hoedown_markdown *rndr, unsigned int num, uint8_t *data, size_t size)
+parse_footnote_def(hoedown_buffer *ob, hoedown_markdown *md, unsigned int num, uint8_t *data, size_t size)
{
hoedown_buffer *work = 0;
- work = rndr_newbuf(rndr, BUFFER_SPAN);
+ work = newbuf(md, BUFFER_SPAN);
- parse_block(work, rndr, data, size);
+ parse_block(work, md, data, size);
- if (rndr->cb.footnote_def)
- rndr->cb.footnote_def(ob, work, num, rndr->cb.opaque);
- rndr_popbuf(rndr, BUFFER_SPAN);
+ if (md->md.footnote_def)
+ md->md.footnote_def(ob, work, num, md->md.opaque);
+ popbuf(md, BUFFER_SPAN);
}
/* parse_footnote_list • render the contents of the footnotes */
static void
-parse_footnote_list(hoedown_buffer *ob, hoedown_markdown *rndr, struct footnote_list *footnotes)
+parse_footnote_list(hoedown_buffer *ob, hoedown_markdown *md, struct footnote_list *footnotes)
{
hoedown_buffer *work = 0;
struct footnote_item *item;
@@ -2006,18 +2006,18 @@ parse_footnote_list(hoedown_buffer *ob, hoedown_markdown *rndr, struct footnote_
if (footnotes->count == 0)
return;
- work = rndr_newbuf(rndr, BUFFER_BLOCK);
+ work = newbuf(md, BUFFER_BLOCK);
item = footnotes->head;
while (item) {
ref = item->ref;
- parse_footnote_def(work, rndr, ref->num, ref->contents->data, ref->contents->size);
+ parse_footnote_def(work, md, ref->num, ref->contents->data, ref->contents->size);
item = item->next;
}
- if (rndr->cb.footnotes)
- rndr->cb.footnotes(ob, work, rndr->cb.opaque);
- rndr_popbuf(rndr, BUFFER_BLOCK);
+ if (md->md.footnotes)
+ md->md.footnotes(ob, work, md->md.opaque);
+ popbuf(md, BUFFER_BLOCK);
}
/* htmlblock_end • checking end of HTML block : [ \t]*\n[ \t*]\n */
@@ -2026,7 +2026,7 @@ static size_t
htmlblock_end_tag(
const char *tag,
size_t tag_len,
- hoedown_markdown *rndr,
+ hoedown_markdown *md,
uint8_t *data,
size_t size)
{
@@ -2054,7 +2054,7 @@ htmlblock_end_tag(
static size_t
htmlblock_end(const char *curtag,
- hoedown_markdown *rndr,
+ hoedown_markdown *md,
uint8_t *data,
size_t size,
int start_of_line)
@@ -2085,7 +2085,7 @@ htmlblock_end(const char *curtag,
if (i + 2 + tag_size >= size)
break;
- end_tag = htmlblock_end_tag(curtag, tag_size, rndr, data + i - 1, size - i + 1);
+ end_tag = htmlblock_end_tag(curtag, tag_size, md, data + i - 1, size - i + 1);
if (end_tag)
return i + end_tag - 1;
}
@@ -2096,7 +2096,7 @@ htmlblock_end(const char *curtag,
/* parse_htmlblock • parsing of inline HTML block */
static size_t
-parse_htmlblock(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t size, int do_render)
+parse_htmlblock(hoedown_buffer *ob, hoedown_markdown *md, uint8_t *data, size_t size, int do_render)
{
size_t i, j = 0, tag_end;
const char *curtag = NULL;
@@ -2130,8 +2130,8 @@ parse_htmlblock(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_
if (j) {
work.size = i + j;
- if (do_render && rndr->cb.blockhtml)
- rndr->cb.blockhtml(ob, &work, rndr->cb.opaque);
+ if (do_render && md->md.blockhtml)
+ md->md.blockhtml(ob, &work, md->md.opaque);
return work.size;
}
}
@@ -2147,8 +2147,8 @@ parse_htmlblock(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_
j = is_empty(data + i, size - i);
if (j) {
work.size = i + j;
- if (do_render && rndr->cb.blockhtml)
- rndr->cb.blockhtml(ob, &work, rndr->cb.opaque);
+ if (do_render && md->md.blockhtml)
+ md->md.blockhtml(ob, &work, md->md.opaque);
return work.size;
}
}
@@ -2160,12 +2160,12 @@ parse_htmlblock(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_
/* looking for an unindented matching closing tag */
/* followed by a blank line */
- tag_end = htmlblock_end(curtag, rndr, data, size, 1);
+ tag_end = htmlblock_end(curtag, md, data, size, 1);
/* if not found, trying a second pass looking for indented match */
/* but not if tag is "ins" or "del" (following original Markdown.pl) */
if (!tag_end && strcmp(curtag, "ins") != 0 && strcmp(curtag, "del") != 0) {
- tag_end = htmlblock_end(curtag, rndr, data, size, 0);
+ tag_end = htmlblock_end(curtag, md, data, size, 0);
}
if (!tag_end)
@@ -2173,8 +2173,8 @@ parse_htmlblock(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_
/* the end of the block has been found */
work.size = tag_end;
- if (do_render && rndr->cb.blockhtml)
- rndr->cb.blockhtml(ob, &work, rndr->cb.opaque);
+ if (do_render && md->md.blockhtml)
+ md->md.blockhtml(ob, &work, md->md.opaque);
return tag_end;
}
@@ -2182,7 +2182,7 @@ parse_htmlblock(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_
static void
parse_table_row(
hoedown_buffer *ob,
- hoedown_markdown *rndr,
+ hoedown_markdown *md,
uint8_t *data,
size_t size,
size_t columns,
@@ -2192,10 +2192,10 @@ parse_table_row(
size_t i = 0, col;
hoedown_buffer *row_work = 0;
- if (!rndr->cb.table_cell || !rndr->cb.table_row)
+ if (!md->md.table_cell || !md->md.table_row)
return;
- row_work = rndr_newbuf(rndr, BUFFER_SPAN);
+ row_work = newbuf(md, BUFFER_SPAN);
if (i < size && data[i] == '|')
i++;
@@ -2204,7 +2204,7 @@ parse_table_row(
size_t cell_start, cell_end;
hoedown_buffer *cell_work;
- cell_work = rndr_newbuf(rndr, BUFFER_SPAN);
+ cell_work = newbuf(md, BUFFER_SPAN);
while (i < size && _isspace(data[i]))
i++;
@@ -2219,27 +2219,27 @@ parse_table_row(
while (cell_end > cell_start && _isspace(data[cell_end]))
cell_end--;
- parse_inline(cell_work, rndr, data + cell_start, 1 + cell_end - cell_start);
- rndr->cb.table_cell(row_work, cell_work, col_data[col] | header_flag, rndr->cb.opaque);
+ parse_inline(cell_work, md, data + cell_start, 1 + cell_end - cell_start);
+ md->md.table_cell(row_work, cell_work, col_data[col] | header_flag, md->md.opaque);
- rndr_popbuf(rndr, BUFFER_SPAN);
+ popbuf(md, BUFFER_SPAN);
i++;
}
for (; col < columns; ++col) {
hoedown_buffer empty_cell = { 0, 0, 0, 0 };
- rndr->cb.table_cell(row_work, &empty_cell, col_data[col] | header_flag, rndr->cb.opaque);
+ md->md.table_cell(row_work, &empty_cell, col_data[col] | header_flag, md->md.opaque);
}
- rndr->cb.table_row(ob, row_work, rndr->cb.opaque);
+ md->md.table_row(ob, row_work, md->md.opaque);
- rndr_popbuf(rndr, BUFFER_SPAN);
+ popbuf(md, BUFFER_SPAN);
}
static size_t
parse_table_header(
hoedown_buffer *ob,
- hoedown_markdown *rndr,
+ hoedown_markdown *md,
uint8_t *data,
size_t size,
size_t *columns,
@@ -2318,7 +2318,7 @@ parse_table_header(
return 0;
parse_table_row(
- ob, rndr, data,
+ ob, md, data,
header_end,
*columns,
*column_data,
@@ -2331,7 +2331,7 @@ parse_table_header(
static size_t
parse_table(
hoedown_buffer *ob,
- hoedown_markdown *rndr,
+ hoedown_markdown *md,
uint8_t *data,
size_t size)
{
@@ -2343,10 +2343,10 @@ parse_table(
size_t columns;
int *col_data = NULL;
- header_work = rndr_newbuf(rndr, BUFFER_SPAN);
- body_work = rndr_newbuf(rndr, BUFFER_BLOCK);
+ header_work = newbuf(md, BUFFER_SPAN);
+ body_work = newbuf(md, BUFFER_BLOCK);
- i = parse_table_header(header_work, rndr, data, size, &columns, &col_data);
+ i = parse_table_header(header_work, md, data, size, &columns, &col_data);
if (i > 0) {
while (i < size) {
@@ -2366,7 +2366,7 @@ parse_table(
parse_table_row(
body_work,
- rndr,
+ md,
data + row_start,
i - row_start,
columns,
@@ -2376,45 +2376,45 @@ parse_table(
i++;
}
- if (rndr->cb.table)
- rndr->cb.table(ob, header_work, body_work, rndr->cb.opaque);
+ if (md->md.table)
+ md->md.table(ob, header_work, body_work, md->md.opaque);
}
free(col_data);
- rndr_popbuf(rndr, BUFFER_SPAN);
- rndr_popbuf(rndr, BUFFER_BLOCK);
+ popbuf(md, BUFFER_SPAN);
+ popbuf(md, BUFFER_BLOCK);
return i;
}
/* parse_block • parsing of one block, returning next uint8_t to parse */
static void
-parse_block(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t size)
+parse_block(hoedown_buffer *ob, hoedown_markdown *md, uint8_t *data, size_t size)
{
size_t beg, end, i;
uint8_t *txt_data;
beg = 0;
- if (rndr->work_bufs[BUFFER_SPAN].size +
- rndr->work_bufs[BUFFER_BLOCK].size > rndr->max_nesting)
+ if (md->work_bufs[BUFFER_SPAN].size +
+ md->work_bufs[BUFFER_BLOCK].size > md->max_nesting)
return;
while (beg < size) {
txt_data = data + beg;
end = size - beg;
- if (is_atxheader(rndr, txt_data, end))
- beg += parse_atxheader(ob, rndr, txt_data, end);
+ if (is_atxheader(md, txt_data, end))
+ beg += parse_atxheader(ob, md, txt_data, end);
- else if (data[beg] == '<' && rndr->cb.blockhtml &&
- (i = parse_htmlblock(ob, rndr, txt_data, end, 1)) != 0)
+ else if (data[beg] == '<' && md->md.blockhtml &&
+ (i = parse_htmlblock(ob, md, txt_data, end, 1)) != 0)
beg += i;
else if ((i = is_empty(txt_data, end)) != 0)
beg += i;
else if (is_hrule(txt_data, end)) {
- if (rndr->cb.hrule)
- rndr->cb.hrule(ob, rndr->cb.opaque);
+ if (md->md.hrule)
+ md->md.hrule(ob, md->md.opaque);
while (beg < size && data[beg] != '\n')
beg++;
@@ -2422,28 +2422,28 @@ parse_block(hoedown_buffer *ob, hoedown_markdown *rndr, uint8_t *data, size_t si
beg++;
}
- else if ((rndr->ext_flags & HOEDOWN_EXT_FENCED_CODE) != 0 &&
- (i = parse_fencedcode(ob, rndr, txt_data, end)) != 0)
+ else if ((md->ext_flags & HOEDOWN_EXT_FENCED_CODE) != 0 &&
+ (i = parse_fencedcode(ob, md, txt_data, end)) != 0)
beg += i;
- else if ((rndr->ext_flags & HOEDOWN_EXT_TABLES) != 0 &&
- (i = parse_table(ob, rndr, txt_data, end)) != 0)
+ else if ((md->ext_flags & HOEDOWN_EXT_TABLES) != 0 &&
+ (i = parse_table(ob, md, txt_data, end)) != 0)
beg += i;
else if (prefix_quote(txt_data, end))
- beg += parse_blockquote(ob, rndr, txt_data, end);
+ beg += parse_blockquote(ob, md, txt_data, end);
- else if (!(rndr->ext_flags & HOEDOWN_EXT_DISABLE_INDENTED_CODE) && prefix_code(txt_data, end))
- beg += parse_blockcode(ob, rndr, txt_data, end);
+ else if (!(md->ext_flags & HOEDOWN_EXT_DISABLE_INDENTED_CODE) && prefix_code(txt_data, end))
+ beg += parse_blockcode(ob, md, txt_data, end);
else if (prefix_uli(txt_data, end))
- beg += parse_list(ob, rndr, txt_data, end, 0);
+ beg += parse_list(ob, md, txt_data, end, 0);
else if (prefix_oli(txt_data, end))
- beg += parse_list(ob, rndr, txt_data, end, HOEDOWN_LIST_ORDERED);
+ beg += parse_list(ob, md, txt_data, end, HOEDOWN_LIST_ORDERED);
else
- beg += parse_paragraph(ob, rndr, txt_data, end);
+ beg += parse_paragraph(ob, md, txt_data, end);
}
}
@@ -2705,24 +2705,24 @@ hoedown_markdown *
hoedown_markdown_new(
unsigned int extensions,
size_t max_nesting,
- const hoedown_renderer *callbacks)
+ const hoedown_renderer *renderer)
{
hoedown_markdown *md = NULL;
- assert(max_nesting > 0 && callbacks);
+ assert(max_nesting > 0 && renderer);
md = malloc(sizeof(hoedown_markdown));
if (!md)
return NULL;
- memcpy(&md->cb, callbacks, sizeof(hoedown_renderer));
+ memcpy(&md->md, renderer, sizeof(hoedown_renderer));
hoedown_stack_new(&md->work_bufs[BUFFER_BLOCK], 4);
hoedown_stack_new(&md->work_bufs[BUFFER_SPAN], 8);
memset(md->active_char, 0x0, 256);
- if (md->cb.emphasis || md->cb.double_emphasis || md->cb.triple_emphasis) {
+ if (md->md.emphasis || md->md.double_emphasis || md->md.triple_emphasis) {
md->active_char['*'] = MD_CHAR_EMPHASIS;
md->active_char['_'] = MD_CHAR_EMPHASIS;
if (extensions & HOEDOWN_EXT_STRIKETHROUGH)
@@ -2731,13 +2731,13 @@ hoedown_markdown_new(
md->active_char['='] = MD_CHAR_EMPHASIS;
}
- if (md->cb.codespan)
+ if (md->md.codespan)
md->active_char['`'] = MD_CHAR_CODESPAN;
- if (md->cb.linebreak)
+ if (md->md.linebreak)
md->active_char['\n'] = MD_CHAR_LINEBREAK;
- if (md->cb.image || md->cb.link)
+ if (md->md.image || md->md.link)
md->active_char['['] = MD_CHAR_LINK;
md->active_char['<'] = MD_CHAR_LANGLE;
@@ -2828,8 +2828,8 @@ hoedown_markdown_render(hoedown_buffer *ob, const uint8_t *document, size_t doc_
hoedown_buffer_grow(ob, text->size + (text->size >> 1));
/* second pass: actual rendering */
- if (md->cb.doc_header)
- md->cb.doc_header(ob, md->cb.opaque);
+ if (md->md.doc_header)
+ md->md.doc_header(ob, md->md.opaque);
if (text->size) {
/* adding a final newline if not already present */
@@ -2843,8 +2843,8 @@ hoedown_markdown_render(hoedown_buffer *ob, const uint8_t *document, size_t doc_
if (footnotes_enabled)
parse_footnote_list(ob, md, &md->footnotes_used);
- if (md->cb.doc_footer)
- md->cb.doc_footer(ob, md->cb.opaque);
+ if (md->md.doc_footer)
+ md->md.doc_footer(ob, md->md.opaque);
/* clean-up */
hoedown_buffer_free(text);
diff --git a/src/markdown.h b/src/markdown.h
index 0f58e8f..7a2ae53 100644
--- a/src/markdown.h
+++ b/src/markdown.h
@@ -92,7 +92,7 @@ struct hoedown_renderer {
void (*doc_header)(hoedown_buffer *ob, void *opaque);
void (*doc_footer)(hoedown_buffer *ob, void *opaque);
- /* cookie */
+ /* state object */
void *opaque;
};
@@ -118,7 +118,7 @@ extern hoedown_markdown *
hoedown_markdown_new(
unsigned int extensions,
size_t max_nesting,
- const hoedown_renderer *callbacks);
+ const hoedown_renderer *renderer);
extern void
hoedown_markdown_render(hoedown_buffer *ob, const uint8_t *document, size_t doc_size, hoedown_markdown *md);