diff options
-rw-r--r-- | src/commonmark.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/commonmark.c b/src/commonmark.c index 0db0f34..404c290 100644 --- a/src/commonmark.c +++ b/src/commonmark.c @@ -32,7 +32,8 @@ static CMARK_INLINE void outc(cmark_renderer *renderer, cmark_escaping escape, needs_escaping = c < 0x80 && escape != LITERAL && ((escape == NORMAL && - (c == '*' || c == '_' || c == '[' || c == ']' || c == '#' || c == '<' || + (c < 0x20 || + c == '*' || c == '_' || c == '[' || c == ']' || c == '#' || c == '<' || c == '>' || c == '\\' || c == '`' || c == '!' || (c == '&' && cmark_isalpha(nextc)) || (c == '!' && nextc == '[') || (renderer->begin_content && (c == '-' || c == '+' || c == '=') && @@ -48,14 +49,18 @@ static CMARK_INLINE void outc(cmark_renderer *renderer, cmark_escaping escape, (c == '`' || c == '<' || c == '>' || c == '"' || c == '\\'))); if (needs_escaping) { - if (cmark_isspace(c)) { + if (escape == URL && cmark_isspace(c)) { // use percent encoding for spaces - snprintf(encoded, ENCODED_SIZE, "%%%2x", c); + snprintf(encoded, ENCODED_SIZE, "%%%2X", c); cmark_strbuf_puts(renderer->buffer, encoded); renderer->column += 3; - } else { + } else if (cmark_ispunct(c)) { cmark_render_ascii(renderer, "\\"); cmark_render_code_point(renderer, c); + } else { // render as entity + snprintf(encoded, ENCODED_SIZE, "&#%d;", c); + cmark_strbuf_puts(renderer->buffer, encoded); + renderer->column += strlen(encoded); } } else { cmark_render_code_point(renderer, c); |