From f68678bf9ea6c5a5d9232c4b0f4a6bcc4d87b6df Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Fri, 10 Jan 2020 09:03:41 -0800 Subject: commonmark renderer: better escaping in smart mode. When CMARK_OPT_SMART is enabled, we escape literal `-`, `.`, and quote characters when needed to avoid their being "smartified." See e.g. jgm/pandoc#6041 for an application. --- src/commonmark.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src') diff --git a/src/commonmark.c b/src/commonmark.c index 7864ee6..24c8581 100644 --- a/src/commonmark.c +++ b/src/commonmark.c @@ -28,6 +28,7 @@ static CMARK_INLINE void outc(cmark_renderer *renderer, cmark_escaping escape, renderer->buffer->size > 0 && cmark_isdigit(renderer->buffer->ptr[renderer->buffer->size - 1]); char encoded[ENCODED_SIZE]; + int options = renderer->options; needs_escaping = c < 0x80 && escape != LITERAL && @@ -36,6 +37,10 @@ static CMARK_INLINE void outc(cmark_renderer *renderer, cmark_escaping escape, c == '*' || c == '_' || c == '[' || c == ']' || c == '#' || c == '<' || c == '>' || c == '\\' || c == '`' || c == '!' || (c == '&' && cmark_isalpha(nextc)) || (c == '!' && nextc == '[') || + ((CMARK_OPT_SMART & options) && + ((c == '-' && nextc == '-') || + (c == '.' && nextc == '.') || + c == '"' || c == '\'')) || (renderer->begin_content && (c == '-' || c == '+' || c == '=') && // begin_content doesn't get set to false til we've passed digits // at the beginning of line, so... -- cgit v1.2.3