summaryrefslogtreecommitdiff
path: root/src/cmark.h
diff options
context:
space:
mode:
authorMathieu Duponchelle <MathieuDuponchelle@users.noreply.github.com>2016-12-20 22:00:17 +0100
committerJohn MacFarlane <jgm@berkeley.edu>2016-12-20 16:00:17 -0500
commit9e643720ec903f3b448bd2589a0c02c2514805ae (patch)
tree5ee8793c56f141821b0039920c2f7cd0b8b544f9 /src/cmark.h
parent29c46c5aeda66e9c454ac8d802e65692d0bab566 (diff)
More sourcepos! (#169)
* open_new_blocks: always create child before advancing offset * Source map * Extent's typology * In-depth python bindings
Diffstat (limited to 'src/cmark.h')
-rw-r--r--src/cmark.h60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/cmark.h b/src/cmark.h
index 6ed7eb0..034f0e6 100644
--- a/src/cmark.h
+++ b/src/cmark.h
@@ -2,6 +2,7 @@
#define CMARK_H
#include <stdio.h>
+#include <stdint.h>
#include <cmark_export.h>
#include <cmark_version.h>
@@ -65,6 +66,21 @@ typedef enum {
CMARK_NODE_LAST_INLINE = CMARK_NODE_IMAGE,
} cmark_node_type;
+typedef enum {
+ CMARK_EXTENT_NONE,
+ CMARK_EXTENT_OPENER,
+ CMARK_EXTENT_CLOSER,
+ CMARK_EXTENT_BLANK,
+ CMARK_EXTENT_CONTENT,
+ CMARK_EXTENT_PUNCTUATION,
+ CMARK_EXTENT_LINK_DESTINATION,
+ CMARK_EXTENT_LINK_TITLE,
+ CMARK_EXTENT_LINK_LABEL,
+ CMARK_EXTENT_REFERENCE_DESTINATION,
+ CMARK_EXTENT_REFERENCE_LABEL,
+ CMARK_EXTENT_REFERENCE_TITLE,
+} cmark_extent_type;
+
/* For backwards compatibility: */
#define CMARK_NODE_HEADER CMARK_NODE_HEADING
#define CMARK_NODE_HRULE CMARK_NODE_THEMATIC_BREAK
@@ -86,6 +102,7 @@ typedef enum {
typedef struct cmark_node cmark_node;
typedef struct cmark_parser cmark_parser;
typedef struct cmark_iter cmark_iter;
+typedef struct cmark_source_extent cmark_source_extent;
/**
* ## Custom memory allocator support
@@ -100,6 +117,11 @@ typedef struct cmark_mem {
void (*free)(void *);
} cmark_mem;
+/** Convenience function for bindings.
+ */
+CMARK_EXPORT
+void cmark_default_mem_free(void *ptr);
+
/**
* ## Creating and Destroying Nodes
*/
@@ -477,6 +499,11 @@ void cmark_parser_feed(cmark_parser *parser, const char *buffer, size_t len);
CMARK_EXPORT
cmark_node *cmark_parser_finish(cmark_parser *parser);
+/** Return a pointer to the first extent of the parser's source map
+ */
+CMARK_EXPORT
+cmark_source_extent *cmark_parser_get_first_source_extent(cmark_parser *parser);
+
/** Parse a CommonMark document in 'buffer' of length 'len'.
* Returns a pointer to a tree of nodes. The memory allocated for
* the node tree should be released using 'cmark_node_free'
@@ -492,6 +519,39 @@ cmark_node *cmark_parse_document(const char *buffer, size_t len, int options);
CMARK_EXPORT
cmark_node *cmark_parse_file(FILE *f, int options);
+/**
+ * ## Source map API
+ */
+
+/* Return the index, in bytes, of the start of this extent */
+CMARK_EXPORT
+uint64_t cmark_source_extent_get_start(cmark_source_extent *extent);
+
+/* Return the index, in bytes, of the stop of this extent. This
+ * index is not included in the extent*/
+CMARK_EXPORT
+uint64_t cmark_source_extent_get_stop(cmark_source_extent *extent);
+
+/* Return the extent immediately following 'extent' */
+CMARK_EXPORT
+cmark_source_extent *cmark_source_extent_get_next(cmark_source_extent *extent);
+
+/* Return the extent immediately preceding 'extent' */
+CMARK_EXPORT
+cmark_source_extent *cmark_source_extent_get_previous(cmark_source_extent *extent);
+
+/* Return the node 'extent' maps to */
+CMARK_EXPORT
+cmark_node *cmark_source_extent_get_node(cmark_source_extent *extent);
+
+/* Return the type of 'extent' */
+CMARK_EXPORT
+cmark_extent_type cmark_source_extent_get_type(cmark_source_extent *extent);
+
+/* Return a string representation of 'extent' */
+CMARK_EXPORT
+const char *cmark_source_extent_get_type_string(cmark_source_extent *extent);
+
/**
* ## Rendering
*/