summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2020-01-10 09:03:41 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2020-01-10 09:03:41 -0800
commitf68678bf9ea6c5a5d9232c4b0f4a6bcc4d87b6df (patch)
tree100f12cd5e2b0092357f5e1cddc5fb619ee6b1d8 /src
parent2da6c9b98e1c5ab0c307a47f63c78e6d6c85543e (diff)
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.
Diffstat (limited to 'src')
-rw-r--r--src/commonmark.c5
1 files changed, 5 insertions, 0 deletions
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...