diff options
author | John MacFarlane <jgm@berkeley.edu> | 2014-12-28 18:45:09 -0800 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2014-12-28 18:45:09 -0800 |
commit | 4cdc1d575ea086253766ecfed6c60b2c855bd505 (patch) | |
tree | ae3542de085eb2a816d327e47f588df2c0b438d0 /src/blocks.c | |
parent | 19a3a5ea4f73e8757b6d208f3be003bc2828e752 (diff) |
Improved end column/end line calculations in finalize.
Diffstat (limited to 'src/blocks.c')
-rw-r--r-- | src/blocks.c | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/blocks.c b/src/blocks.c index 0caa4a5..319706d 100644 --- a/src/blocks.c +++ b/src/blocks.c @@ -193,14 +193,23 @@ finalize(cmark_parser *parser, cmark_node* b) return parent; b->open = false; - if (parser->line_number > b->start_line) { - b->end_line = parser->line_number - 1; - } else { + + if (parser->curline->size == 0) { + // end of input - line number has not been incremented + b->end_line = parser->line_number; + b->end_column = parser->last_line_length; + } else if (b->type == NODE_DOCUMENT || + (b->type == NODE_CODE_BLOCK && b->as.code.fenced) || + (b->type == NODE_HEADER && b->as.header.setext)) { b->end_line = parser->line_number; + b->end_column = parser->curline->size - + (parser->curline->ptr[parser->curline->size - 1] == '\n' ? + 1 : 0); + } else { + b->end_line = parser->line_number - 1; + b->end_column = parser->last_line_length; } - b->end_column = parser->last_line_length - 1; // -1 because of newline - switch (b->type) { case NODE_PARAGRAPH: while (cmark_strbuf_at(&b->string_content, 0) == '[' && @@ -856,7 +865,10 @@ S_process_line(cmark_parser *parser, const unsigned char *buffer, size_t bytes) parser->current = container; } - parser->last_line_length = parser->curline->size; + parser->last_line_length = parser->curline->size - + (parser->curline->ptr[parser->curline->size - 1] == '\n' ? + 1 : 0); +; cmark_strbuf_clear(parser->curline); } |