summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/blocks.c4
-rw-r--r--src/cmark.h5
-rw-r--r--src/node.c8
-rw-r--r--src/node.h1
-rw-r--r--src/parser.h1
-rw-r--r--src/xml.c5
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
*/
diff --git a/src/node.c b/src/node.c
index 6a5370f..88b1281 100644
--- a/src/node.c
+++ b/src/node.c
@@ -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) {
diff --git a/src/node.h b/src/node.h
index fb3b667..c0c43d3 100644
--- a/src/node.h
+++ b/src/node.h
@@ -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;
};
diff --git a/src/xml.c b/src/xml.c
index 1ec1d7d..2cfd800 100644
--- a/src/xml.c
+++ b/src/xml.c
@@ -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;