More fixes

This commit is contained in:
Xavier Mendez 2014-09-03 10:39:33 +02:00
parent a6b90a7cf7
commit 73d8a1120a
8 changed files with 47 additions and 45 deletions

View file

@ -4,30 +4,36 @@ EXPORTS
hoedown_autolink__www hoedown_autolink__www
hoedown_autolink__email hoedown_autolink__email
hoedown_autolink__url hoedown_autolink__url
hoedown_buffer_grow hoedown_buffer_init
hoedown_buffer_new hoedown_buffer_new
hoedown_buffer_cstr hoedown_buffer_reset
hoedown_buffer_prefix hoedown_buffer_grow
hoedown_buffer_put hoedown_buffer_put
hoedown_buffer_puts hoedown_buffer_puts
hoedown_buffer_putc hoedown_buffer_putc
hoedown_buffer_free hoedown_buffer_set
hoedown_buffer_reset hoedown_buffer_sets
hoedown_buffer_eq
hoedown_buffer_eqs
hoedown_buffer_prefix
hoedown_buffer_slurp hoedown_buffer_slurp
hoedown_buffer_cstr
hoedown_buffer_printf hoedown_buffer_printf
hoedown_buffer_free
hoedown_document_new hoedown_document_new
hoedown_document_render hoedown_document_render
hoedown_document_render_inline
hoedown_document_free hoedown_document_free
hoedown_escape_html
hoedown_escape_href hoedown_escape_href
hoedown_escape_html
hoedown_html_smartypants
hoedown_html_is_tag hoedown_html_is_tag
hoedown_html_renderer_new hoedown_html_renderer_new
hoedown_html_toc_renderer_new hoedown_html_toc_renderer_new
hoedown_html_renderer_free hoedown_html_renderer_free
hoedown_html_smartypants hoedown_stack_init
hoedown_stack_free hoedown_stack_uninit
hoedown_stack_grow hoedown_stack_grow
hoedown_stack_new
hoedown_stack_push hoedown_stack_push
hoedown_stack_pop hoedown_stack_pop
hoedown_stack_top hoedown_stack_top

View file

