summary refs log tree commit diff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c21
1 files changed, 16 insertions, 5 deletions
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( "<em>"), S( "<code>"), S("“") };
-Str im_str_cl[IM_NONE] = { S("</em>"), S("</code>"), S("”") };
+Str im_str_op[IM_NONE] = { S( "<em>"), S( "<code>"),  };
+Str im_str_cl[IM_NONE] = { S("</em>"), S("</code>"),  };
+
+#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("&mdash;"), perm);
 				i += 2;
 			} else {
+				text_inline(ms, c, out, perm);
 				str_catc_html(out, src.s[i], perm);
 			}
 		}