From 589e6f67eca81c727873656a19508675810e8f08 Mon Sep 17 00:00:00 2001
From: wrmr
Date: Sat, 5 Apr 2025 21:59:54 -0500
Subject: smart quotes doesn't require --inline, can be unpaired
---
main.c | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
(limited to 'main.c')
diff --git a/main.c b/main.c
index 9e964bb..5fc6bd0 100644
--- a/main.c
+++ b/main.c
@@ -272,14 +272,17 @@ BlockList blk_gather(Str src, Arena *perm) {
typedef enum {
IM_ITAL,
IM_CODE,
- IM_DQUOT,
IM_NONE
} InlineMarkup;
-Str im_str_op[IM_NONE] = { S( ""), S( ""), S("“") };
-Str im_str_cl[IM_NONE] = { S("
"), S(""), S("”") };
+Str im_str_op[IM_NONE] = { S( ""), S( ""), };
+Str im_str_cl[IM_NONE] = { S("
"), S(""), };
+
+#define DQUOT_OP S("“")
+#define DQUOT_CL S("”")
typedef struct {
+ int dquot;
int stkc;
InlineMarkup *stkv;
} InlineState;
@@ -331,9 +334,17 @@ void im_tog(InlineState *ms, Str *out, InlineMarkup mu, Arena *scratch, Arena *p
}
}
+void text_inline(InlineState *ms, char c, Str *out, Arena *perm) {
+ if (c == '"' && opts.smartquot) {
+ str_cat(out, (ms->dquot = !ms->dquot) ? DQUOT_OP : DQUOT_CL, perm);
+ } else {
+ str_catc_html(out, c, perm);
+ }
+}
+
void markup_inline(InlineState *ms, Str *out, Str src, Arena *scratch, Arena *perm) {
if (!opts.inlinep) {
- str_cat_html(out, src, perm);
+ for (int i = 0; i < src.n; i++) text_inline(ms, src.s[i], out, perm);
return;
}
for (int i = 0; i < src.n; i++) {
@@ -347,11 +358,11 @@ void markup_inline(InlineState *ms, Str *out, Str src, Arena *scratch, Arena *pe
} else {
if (c == '`') im_op(ms, out, IM_CODE, scratch, perm);
else if (c == '*') im_tog(ms, out, IM_ITAL, scratch, perm);
- else if (c == '"' && opts.smartquot) im_tog(ms, out, IM_DQUOT, scratch, perm);
else if (str_starts(str_skip(src, i), S("---"))) {
str_cat(out, S("—"), perm);
i += 2;
} else {
+ text_inline(ms, c, out, perm);
str_catc_html(out, src.s[i], perm);
}
}
--
cgit 1.4.1-2-gfad0