diff options
-rw-r--r-- | src/blocks.c | 4 | ||||
-rw-r--r-- | src/cmark.h | 5 | ||||
-rw-r--r-- | src/node.c | 8 | ||||
-rw-r--r-- | src/node.h | 1 | ||||
-rw-r--r-- | src/parser.h | 1 | ||||
-rw-r--r-- | src/xml.c | 5 |
6 files changed, 22 insertions, 2 deletions
diff --git a/src/blocks.c b/src/blocks.c index 7b676b7..0caa4a5 100644 --- a/src/blocks.c +++ b/src/blocks.c @@ -64,6 +64,7 @@ cmark_parser *cmark_parser_new() parser->current = document; parser->line_number = 0; parser->curline = line; + parser->last_line_length = 0; parser->linebuf = buf; return parser; @@ -198,6 +199,8 @@ finalize(cmark_parser *parser, cmark_node* b) b->end_line = parser->line_number; } + 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) == '[' && @@ -853,6 +856,7 @@ S_process_line(cmark_parser *parser, const unsigned char *buffer, size_t bytes) parser->current = container; } + parser->last_line_length = parser->curline->size; cmark_strbuf_clear(parser->curline); } diff --git a/src/cmark.h b/src/cmark.h index a9d7bb6..37b3efa 100644 --- a/src/cmark.h +++ b/src/cmark.h @@ -306,6 +306,11 @@ cmark_node_get_start_column(cmark_node *node); CMARK_EXPORT int cmark_node_get_end_line(cmark_node *node); +/** Returns the column at which 'node' ends. + */ +CMARK_EXPORT int +cmark_node_get_end_column(cmark_node *node); + /** * ## Tree Manipulation */ @@ -475,6 +475,14 @@ cmark_node_get_end_line(cmark_node *node) { return node->end_line; } +int +cmark_node_get_end_column(cmark_node *node) { + if (node == NULL) { + return 0; + } + return node->end_column; +} + static inline bool S_is_block(cmark_node *node) { if (node == NULL) { @@ -52,6 +52,7 @@ struct cmark_node { int start_line; int start_column; int end_line; + int end_column; bool open; bool last_line_blank; diff --git a/src/parser.h b/src/parser.h index 9d65b67..3c8def9 100644 --- a/src/parser.h +++ b/src/parser.h @@ -17,6 +17,7 @@ struct cmark_parser { struct cmark_node* current; int line_number; cmark_strbuf *curline; + int last_line_length; cmark_strbuf *linebuf; }; @@ -49,10 +49,11 @@ S_render_node(cmark_node *node, cmark_event_type ev_type, void *vstate) cmark_node_get_type_string(node)); if (node->start_line != 0) { - cmark_strbuf_printf(xml, " sourcepos=\"%d:%d-%d\"", + cmark_strbuf_printf(xml, " sourcepos=\"%d:%d-%d:%d\"", node->start_line, node->start_column, - node->end_line); + node->end_line, + node->end_column); } literal = false; |