Skip to content

Commit

Permalink
Add ancestor_extension field.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinbackhouse committed Mar 28, 2023
1 parent 763587e commit 78e1cc0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
8 changes: 8 additions & 0 deletions src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ struct cmark_node {

cmark_syntax_extension *extension;

/**
* Used during cmark_render() to cache the most recent non-NULL
* extension, if you go up the parent chain like this:
*
* node->parent->...parent->extension
*/
cmark_syntax_extension *ancestor_extension;

union {
int ref_ix;
int def_count;
Expand Down
13 changes: 6 additions & 7 deletions src/render.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,7 @@ static void S_out(cmark_renderer *renderer, cmark_node *node,
cmark_chunk remainder = cmark_chunk_literal("");
int k = renderer->buffer->size - 1;

cmark_syntax_extension *ext = NULL;
cmark_node *n = node;
while (n && !ext) {
ext = n->extension;
if (!ext)
n = n->parent;
}
cmark_syntax_extension *ext = node->ancestor_extension;
if (ext && !ext->commonmark_escape_func)
ext = NULL;

Expand Down Expand Up @@ -182,6 +176,11 @@ char *cmark_render(cmark_mem *mem, cmark_node *root, int options, int width,

while ((ev_type = cmark_iter_next(iter)) != CMARK_EVENT_DONE) {
cur = cmark_iter_get_node(iter);
if (cur->extension) {
cur->ancestor_extension = cur->extension;
} else if (cur->parent) {
cur->ancestor_extension = cur->parent->ancestor_extension;
}
if (!render_node(&renderer, cur, ev_type, options)) {
// a false value causes us to skip processing
// the node's contents. this is used for
Expand Down

0 comments on commit 78e1cc0

Please sign in to comment.