cmark

My personal build of CMark ✏️

Commit
f68678bf9ea6c5a5d9232c4b0f4a6bcc4d87b6df
Parent
2da6c9b98e1c5ab0c307a47f63c78e6d6c85543e
Author
John MacFarlane <jgm@berkeley.edu>
Date

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

1 file changed, 5 insertions, 0 deletions

Status File Name N° Changes Insertions Deletions
Modified src/commonmark.c 5 5 0
diff --git 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...