diff options
Diffstat (limited to 'src/render.c')
-rwxr-xr-x | src/render.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/render.c b/src/render.c index 898a9e2..2c941bf 100755 --- a/src/render.c +++ b/src/render.c @@ -23,6 +23,7 @@ static void S_out(cmark_renderer *renderer, const char *source, bool wrap, unsigned char nextc; int32_t c; int i = 0; + int last_nonspace; int len; cmark_chunk remainder = cmark_chunk_literal(""); int k = renderer->buffer->size - 1; @@ -63,15 +64,20 @@ static void S_out(cmark_renderer *renderer, const char *source, bool wrap, nextc = source[i + len]; if (c == 32 && wrap) { if (!renderer->begin_line) { + last_nonspace = renderer->buffer->size; cmark_strbuf_putc(renderer->buffer, ' '); renderer->column += 1; renderer->begin_line = false; renderer->begin_content = false; - renderer->last_breakable = renderer->buffer->size - 1; // skip following spaces while (source[i + 1] == ' ') { i++; } + // We don't allow breaks that make a digit the first character + // because this causes problems with commonmark output. + if (!cmark_isdigit(source[i + 1])) { + renderer->last_breakable = last_nonspace; + } } } else if (c == 10) { @@ -83,11 +89,17 @@ static void S_out(cmark_renderer *renderer, const char *source, bool wrap, } else if (escape == LITERAL) { cmark_render_code_point(renderer, c); renderer->begin_line = false; - renderer->begin_content = false; + // we don't set 'begin_content' to false til we've + // finished parsing a digit. Reason: in commonmark + // we need to escape a potential list marker after + // a digit: + renderer->begin_content = renderer->begin_content && + cmark_isdigit(c) == 1; } else { (renderer->outc)(renderer, escape, c, nextc); renderer->begin_line = false; - renderer->begin_content = false; + renderer->begin_content = renderer->begin_content && + cmark_isdigit(c) == 1; } // If adding the character went beyond width, look for an |