Skip to content

Commit

Permalink
syntax-extension: add "priv" field.
Browse files Browse the repository at this point in the history
+ And pointer to a free function as well.
  • Loading branch information
MathieuDuponchelle committed Apr 27, 2016
1 parent d1492fc commit 963d548
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/cmark_extension_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions src/syntax_extension.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
2 changes: 2 additions & 0 deletions src/syntax_extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 963d548

Please sign in to comment.