diff options
author | John MacFarlane <jgm@berkeley.edu> | 2015-03-21 18:16:50 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2015-03-21 18:25:18 -0700 |
commit | 4b21fe65b6f774193ce25b6f0ebee5cf88b88200 (patch) | |
tree | 9c9c173885fa3be29d3d4108fdaae60b8ca19b3a /src | |
parent | 0bf07dda1cbbdaf0ae7696be1f0c37169689539f (diff) |
Commonmark renderer: improved escaping.
Diffstat (limited to 'src')
-rw-r--r-- | src/commonmark.c | 16 |
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; |