summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWormHeamer2025-05-14 22:39:39 -0400
committerWormHeamer2025-05-14 22:39:39 -0400
commit4022ff9578b4fbcb64f3896702d74529f92c7608 (patch)
tree895261ef96408119b6dd0a4154006297d6902346
parent23bab6644402a3bb91a008cc3da5c79e4806ad3a (diff)
add inline links
-rw-r--r--main.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/main.c b/main.c
index 5aa7a9e..7743de8 100644
--- a/main.c
+++ b/main.c
@@ -356,9 +356,22 @@ void markup_inline(InlineState *ms, Str *out, Str src, Arena *scratch, Arena *pe
str_catc_html(out, src.s[i], perm);
}
} else {
+ Str skp = str_skip(src, i);
if (c == '`') im_op(ms, out, IM_CODE, scratch, perm);
else if (c == '*') im_tog(ms, out, IM_ITAL, scratch, perm);
- else if (str_starts(str_skip(src, i), S("---"))) {
+ else if (str_starts(skp, S("[["))) {
+ skp = str_skip(skp, 2);
+ Str f = str_find(skp, S("]]"));
+ Str lnks = { skp.s, f.n ? f.s - skp.s : skp.n };
+ Cut lnk = str_cut(lnks, '|');
+ str_cat(out, S("<a href="), perm);
+ str_cat_uri(out, lnk.tail.n > 0 ? lnk.tail : lnk.head, perm);
+ str_catc(out, '>', perm);
+ markup_inline(ms, out, lnk.head, scratch, perm);
+ str_cat(out, S("</a>"), perm);
+ if (!f.n) break;
+ i = f.s - src.s + 2;
+ } else if (str_starts(skp, S("---"))) {
str_cat(out, S("&mdash;"), perm);
i += 2;
} else {
@@ -510,7 +523,7 @@ void usage(const char *cmd) {
" -c --css embed the given file within a <style> element\n"
" -l --link when combined with --css, link to an external stylehseet\n"
" instead of reading from a file locally\n"
- " -i --inline enable inline formatting (*italics*, `code`, ---dashes)\n"
+ " -i --inline enable inline formatting (*italics*, `code`, ---dashes, [[links]])\n"
" -q --smartq enable smart quotes\n"
" -t --title set the document title (does nothing without --standalone)\n"
" -L --lang set the document's language\n",