From f97750517aa62066c1feab178262b32e370f22ce Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sat, 6 Feb 2016 22:05:27 -0800 Subject: Fixed handling of tabs in lists. --- src/blocks.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/blocks.c b/src/blocks.c index 1f4a008..acb9ab4 100644 --- a/src/blocks.c +++ b/src/blocks.c @@ -626,6 +626,9 @@ static void S_process_line(cmark_parser *parser, const unsigned char *buffer, cmark_chunk input; bool maybe_lazy; char c; + bool save_partially_consumed_tab; + int save_offset; + int save_column; if (parser->options & CMARK_OPT_VALIDATE_UTF8) { cmark_utf8proc_check(parser->curline, buffer, bytes); @@ -861,21 +864,28 @@ static void S_process_line(cmark_parser *parser, const unsigned char *buffer, S_advance_offset(parser, &input, parser->first_nonspace + matched - parser->offset, false); - i = 0; - // TODO handle tabs - while (i <= 5 && (c = peek_at(&input, parser->offset + i)) && c == ' ') { - i++; + + save_partially_consumed_tab = parser->partially_consumed_tab; + save_offset = parser->offset; + save_column = parser->column; + + while (parser->column - save_column <= 5 && + (c = peek_at(&input, parser->offset)) && + (c == ' ' || c == '\t')) { + S_advance_offset(parser, &input, 1, true); } - // i = number of spaces after marker, up to 5 - if (i >= 5 || i < 1 || - S_is_line_end_char(peek_at(&input, parser->offset))) { + + i = parser->column - save_column; + if (i >= 5 || i < 1) { data->padding = matched + 1; + parser->offset = save_offset; + parser->column = save_column; + parser->partially_consumed_tab = save_partially_consumed_tab; if (i > 0) { - S_advance_offset(parser, &input, 1, false); + S_advance_offset(parser, &input, 1, true); } } else { data->padding = matched + i; - S_advance_offset(parser, &input, i, true); } // check container; if it's a list, see if this list item -- cgit v1.2.3