ext/commonmarker/inlines.c in commonmarker-0.23.5 vs ext/commonmarker/inlines.c in commonmarker-0.23.6

- old
+ new

@@ -39,10 +39,12 @@ cmark_node *inl_text; bufsize_t position; bool image; bool active; bool bracket_after; + bool in_bracket_image0; + bool in_bracket_image1; } bracket; typedef struct subject{ cmark_mem *mem; cmark_chunk input; @@ -514,18 +516,25 @@ static void push_bracket(subject *subj, bool image, cmark_node *inl_text) { bracket *b = (bracket *)subj->mem->calloc(1, sizeof(bracket)); if (subj->last_bracket != NULL) { subj->last_bracket->bracket_after = true; + b->in_bracket_image0 = subj->last_bracket->in_bracket_image0; + b->in_bracket_image1 = subj->last_bracket->in_bracket_image1; } b->image = image; b->active = true; b->inl_text = inl_text; b->previous = subj->last_bracket; b->previous_delimiter = subj->last_delim; b->position = subj->pos; b->bracket_after = false; + if (image) { + b->in_bracket_image1 = true; + } else { + b->in_bracket_image0 = true; + } subj->last_bracket = b; } // Assumes the subject has a c at the current position. static cmark_node *handle_delim(subject *subj, unsigned char c, bool smart) { @@ -1252,10 +1261,21 @@ opener->active = false; } } opener = opener->previous; } + bool in_bracket_image1 = false; + if (opener) { + in_bracket_image1 = opener->in_bracket_image1; + } + bracket *opener2 = subj->last_bracket; + while (opener2 != opener) { + if (opener2->image) { + opener2->in_bracket_image1 = in_bracket_image1; + } + opener2 = opener2->previous; + } } return NULL; } @@ -1660,13 +1680,18 @@ cmark_chunk *cmark_inline_parser_get_chunk(cmark_inline_parser *parser) { return &parser->input; } int cmark_inline_parser_in_bracket(cmark_inline_parser *parser, int image) { - for (bracket *b = parser->last_bracket; b; b = b->previous) - if (b->active && b->image == (image != 0)) - return 1; - return 0; + bracket *b = parser->last_bracket; + if (!b) { + return 0; + } + if (image != 0) { + return b->in_bracket_image1; + } else { + return b->in_bracket_image0; + } } void cmark_node_unput(cmark_node *node, int n) { node = node->last_child; while (n > 0 && node && node->type == CMARK_NODE_TEXT) {