@ -1736,7 +1736,7 @@ parse_blockcode(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t
/* parse_listitem • parsing of a single list item */ /* parse_listitem • parsing of a single list item */
/* assuming initial prefix is already removed */ /* assuming initial prefix is already removed */
static size_t static size_t
parse_listitem(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t size, hoedown_listflags *flags) parse_listitem(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t size, hoedown_list_flags *flags)
{ {
hoedown_buffer *work = 0, *inter = 0; hoedown_buffer *work = 0, *inter = 0;
size_t beg = 0, end, pre, sublist = 0, orgpre = 0, i; size_t beg = 0, end, pre, sublist = 0, orgpre = 0, i;
@ -1873,7 +1873,7 @@ parse_listitem(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t
/* parse_list • parsing ordered or unordered list block */ /* parse_list • parsing ordered or unordered list block */
static size_t static size_t
parse_list(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t size, hoedown_listflags flags) parse_list(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t size, hoedown_list_flags flags)
{ {
hoedown_buffer *work = 0; hoedown_buffer *work = 0;
size_t i = 0, j; size_t i = 0, j;
@ -2136,8 +2136,8 @@ parse_table_row(
uint8_t *data, uint8_t *data,
size_t size, size_t size,
size_t columns, size_t columns,
hoedown_tableflags *col_data, hoedown_table_flags *col_data,
hoedown_tableflags header_flag) hoedown_table_flags header_flag)
{ {
size_t i = 0, col; size_t i = 0, col;
hoedown_buffer *row_work = 0; hoedown_buffer *row_work = 0;
@ -2193,7 +2193,7 @@ parse_table_header(
uint8_t *data, uint8_t *data,
size_t size, size_t size,
size_t *columns, size_t *columns,
hoedown_tableflags **column_data) hoedown_table_flags **column_data)
{ {
int pipes; int pipes;
size_t i = 0, col, header_end, under_end; size_t i = 0, col, header_end, under_end;
@ -2221,7 +2221,7 @@ parse_table_header(
return 0; return 0;
*columns = pipes + 1; *columns = pipes + 1;
*column_data = hoedown_calloc(*columns, sizeof(hoedown_tableflags)); *column_data = hoedown_calloc(*columns, sizeof(hoedown_table_flags));
/* Parse the header underline */ /* Parse the header underline */
i++; i++;
@ -2291,7 +2291,7 @@ parse_table(
hoedown_buffer *body_work = 0; hoedown_buffer *body_work = 0;
size_t columns; size_t columns;
hoedown_tableflags *col_data = NULL; hoedown_table_flags *col_data = NULL;
header_work = newbuf(doc, BUFFER_SPAN); header_work = newbuf(doc, BUFFER_SPAN);
body_work = newbuf(doc, BUFFER_BLOCK); body_work = newbuf(doc, BUFFER_BLOCK);
@ -2854,8 +2854,8 @@ hoedown_document_free(hoedown_document *doc)
for (i = 0; i < (size_t)doc->work_bufs[BUFFER_BLOCK].asize; ++i) for (i = 0; i < (size_t)doc->work_bufs[BUFFER_BLOCK].asize; ++i)
hoedown_buffer_free(doc->work_bufs[BUFFER_BLOCK].item[i]); hoedown_buffer_free(doc->work_bufs[BUFFER_BLOCK].item[i]);
hoedown_stack_reset(&doc->work_bufs[BUFFER_SPAN]); hoedown_stack_uninit(&doc->work_bufs[BUFFER_SPAN]);
hoedown_stack_reset(&doc->work_bufs[BUFFER_BLOCK]); hoedown_stack_uninit(&doc->work_bufs[BUFFER_BLOCK]);
free(doc); free(doc);
} }

View file

@ -59,18 +59,18 @@ typedef enum hoedown_extensions {
#define HOEDOWN_EXT_NEGATIVE (\ #define HOEDOWN_EXT_NEGATIVE (\
HOEDOWN_EXT_DISABLE_INDENTED_CODE ) HOEDOWN_EXT_DISABLE_INDENTED_CODE )
typedef enum hoedown_listflags { typedef enum hoedown_list_flags {
HOEDOWN_LIST_ORDERED = (1 << 0), HOEDOWN_LIST_ORDERED = (1 << 0),
HOEDOWN_LI_BLOCK = (1 << 1) /* <li> containing block data */ HOEDOWN_LI_BLOCK = (1 << 1) /* <li> containing block data */
} hoedown_listflags; } hoedown_list_flags;
typedef enum hoedown_tableflags { typedef enum hoedown_table_flags {
HOEDOWN_TABLE_ALIGN_LEFT = 1, HOEDOWN_TABLE_ALIGN_LEFT = 1,
HOEDOWN_TABLE_ALIGN_RIGHT = 2, HOEDOWN_TABLE_ALIGN_RIGHT = 2,
HOEDOWN_TABLE_ALIGN_CENTER = 3, HOEDOWN_TABLE_ALIGN_CENTER = 3,
HOEDOWN_TABLE_ALIGNMASK = 3, HOEDOWN_TABLE_ALIGNMASK = 3,
HOEDOWN_TABLE_HEADER = 4 HOEDOWN_TABLE_HEADER = 4
} hoedown_tableflags; } hoedown_table_flags;
typedef enum hoedown_autolink_type { typedef enum hoedown_autolink_type {
HOEDOWN_AUTOLINK_NONE, /* used internally when it is not an autolink*/ HOEDOWN_AUTOLINK_NONE, /* used internally when it is not an autolink*/
@ -94,12 +94,12 @@ struct hoedown_renderer {
void (*blockhtml)(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 (*header)(hoedown_buffer *ob, const hoedown_buffer *text, int level, void *opaque);
void (*hrule)(hoedown_buffer *ob, void *opaque); void (*hrule)(hoedown_buffer *ob, void *opaque);
void (*list)(hoedown_buffer *ob, const hoedown_buffer *text, hoedown_listflags flags, void *opaque); void (*list)(hoedown_buffer *ob, const hoedown_buffer *text, hoedown_list_flags flags, void *opaque);
void (*listitem)(hoedown_buffer *ob, const hoedown_buffer *text, hoedown_listflags flags, void *opaque); void (*listitem)(hoedown_buffer *ob, const hoedown_buffer *text, hoedown_list_flags flags, void *opaque);
void (*paragraph)(hoedown_buffer *ob, const hoedown_buffer *text, void *opaque); 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)(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); void (*table_row)(hoedown_buffer *ob, const hoedown_buffer *text, void *opaque);
void (*table_cell)(hoedown_buffer *ob, const hoedown_buffer *text, hoedown_tableflags flags, void *opaque); void (*table_cell)(hoedown_buffer *ob, const hoedown_buffer *text, hoedown_table_flags flags, void *opaque);
void (*footnotes)(hoedown_buffer *ob, const hoedown_buffer *text, void *opaque); 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); void (*footnote_def)(hoedown_buffer *ob, const hoedown_buffer *text, unsigned int num, void *opaque);

View file

@ -64,16 +64,15 @@ hoedown_escape_href(hoedown_buffer *ob, const uint8_t *data, size_t size)
while (i < size) { while (i < size) {
mark = i; mark = i;
while (i < size && HREF_SAFE[data[i]] != 0) while (i < size && HREF_SAFE[data[i]]) i++;
i++;
/* Optimization for cases when there's nothing to escape */ /* Optimization for cases where there's nothing to escape */
if (mark == 0 && i >= size) { if (mark == 0 && i >= size) {
hoedown_buffer_put(ob, data, size); hoedown_buffer_put(ob, data, size);
return; return;
} }
if (i > mark) { if (likely(i > mark)) {
hoedown_buffer_put(ob, data + mark, i - mark); hoedown_buffer_put(ob, data + mark, i - mark);
} }

View file

@ -265,7 +265,7 @@ rndr_link(hoedown_buffer *ob, const hoedown_buffer *link, const hoedown_buffer *
} }
static void static void
rndr_list(hoedown_buffer *ob, const hoedown_buffer *text, unsigned int flags, void *opaque) rndr_list(hoedown_buffer *ob, const hoedown_buffer *text, hoedown_list_flags flags, void *opaque)
{ {
if (ob->size) hoedown_buffer_putc(ob, '\n'); if (ob->size) hoedown_buffer_putc(ob, '\n');
hoedown_buffer_put(ob, (uint8_t *)(flags & HOEDOWN_LIST_ORDERED ? "<ol>\n" : "<ul>\n"), 5); hoedown_buffer_put(ob, (uint8_t *)(flags & HOEDOWN_LIST_ORDERED ? "<ol>\n" : "<ul>\n"), 5);
@ -274,7 +274,7 @@ rndr_list(hoedown_buffer *ob, const hoedown_buffer *text, unsigned int flags, vo
} }
static void static void
rndr_listitem(hoedown_buffer *ob, const hoedown_buffer *text, unsigned int flags, void *opaque) rndr_listitem(hoedown_buffer *ob, const hoedown_buffer *text, hoedown_list_flags flags, void *opaque)
{ {
HOEDOWN_BUFPUTSL(ob, "<li>"); HOEDOWN_BUFPUTSL(ob, "<li>");
if (text) { if (text) {
@ -428,7 +428,7 @@ rndr_tablerow(hoedown_buffer *ob, const hoedown_buffer *text, void *opaque)
} }
static void static void
rndr_tablecell(hoedown_buffer *ob, const hoedown_buffer *text, hoedown_tableflags flags, void *opaque) rndr_tablecell(hoedown_buffer *ob, const hoedown_buffer *text, hoedown_table_flags flags, void *opaque)
{ {
if (flags & HOEDOWN_TABLE_HEADER) { if (flags & HOEDOWN_TABLE_HEADER) {
HOEDOWN_BUFPUTSL(ob, "<th"); HOEDOWN_BUFPUTSL(ob, "<th");
@ -648,7 +648,7 @@ hoedown_html_toc_renderer_new(int nesting_level)
} }
hoedown_renderer * hoedown_renderer *
hoedown_html_renderer_new(unsigned int render_flags, int nesting_level) hoedown_html_renderer_new(hoedown_html_flags render_flags, int nesting_level)
{ {
static const hoedown_renderer cb_default = { static const hoedown_renderer cb_default = {
NULL, NULL,

View file

@ -21,15 +21,11 @@ hoedown_stack_init(hoedown_stack *st, size_t initial_size)
} }
void void
hoedown_stack_reset(hoedown_stack *st) hoedown_stack_uninit(hoedown_stack *st)
{ {
assert(st); assert(st);
free(st->item); free(st->item);
st->item = NULL;
st->size = 0;
st->asize = 0;
} }
void void
@ -42,6 +38,7 @@ hoedown_stack_grow(hoedown_stack *st, size_t neosz)
st->item = hoedown_realloc(st->item, neosz * sizeof(void *)); st->item = hoedown_realloc(st->item, neosz * sizeof(void *));
memset(st->item + st->asize, 0x0, (neosz - st->asize) * sizeof(void *)); memset(st->item + st->asize, 0x0, (neosz - st->asize) * sizeof(void *));
st->asize = neosz; st->asize = neosz;
if (st->size > neosz) if (st->size > neosz)
@ -54,7 +51,7 @@ hoedown_stack_push(hoedown_stack *st, void *item)
assert(st); assert(st);
if (st->size >= st->asize) if (st->size >= st->asize)
hoedown_stack_grow(st, (st->size + 1) * 2); hoedown_stack_grow(st, st->size * 2);
st->item[st->size++] = item; st->item[st->size++] = item;
} }

View file

@ -29,8 +29,8 @@ typedef struct hoedown_stack hoedown_stack;
/* hoedown_stack_init: initialize a stack */ /* hoedown_stack_init: initialize a stack */
void hoedown_stack_init(hoedown_stack *st, size_t initial_size); void hoedown_stack_init(hoedown_stack *st, size_t initial_size);
/* hoedown_stack_reset: free internal data of the stack */ /* hoedown_stack_uninit: free internal data of the stack */
void hoedown_stack_reset(hoedown_stack *st); void hoedown_stack_uninit(hoedown_stack *st);
/* hoedown_stack_grow: increase the allocated size to the given value */ /* hoedown_stack_grow: increase the allocated size to the given value */
void hoedown_stack_grow(hoedown_stack *st, size_t neosz); void hoedown_stack_grow(hoedown_stack *st, size_t neosz);

View file

@ -1,9 +1,9 @@
#include "version.h" #include "version.h"
void void
hoedown_version(int *ver_major, int *ver_minor, int *ver_revision) hoedown_version(int *major, int *minor, int *revision)
{ {
*ver_major = HOEDOWN_VERSION_MAJOR; *major = HOEDOWN_VERSION_MAJOR;
*ver_minor = HOEDOWN_VERSION_MINOR; *minor = HOEDOWN_VERSION_MINOR;
*ver_revision = HOEDOWN_VERSION_REVISION; *revision = HOEDOWN_VERSION_REVISION;
} }