Exemplo n.º 1
0
/* extract_references -- go through node tree and find elements we need to reference;
   e.g. links, images, citations, footnotes 
   Copy them from main parse tree */
void extract_references(node *list, scratch_pad *scratch) {
	node *temp;
	char * temp_str;
	link_data *l;
	
	while (list != NULL) {
		switch (list->key) {
			case LINKREFERENCE:
				l = list->link_data;
				temp_str = lower_string(l->label);

				temp = mk_link(list->children, temp_str, l->source, l->title, NULL);
				temp->link_data->attr = copy_node_tree(l->attr);

				/* store copy of link reference */
				scratch->links = cons(temp, scratch->links);
				
				free(temp_str);

				break;
			case NOTESOURCE:
			case GLOSSARYSOURCE:
				temp = copy_node(list);
				scratch->notes = cons(temp, scratch->notes);
				break;
			case H1: case H2: case H3: case H4: case H5: case H6:
				if ((list->children->key != AUTOLABEL) && !(scratch->extensions & EXT_NO_LABELS)
				&& !(scratch->extensions & EXT_COMPATIBILITY)) {
					char *label = label_from_node_tree(list->children);

					/* create a label from header */
					temp = mk_autolink(label);
					scratch->links = cons(temp, scratch->links);
					free(label);
				}
				break;
			case TABLE:
				if (list->children->key != TABLELABEL) {
					char *label = label_from_node(list->children);

					/* create a label from header */
					temp = mk_autolink(label);
					scratch->links = cons(temp, scratch->links);
					free(label);
				}

				break;
			case HEADINGSECTION:
			case RAW:
			case LIST:
				extract_references(list->children, scratch);
				break;
			default:
				break;
		}
		list = list->next;
	}
}
Exemplo n.º 2
0
/* extract_references -- go through node tree and find elements we need to reference;
   e.g. links, images, citations, footnotes 
   Remove them from main parse tree */
void extract_references(node *list, scratch_pad *scratch) {
	/* TODO: Will these all be top level elements?  What about RAW?? */
	node *temp;
	node *last = NULL;
	link_data *l;
	
	while (list != NULL) {
		switch (list->key) {
			case LINKREFERENCE:
				l = list->link_data;
				temp = mk_link(list->children, l->label, l->source, l->title, l->attr);
				
				/* store copy of link reference */
				scratch->links = cons(temp, scratch->links);
				
				/* Disconnect from children so not duplicated */
				l->attr = NULL;
				
				if (last != NULL) {
					/* remove this node from tree */
					last->next = list->next;
					free_link_data(list->link_data);
					free(list);
					list = last->next;
					continue;
				} else {
				}
				break;
			case NOTESOURCE:
				if (last != NULL) {
					last->next = list->next;
					scratch->notes = cons(list, scratch->notes);
					list = last->next;
					continue;
				}
				break;
			case GLOSSARYSOURCE:
				if (last != NULL) {
					last->next = list->next;
					scratch->notes = cons(list, scratch->notes);
					list = last->next;
					continue;
				}
				break;
			case H1: case H2: case H3: case H4: case H5: case H6:
				if ((list->children->key != AUTOLABEL) && !(scratch->extensions & EXT_NO_LABELS)) {
					char *label = label_from_node_tree(list->children);

					/* create a label from header */
					temp = mk_autolink(label);
					scratch->links = cons(temp, scratch->links);
					free(label);
				}
				break;
			case TABLE:
				if (list->children->key != TABLELABEL) {
					char *label = label_from_node(list->children);

					/* create a label from header */
					temp = mk_autolink(label);
					scratch->links = cons(temp, scratch->links);
					free(label);
				}

				break;
			case HEADINGSECTION:
				extract_references(list->children, scratch);
				break;
			default:
				break;
		}
		last = list;
		list = list->next;
	}
}