From 963d5480bba988f3be1b8d12eac2d1583458217d Mon Sep 17 00:00:00 2001 From: Mathieu Duponchelle Date: Sun, 3 Apr 2016 00:59:11 +0200 Subject: [PATCH] syntax-extension: add "priv" field. + And pointer to a free function as well. --- src/cmark_extension_api.h | 11 +++++++++++ src/syntax_extension.c | 11 +++++++++++ src/syntax_extension.h | 2 ++ 3 files changed, 24 insertions(+) diff --git a/src/cmark_extension_api.h b/src/cmark_extension_api.h index ee2cd23f3..941d82e78 100644 --- a/src/cmark_extension_api.h +++ b/src/cmark_extension_api.h @@ -97,6 +97,10 @@ typedef struct cmark_plugin cmark_plugin; * * Finally, the extension should return NULL if its scan didn't * match its syntax rules. + * + * The extension can store whatever private data it might need + * with 'cmark_syntax_extension_set_private', + * and optionally define a free function for this data. */ typedef struct cmark_syntax_extension cmark_syntax_extension; @@ -249,6 +253,13 @@ CMARK_EXPORT void cmark_syntax_extension_set_special_inline_chars(cmark_syntax_extension *extension, cmark_llist *special_chars); +/** See the documentation for 'cmark_syntax_extension' + */ +CMARK_EXPORT +void cmark_syntax_extension_set_private(cmark_syntax_extension *extension, + void *priv, + cmark_free_func free_func); + /** Return the index of the line currently being parsed, starting with 1. */ CMARK_EXPORT diff --git a/src/syntax_extension.c b/src/syntax_extension.c index 04c0868e5..941d76184 100644 --- a/src/syntax_extension.c +++ b/src/syntax_extension.c @@ -5,6 +5,10 @@ #include "buffer.h" void cmark_syntax_extension_free(cmark_syntax_extension *extension) { + if (extension->free_function && extension->priv) { + extension->free_function(extension->priv); + } + cmark_llist_free(extension->special_inline_chars); free(extension->name); free(extension); @@ -42,3 +46,10 @@ void cmark_syntax_extension_set_special_inline_chars(cmark_syntax_extension *ext cmark_llist *special_chars) { extension->special_inline_chars = special_chars; } + +void cmark_syntax_extension_set_private(cmark_syntax_extension *extension, + void *priv, + cmark_free_func free_func) { + extension->priv = priv; + extension->free_function = free_func; +} diff --git a/src/syntax_extension.h b/src/syntax_extension.h index f9af1f12c..f46a7d2fe 100644 --- a/src/syntax_extension.h +++ b/src/syntax_extension.h @@ -11,6 +11,8 @@ struct cmark_syntax_extension { cmark_inline_from_delim_func insert_inline_from_delim; cmark_llist * special_inline_chars; char * name; + void * priv; + cmark_free_func free_function; }; #endif