diff options
-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); } |