From 4f28d4e17d4eddeb7b27ccceee80a92233a7f0c7 Mon Sep 17 00:00:00 2001 From: Michael McVady Date: Thu, 18 Nov 2021 13:59:17 -0500 Subject: Clean up --- src/clog.c | 67 +++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/src/clog.c b/src/clog.c index 6fd2843..083e07d 100644 --- a/src/clog.c +++ b/src/clog.c @@ -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%s%s%s\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); +} + -- cgit v1.2.3