diff options
author | John MacFarlane <[email protected]> | 2016-01-17 14:28:53 -0800 |
---|---|---|
committer | John MacFarlane <[email protected]> | 2016-01-17 14:28:53 -0800 |
commit | 01cb5c9563cc257e14a0093843d87621563d961f (patch) | |
tree | 6b53401cef0dca299fa1b9e3b437a7669fe96c12 /src/commonmark.c | |
parent | 1f8ea828409287b7901bf32d01f8ec662ffdc9ba (diff) |
Improved escaping in commonmark renderer.
We try not to escape punctuation unless we absolutely have
to. So, `)` and `.` are no longer escaped whenever they
occur after digits; now they are only escaped if they are
geuninely in a position where they'd cause a list item.
This required a couple changes to render.c.
- `renderer->begin_content` is only set to false AFTER a
string of digits at the beginning of the line. (This is
slightly unprincipled.)
- We never break before a numeral (also slightly unprincipled).
Diffstat (limited to 'src/commonmark.c')
-rw-r--r-- | src/commonmark.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/commonmark.c b/src/commonmark.c index 3eac076..4fb9cec 100644 --- a/src/commonmark.c +++ b/src/commonmark.c @@ -24,6 +24,8 @@ static inline void outc(cmark_renderer *renderer, cmark_escaping escape, int32_t c, unsigned char nextc) { bool needs_escaping = false; char encoded[20]; + bool follows_digit = renderer->buffer->size > 0 && + cmark_isdigit(renderer->buffer->ptr[renderer->buffer->size - 1]); needs_escaping = escape != LITERAL && @@ -31,9 +33,12 @@ static inline void outc(cmark_renderer *renderer, cmark_escaping escape, (c == '*' || c == '_' || c == '[' || c == ']' || c == '#' || c == '<' || c == '>' || c == '\\' || c == '`' || c == '!' || (c == '&' && isalpha(nextc)) || (c == '!' && nextc == '[') || - (renderer->begin_content && (c == '-' || c == '+' || c == '=')) || - ((c == '.' || c == ')') && - isdigit(renderer->buffer->ptr[renderer->buffer->size - 1])))) || + (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... + !follows_digit) || + (renderer->begin_content && (c == '.' || c == ')') && follows_digit && + (nextc == 0 || cmark_isspace(nextc))))) || (escape == URL && (c == '`' || c == '<' || c == '>' || isspace(c) || c == '\\' || c == ')' || c == '(')) || (escape == TITLE && |