From e6e0d5a53eeb969e9e04051559993db69b98cc85 Mon Sep 17 00:00:00 2001 From: WormHeamer Date: Mon, 10 Mar 2025 15:15:17 -0400 Subject: replace .gmi with .html for local links properly --- main.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/main.c b/main.c index 70029f8..d9cbd44 100644 --- a/main.c +++ b/main.c @@ -183,6 +183,7 @@ BlockList blk_gather(Str src, Arena *perm) { Block *b = &blk.data[blk.len-1]; if (!b->lines) b->lines = lptr; } + last = t; } for (size_t i = 0; i < blk.len; i++) { if (blk.data[i].type == LN_NONE) { @@ -200,7 +201,15 @@ BlockList blk_gather(Str src, Arena *perm) { #define Ot(a, s, b) Os(a), O(s), Os(b) #define Otl(a, f, b) for (Line *l = blk->lines; l; l = l->next) Ot(a, f, b) -void str_cat_blk(Str *out, Block *blk, Arena *perm) { +Str str_replace_end(Str s, Str a, Str b, Arena *m) { + if (!str_ends(s, a)) return s; + char *p = new_arr(m, char, s.n + b.n - a.n); + memcpy(p, s.s, s.n - a.n); + memcpy(p + s.n - a.n, b.s, b.n); + return (Str) { p, s.n + b.n - a.n }; +} + +void str_cat_blk(Str *out, Block *blk, Arena *perm, Arena *scratch) { switch (blk->type) { case LN_CODE: Os("
");
@@ -216,7 +225,9 @@ void str_cat_blk(Str *out, Block *blk, Arena *perm) {
Cut c = str_cut(str_trim(str_skip(l->txt, 2)), ' ');
Str url = c.head, txt = c.tail.n > 0 ? c.tail : c.head;
Os("", txt, " \n");
}
Os("");
@@ -268,14 +279,6 @@ int has_image_ext(Str url) {
|| str_ends(url, S(".webp"));
}
-Str str_replace_end(Str s, Str a, Str b, Arena *m) {
- if (!str_ends(s, a)) return s;
- char *p = new_arr(m, char, s.n + b.n - a.n);
- memcpy(p, s.s, s.n - a.n);
- memcpy(p + s.n - a.n, b.s, b.n);
- return (Str) { p, s.n + b.n - a.n };
-}
-
int wdoc(FILE *f, Doc **dp, Arena *perm, Arena *scratch) {
Str buf;
if (read_all(f, &buf, scratch)) return -1;
@@ -285,7 +288,7 @@ int wdoc(FILE *f, Doc **dp, Arena *perm, Arena *scratch) {
if (blk.data[i].type == LN_HDR1 && !d->title.s) {
d->title = str_trim(str_skip(blk.data[i].lines->txt, 1));
}
- str_cat_blk(&d->html, &blk.data[i], perm);
+ str_cat_blk(&d->html, &blk.data[i], perm, scratch);
}
*dp = d;
return 0;
--
cgit 1.4.1-2-gfad0