Exemple #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;
	}
}
Exemple #2
0
/* print_html_endnotes */
void print_html_endnotes(GString *out, scratch_pad *scratch) {
	int counter = 0;
	int random;
	node *reversed = copy_node_tree(scratch->used_notes);

	reversed = reverse_list(reversed);

	scratch->printing_notes = 1;
	
	node *note = reversed;
#ifdef DEBUG_ON
	fprintf(stderr, "start endnotes\n");
#endif
	
	if ((note == NULL) || ((note->key == KEY_COUNTER) && (note->next == NULL))) {
		free_node_tree(reversed);
		return;
	}

#ifdef DEBUG_ON
	fprintf(stderr, "there are endnotes to print\n");
#endif

	pad(out,2, scratch);
	g_string_append_printf(out, "<div class=\"footnotes\">\n<hr />\n<ol>");
	while ( note != NULL) {
		if (note->key == KEY_COUNTER) {
			note = note->next;
			continue;
		}
		
		counter++;
		pad(out, 1, scratch);
		
		if (scratch->extensions & EXT_RANDOM_FOOT) {
			srand(scratch->random_seed_base + counter);
			random = rand() % 99999 + 1;
		} else {
			random = counter;
		}
		
		if (note->key == CITATIONSOURCE) {
			g_string_append_printf(out, "<li id=\"fn:%d\" class=\"citation\"><span class=\"citekey\" style=\"display:none\">%s</span>", 
				random, note->str);
		} else {
			g_string_append_printf(out, "<li id=\"fn:%d\">\n", random);
		}
		
		
		scratch->padded = 2;
		if ((note->key == NOTESOURCE) || (note->key == GLOSSARYSOURCE))
			scratch->footnote_to_print = counter;
		scratch->footnote_para_counter = tree_contains_key_count(note->children,PARA);
		print_html_node(out, note, scratch);
		pad(out, 1, scratch);
		g_string_append_printf(out, "</li>");
		
		note = note->next;
	}
	pad(out,1, scratch);
	g_string_append_printf(out, "</ol>\n</div>\n");
	scratch->padded = 0;

	free_node_tree(reversed);
#ifdef DEBUG_ON
	fprintf(stderr, "finish endnotes\n");
#endif
}