summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/commonmark.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/commonmark.c b/src/commonmark.c
index 6c0de88..3ab9988 100644
--- a/src/commonmark.c
+++ b/src/commonmark.c
@@ -36,14 +36,17 @@ static inline void blankline(struct render_state *state)
}
}
-static inline bool needs_escaping(int32_t c, unsigned char d)
+static inline bool
+needs_escaping(int32_t c, unsigned char next_c, struct render_state *state)
{
- // TODO escape potential list markers at beginning of line
- // (add param)
return (c == '*' || c == '_' || c == '[' || c == ']' ||
c == '<' || c == '>' || c == '\\' ||
- (c == '&' && isalpha(d)) ||
- (c == '!' && d == '['));
+ (c == '&' && isalpha(next_c)) ||
+ (c == '!' && next_c == '[') ||
+ (state->begin_line &&
+ (c == '-' || c == '+' || c == '#' || c == '=')) ||
+ ((c == '.' || c == ')') &&
+ isdigit(state->buffer->ptr[state->buffer->size - 1])));
}
static inline void out(struct render_state *state,
@@ -103,7 +106,8 @@ static inline void out(struct render_state *state,
state->column = 0;
state->begin_line = true;
state->last_breakable = 0;
- } else if (escape && needs_escaping(c, nextc)) {
+ } else if (escape &&
+ needs_escaping(c, nextc, state)) {
cmark_strbuf_putc(state->buffer, '\\');
utf8proc_encode_char(c, state->buffer);
state->column += 2;