aboutsummaryrefslogtreecommitdiff
path: root/src/msg.c
diff options
context:
space:
mode:
authorRaghuram Subramani <raghus2247@gmail.com>2025-07-31 12:01:18 +0530
committerRaghuram Subramani <raghus2247@gmail.com>2025-07-31 12:01:18 +0530
commit950fdee16ad3433c536d04d58e356803fd204d11 (patch)
tree920c03b7025a4485648cb3b4a7b82643731f6213 /src/msg.c
parentc2f524679ef0a5902c27ac2e9d8dcca62ff27da7 (diff)
msg: allow markdown files to specify a template
Diffstat (limited to 'src/msg.c')
-rw-r--r--src/msg.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/msg.c b/src/msg.c
index 49a4155..29566c1 100644
--- a/src/msg.c
+++ b/src/msg.c
@@ -96,8 +96,22 @@ handle_file(const char *path)
char *buffer = fcontent(in, size);
if (dot && strcmp(dot, ".md") == 0) {
+ engine_t engine = { .config = NULL, .content_headers = NULL };
+
+ char *p = strstr(buffer, "---");
+ if (p != NULL) {
+ char *config;
+ asprintf(&config, "%.*s\n", (int) (p - buffer), buffer);
+ engine.config = config_parse(config);
+ free(config);
+ strcpy(buffer, p + strlen("---"));
+ }
+
MMIOT *doc = mkd_string(buffer, size, 0);
- template_write(NULL, out, doc, true);
+ template_write(&engine, out, doc, true);
+
+ if (engine.config != NULL)
+ config_delete(engine.config);
} else if (strlen(buffer) != 0) {
engine_t *engine = engine_ingest(&buffer);
template_write(engine, out, buffer, false);