if (strncmp(&source[t->child->start + t->child->len], "\\begin", 6) != 0)
mmd_export_token_latex(out, source, t->child->mate, scratch);
- break;
+ break;
+ case PAIR_EMPH:
case PAIR_PAREN:
case PAIR_QUOTE_DOUBLE:
case PAIR_QUOTE_SINGLE:
case PAIR_STAR:
+ case PAIR_STRONG:
case PAIR_UL:
mmd_export_token_tree_latex(out, source, t->child, scratch);
break;
tokens_prune(t->next, t->next);
tokens_prune(closer->prev, closer->prev);
+
+ token_prune_graft(t, closer, PAIR_STRONG);
} else {
t->type = EMPH_START;
closer->type = EMPH_STOP;
+ token_prune_graft(t, closer, PAIR_EMPH);
}
break;
last = first;
}
-
walker = walker->next;
while (walker) {
switch (walker->type) {
case PIPE:
- if (row->child == first) {
- row->child = token_prune_graft(first, last, TABLE_CELL);
- } else {
- token_prune_graft(first, last, TABLE_CELL);
- }
+ token_prune_graft(first, last, TABLE_CELL);
first = NULL;
last = NULL;
walker->type = TABLE_DIVIDER;
}
if (first) {
- if (row->child == first) {
- row->child = token_prune_graft(first, last, TABLE_CELL);
- } else {
- token_prune_graft(first, last, TABLE_CELL);
- }
+ token_prune_graft(first, last, TABLE_CELL);
}
}
}
+/// Duplicate an existing token
+token * token_copy(token * original) {
+#ifdef kUseObjectPool
+ token * t = pool_allocate_object(token_pool);
+#else
+ token * t = malloc(sizeof(token));
+#endif
+
+ if (t) {
+ * t = * original;
+ }
+
+ return t;
+}
+
+
/// Create a parent for a chain of tokens
token * token_new_parent(token * child, unsigned short type) {
if (child == NULL) {
token * prev = first->prev;
token * next = last->next;
- // If we are head of chain, remember tail
- token * tail = NULL;
- if (prev == NULL)
- tail = first->tail;
-
-
- token * container = token_new(container_type, first->start, last->start + last->len - first->start);
-
- container->child = first;
- container->next = next;
- container->prev = prev;
- container->can_close = 0;
- container->can_open = 0;
-
- if (tail)
- container->tail = tail;
-
- if (prev)
- prev->next = container;
+ // Duplicate first token -- this will be child of new container
+ token * new_child = token_copy(first);
+ new_child->prev = NULL;
+ new_child->tail = last;
+ if (new_child->next) {
+ new_child->next->prev = new_child;
+ }
- first->prev = NULL;
+ // Swap last (if necessary)
+ if (first == last)
+ last = new_child;
+
+ // Existing first token will be new container
+ first->child = new_child;
+ first->type = container_type;
+ first->len = last->start + last->len - first->start;
+ first->next = next;
+ first->can_close = 0;
+ first->can_open = 0;
+
+ // Fix mating
+ if (first->mate) {
+ first->mate = NULL;
+ new_child->mate->mate = new_child;
+ }
+ // Disconnect last token
last->next = NULL;
if (next)
- next->prev = container;
+ next->prev = first;
- return container;
+ return first;
}