aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael McVady <femtonaut@gmail.com>2021-11-18 13:59:17 -0500
committerMichael McVady <femtonaut@gmail.com>2021-11-18 13:59:17 -0500
commit4f28d4e17d4eddeb7b27ccceee80a92233a7f0c7 (patch)
tree5eb8a9b07c83323702a51d2319f0d2c51fbfd96a
parent9cb9e59858c41ff65f4df4f0767e3acbcc4e4b48 (diff)
Clean up
-rw-r--r--src/clog.c67
1 files 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<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);
+}
+