Print this page
        
@@ -1,7 +1,8 @@
 /*
  * Copyright (c) 2009-2020 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
+ * Copyright 2020, Kebe Software & Services
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
  * in the Software without restriction, including without limitation the rights
  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@@ -240,10 +241,33 @@
         ASSERT(post->body);
 
         return 0;
 }
 
+static int
+__do_load_post_body_fmt4(struct post *post, const struct str *md)
+{
+        /*
+         * Like HTML, assume the .lisp file contains all of the other post
+         * metadata.  If that assumption changes, update here.
+         *
+         * Unlike HTML, we plan to provide a clean error string if MD
+         * parsing fails.
+         */
+        str_putref(post->body); /* Free the previous text. */
+        post->body = fmt4_md_to_html(md);
+        if (post->body == NULL) {
+                /*
+                 * XXX KEBE SAYS do something clever here with a small HTML
+                 * string.  For now, panic.
+                 */
+                ASSERT(post->body != NULL);
+        }
+
+        return (0);
+}
+
 static int __do_load_post_body_fmt3(struct post *post, const struct str *input)
 {
         struct parser_output x;
         int ret;
 
@@ -302,21 +326,22 @@
         return 0;
 }
 
 static int __load_post_body(struct post *post)
 {
-        static const char *exts[4] = {
+        static const char *exts[5] = {
                 [2] = "html",
                 [3] = "tex",
+                [4] = "md",
         };
 
         char path[FILENAME_MAX];
         struct str *raw;
         int ret;
 
         ASSERT3U(post->fmt, >=, 2);
-        ASSERT3U(post->fmt, <=, 3);
+        ASSERT3U(post->fmt, <=, 4);
 
         snprintf(path, FILENAME_MAX, "%s/posts/%d/post.%s",
                  str_cstr(config.data_dir), post->id, exts[post->fmt]);
 
         raw = post_get_cached_file(post, path);
@@ -328,10 +353,13 @@
                         ret = __do_load_post_body_fmt2(post, raw);
                         break;
                 case 3:
                         ret = __do_load_post_body_fmt3(post, raw);
                         break;
+                case 4:
+                        ret = __do_load_post_body_fmt4(post, raw);
+                        break;
         }
 
         str_putref(raw);
 
         return ret;