Make the HTML renderer state public again

This commit is contained in:
Devin Torres 2014-01-07 10:21:25 -06:00
parent 0a67a5f484
commit 30976be4d7
2 changed files with 35 additions and 35 deletions

View file

@ -9,22 +9,6 @@
#define USE_XHTML(opt) (opt->flags & HOEDOWN_HTML_USE_XHTML)
struct rndr_state {
struct {
int header_count;
int current_level;
int level_offset;
int nesting_level;
} toc_data;
unsigned int flags;
/* extra callbacks */
void (*link_attributes)(hoedown_buffer *ob, const hoedown_buffer *url, void *self);
};
typedef struct rndr_state rndr_state;
int
hoedown_html_is_tag(const uint8_t *tag_data, size_t tag_size, const char *tagname)
{
@ -74,7 +58,7 @@ 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)
{
rndr_state *state = opaque;
hoedown_html_renderer_state *state = opaque;
if (!link || !link->size)
return 0;
@ -116,7 +100,7 @@ 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)
{
rndr_state *state = opaque;
hoedown_html_renderer_state *state = opaque;
if (ob->size) hoedown_buffer_putc(ob, '\n');
@ -171,7 +155,7 @@ rndr_blockquote(hoedown_buffer *ob, const hoedown_buffer *text, void *opaque)
static int
rndr_codespan(hoedown_buffer *ob, const hoedown_buffer *text, void *opaque)
{
rndr_state *state = opaque;
hoedown_html_renderer_state *state = opaque;
if (state->flags & HOEDOWN_HTML_PRETTIFY)
HOEDOWN_BUFPUTSL(ob, "<code class=\"prettyprint\">");
else
@ -258,7 +242,7 @@ rndr_quote(hoedown_buffer *ob, const hoedown_buffer *text, void *opaque)
static int
rndr_linebreak(hoedown_buffer *ob, void *opaque)
{
rndr_state *state = opaque;
hoedown_html_renderer_state *state = opaque;
hoedown_buffer_puts(ob, USE_XHTML(state) ? "<br/>\n" : "<br>\n");
return 1;
}
@ -266,7 +250,7 @@ rndr_linebreak(hoedown_buffer *ob, void *opaque)
static void
rndr_header(hoedown_buffer *ob, const hoedown_buffer *text, int level, void *opaque)
{
rndr_state *state = opaque;
hoedown_html_renderer_state *state = opaque;
if (ob->size)
hoedown_buffer_putc(ob, '\n');
@ -283,7 +267,7 @@ 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)
{
rndr_state *state = opaque;
hoedown_html_renderer_state *state = opaque;
if (link != NULL && (state->flags & HOEDOWN_HTML_SAFELINK) != 0 && !hoedown_autolink_is_safe(link->data, link->size))
return 0;
@ -337,7 +321,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)
{
rndr_state *state = opaque;
hoedown_html_renderer_state *state = opaque;
size_t i = 0;
if (ob->size) hoedown_buffer_putc(ob, '\n');
@ -405,7 +389,7 @@ rndr_triple_emphasis(hoedown_buffer *ob, const hoedown_buffer *text, void *opaqu
static void
rndr_hrule(hoedown_buffer *ob, void *opaque)
{
rndr_state *state = opaque;
hoedown_html_renderer_state *state = opaque;
if (ob->size) hoedown_buffer_putc(ob, '\n');
hoedown_buffer_puts(ob, USE_XHTML(state) ? "<hr/>\n" : "<hr>\n");
}
@ -413,7 +397,7 @@ rndr_hrule(hoedown_buffer *ob, void *opaque)
static int
rndr_image(hoedown_buffer *ob, const hoedown_buffer *link, const hoedown_buffer *title, const hoedown_buffer *alt, void *opaque)
{
rndr_state *state = opaque;
hoedown_html_renderer_state *state = opaque;
if (!link || !link->size) return 0;
HOEDOWN_BUFPUTSL(ob, "<img src=\"");
@ -434,7 +418,7 @@ rndr_image(hoedown_buffer *ob, const hoedown_buffer *link, const hoedown_buffer
static int
rndr_raw_html(hoedown_buffer *ob, const hoedown_buffer *text, void *opaque)
{
rndr_state *state = opaque;
hoedown_html_renderer_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. */
@ -540,7 +524,7 @@ 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)
{
rndr_state *state = opaque;
hoedown_html_renderer_state *state = opaque;
if (ob->size) hoedown_buffer_putc(ob, '\n');
HOEDOWN_BUFPUTSL(ob, "<div class=\"footnotes\">\n");
@ -593,7 +577,7 @@ 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)
{
rndr_state *state = opaque;
hoedown_html_renderer_state *state = opaque;
if (level <= state->toc_data.nesting_level) {
/* set the level offset if this is the first header
@ -636,7 +620,7 @@ toc_link(hoedown_buffer *ob, const hoedown_buffer *link, const hoedown_buffer *t
static void
toc_finalize(hoedown_buffer *ob, void *opaque)
{
rndr_state *state = opaque;
hoedown_html_renderer_state *state = opaque;
while (state->toc_data.current_level > 0) {
HOEDOWN_BUFPUTSL(ob, "</li>\n</ul>\n");
@ -687,15 +671,15 @@ hoedown_html_toc_renderer_new(int nesting_level)
NULL
};
rndr_state *state;
hoedown_html_renderer_state *state;
hoedown_renderer *renderer;
/* Prepare the state pointer */
state = malloc(sizeof(rndr_state));
state = malloc(sizeof(hoedown_html_renderer_state));
if (!state)
return NULL;
memset(state, 0x0, sizeof(rndr_state));
memset(state, 0x0, sizeof(hoedown_html_renderer_state));
if (nesting_level > 0) {
state->flags |= HOEDOWN_HTML_TOC;
@ -758,15 +742,15 @@ hoedown_html_renderer_new(unsigned int render_flags, int nesting_level)
NULL
};
rndr_state *state;
hoedown_html_renderer_state *state;
hoedown_renderer *renderer;
/* Prepare the state pointer */
state = malloc(sizeof(rndr_state));
state = malloc(sizeof(hoedown_html_renderer_state));
if (!state)
return NULL;
memset(state, 0x0, sizeof(rndr_state));
memset(state, 0x0, sizeof(hoedown_html_renderer_state));
state->flags = render_flags;

View file

@ -31,6 +31,22 @@ typedef enum {
HOEDOWN_HTML_TAG_CLOSE
} hoedown_html_tag;
struct hoedown_html_renderer_state {
struct {
int header_count;
int current_level;
int level_offset;
int nesting_level;
} toc_data;
unsigned int flags;
/* extra callbacks */
void (*link_attributes)(hoedown_buffer *ob, const hoedown_buffer *url, void *self);
};
typedef struct hoedown_html_renderer_state hoedown_html_renderer_state;
int
hoedown_html_is_tag(const uint8_t *tag_data, size_t tag_size, const char *tagname);