diff options
author | Nick Wellnhofer <wellnhofer@aevum.de> | 2014-11-18 00:12:27 +0100 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2014-11-17 21:43:47 -0800 |
commit | 59fd5633da5395cbd3627af4a2ab855dc43ce1e0 (patch) | |
tree | 89da7422572556dc2ac911a78889431f14db107b /src/inlines.c | |
parent | c38944d4565b6266b3ab1fd6fd576710fdec420b (diff) |
Set prev, parent and last_child for inlines
Diffstat (limited to 'src/inlines.c')
-rw-r--r-- | src/inlines.c | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/src/inlines.c b/src/inlines.c index 078afd4..96b1792 100644 --- a/src/inlines.c +++ b/src/inlines.c @@ -193,6 +193,7 @@ static inline cmark_node* cmark_append_inlines(cmark_node* a, cmark_node* b) cur = cur->next; } cur->next = b; + b->prev = cur; return a; } @@ -395,12 +396,8 @@ static void process_emphasis(subject *subj, delimiter_stack *stack_bottom) // between the opener and closer emph = use_delims == 1 ? make_emph(inl->next) : make_strong(inl->next); emph->next = closer->first_inline; + emph->prev = inl; inl->next = emph; - tmp = emph->first_child; - while (tmp->next != NULL && tmp->next != closer->first_inline) { - tmp = tmp->next; - } - tmp->next = NULL; // if opener has 0 delims, remove it and its associated inline if (opener->delim_count == 0) { @@ -415,11 +412,27 @@ static void process_emphasis(subject *subj, delimiter_stack *stack_bottom) remove_delimiter(subj, opener); } + // fix tree structure + tmp = emph->first_child; + while (tmp->next != NULL && tmp->next != closer->first_inline) { + tmp->parent = emph; + tmp = tmp->next; + } + tmp->parent = emph; + if (tmp->next) { + tmp->next->prev = emph; + } + tmp->next = NULL; + emph->last_child = tmp; + // if closer has 0 delims, remove it and its associated inline if (closer->delim_count == 0) { // remove empty closer inline tmp = closer->first_inline; emph->next = tmp->next; + if (tmp->next) { + tmp->next->prev = emph; + } tmp->next = NULL; cmark_free_nodes(tmp); // remove closer from stack @@ -727,6 +740,15 @@ match: inl->as.link.url = url; inl->as.link.title = title; inl->next = NULL; + if (link_text) { + cmark_node *tmp; + link_text->prev = NULL; + for (tmp = link_text; tmp->next != NULL; tmp = tmp->next) { + tmp->parent = inl; + } + tmp->parent = inl; + inl->last_child = tmp; + } *last = inl; // process_emphasis will remove this delimiter and all later ones. |