- Commit
- c3d897c6c86607493004e0ccdc2c7436eba9e30e
- Parent
- da6e2ffafd9a988aa04ffafd7c1118891e3d97c1
- Author
- John MacFarlane <jgm@berkeley.edu>
- Date
Nonrecursive rewrite of ends_with_blank_line.
Closes #286.
My personal build of CMark ✏️
Nonrecursive rewrite of ends_with_blank_line.
Closes #286.
1 file changed, 11 insertions, 7 deletions
Status | File Name | N° Changes | Insertions | Deletions |
Modified | src/blocks.c | 18 | 11 | 7 |
diff --git a/src/blocks.c b/src/blocks.c @@ -147,14 +147,18 @@ static void remove_trailing_blank_lines(cmark_strbuf *ln) // if needed into lists and sublists. static bool ends_with_blank_line(cmark_node* node) { - if (node->last_line_blank) { - return true; - } - if ((node->type == NODE_LIST || node->type == NODE_ITEM) && node->last_child) { - return ends_with_blank_line(node->last_child); - } else { - return false; + cmark_node *cur = node; + while (cur != NULL) { + if (cur->last_line_blank) { + return true; + } + if (cur->type == NODE_LIST || cur->type == NODE_ITEM) { + cur = cur->last_child; + } else { + cur = NULL; + } } + return false; } // Break out of all containing lists