diff options
-rw-r--r-- | src/clog.c | 67 |
1 files changed, 36 insertions, 31 deletions
@@ -13,6 +13,8 @@ int init(int); int page(struct http_request *); +static void process_md_output(const MD_CHAR *, MD_SIZE size, void *); +static int render_md(char *, struct kore_buf *); // Called when this module is loaded (see config) int @@ -27,29 +29,6 @@ init(int state) return err; } -static void -process_md_output(const MD_CHAR* html, MD_SIZE size, void *buf) -{ - kore_buf_append((struct kore_buf *) buf, (const void *) html, (size_t) size); -} - -static int -render_md(char *in, struct kore_buf *out) -{ - static unsigned parser_flags = 0; - static unsigned renderer_flags = MD_HTML_FLAG_DEBUG; - - int ret = md_html(in, (MD_SIZE) strlen(in), process_md_output, (void*) out, - parser_flags, renderer_flags); - - if(ret != 0) { - fprintf(stderr, "Parsing failed.\n"); - return -1; - } - - return 1; -} - int page(struct http_request *req) { @@ -106,18 +85,14 @@ page(struct http_request *req) struct kore_buf *html_buf = kore_buf_alloc(4096); if (!render_md(body, html_buf)) { - kore_log(LOG_NOTICE, "Error rendering markdown."); + kore_log(LOG_ERR, "Error rendering markdown for entry %s.", id); kore_buf_free(html_buf); continue; } - kore_buf_appendf( - resp_buf, - "\t<tr><td>%s</td><td>%s</td><td>%s</td></tr>\n", - id, - title, - kore_buf_stringify(html_buf, NULL) - ); + kore_buf_append(resp_buf, asset_post_begin_html, asset_len_post_begin_html); + kore_buf_appendf(resp_buf, "%s", kore_buf_stringify(html_buf, NULL)); + kore_buf_append(resp_buf, asset_post_end_html, asset_len_post_end_html); kore_buf_free(html_buf); } @@ -134,3 +109,33 @@ out: ; return (KORE_RESULT_OK); } + +static int +render_md(char *in, struct kore_buf *out) +{ + static unsigned parser_flags = 0; + static unsigned renderer_flags = MD_HTML_FLAG_DEBUG; + + int ret = md_html( + in, + (MD_SIZE) strlen(in), + process_md_output, + (void*) out, + parser_flags, + renderer_flags + ); + + if(ret != 0) { + fprintf(stderr, "Parsing failed.\n"); + return -1; + } + + return 1; +} + +static void +process_md_output(const MD_CHAR *html, MD_SIZE size, void *buf) +{ + kore_buf_append((struct kore_buf *) buf, (const void *) html, (size_t) size); +} + |