multimarkdown 4.5.0.r1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data/LICENSE +75 -0
  2. data/MultiMarkdown-4/GLibFacade.c +294 -0
  3. data/MultiMarkdown-4/GLibFacade.h +95 -0
  4. data/MultiMarkdown-4/beamer.c +179 -0
  5. data/MultiMarkdown-4/beamer.h +11 -0
  6. data/MultiMarkdown-4/critic.c +111 -0
  7. data/MultiMarkdown-4/critic.h +15 -0
  8. data/MultiMarkdown-4/glib.h +11 -0
  9. data/MultiMarkdown-4/html.c +1060 -0
  10. data/MultiMarkdown-4/html.h +14 -0
  11. data/MultiMarkdown-4/latex.c +1137 -0
  12. data/MultiMarkdown-4/latex.h +16 -0
  13. data/MultiMarkdown-4/libMultiMarkdown.h +156 -0
  14. data/MultiMarkdown-4/lyx.c +2163 -0
  15. data/MultiMarkdown-4/lyx.h +36 -0
  16. data/MultiMarkdown-4/lyxbeamer.c +267 -0
  17. data/MultiMarkdown-4/lyxbeamer.h +11 -0
  18. data/MultiMarkdown-4/memoir.c +79 -0
  19. data/MultiMarkdown-4/memoir.h +10 -0
  20. data/MultiMarkdown-4/multimarkdown.c +483 -0
  21. data/MultiMarkdown-4/odf.c +1201 -0
  22. data/MultiMarkdown-4/odf.h +18 -0
  23. data/MultiMarkdown-4/opml.c +188 -0
  24. data/MultiMarkdown-4/opml.h +15 -0
  25. data/MultiMarkdown-4/parse_utilities.c +752 -0
  26. data/MultiMarkdown-4/parser.c +15582 -0
  27. data/MultiMarkdown-4/parser.h +186 -0
  28. data/MultiMarkdown-4/rng.c +117 -0
  29. data/MultiMarkdown-4/rtf.c +648 -0
  30. data/MultiMarkdown-4/rtf.h +17 -0
  31. data/MultiMarkdown-4/strtok.c +56 -0
  32. data/MultiMarkdown-4/strtok.h +9 -0
  33. data/MultiMarkdown-4/text.c +53 -0
  34. data/MultiMarkdown-4/text.h +11 -0
  35. data/MultiMarkdown-4/transclude.c +213 -0
  36. data/MultiMarkdown-4/transclude.h +26 -0
  37. data/MultiMarkdown-4/writer.c +576 -0
  38. data/MultiMarkdown-4/writer.h +34 -0
  39. data/README.md +70 -0
  40. data/Rakefile +85 -0
  41. data/bin/ruby_multi_markdown +128 -0
  42. data/ext/extconf.h +3 -0
  43. data/ext/extconf.rb +17 -0
  44. data/ext/multi_markdown.c +100 -0
  45. data/lib/multi_markdown.bundle +0 -0
  46. data/lib/multi_markdown.rb +88 -0
  47. data/lib/multi_markdown/version.rb +6 -0
  48. data/lib/multimarkdown.rb +1 -0
  49. data/multi_markdown.gemspec +37 -0
  50. data/test/multi_markdown_test.rb +64 -0
  51. metadata +119 -0
@@ -0,0 +1,179 @@
1
+ /*
2
+
3
+ beamer.c -- Beamer add-on to LaTeX writer
4
+
5
+ (c) 2013 Fletcher T. Penney (http://fletcherpenney.net/).
6
+
7
+ This program is free software; you can redistribute it and/or modify
8
+ it under the terms of the GNU General Public License or the MIT
9
+ license. See LICENSE for details.
10
+
11
+ This program is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ GNU General Public License for more details.
15
+
16
+ */
17
+
18
+ #include "beamer.h"
19
+
20
+ /* print_beamer_node_tree -- convert node tree to LaTeX */
21
+ void print_beamer_node_tree(GString *out, node *list, scratch_pad *scratch) {
22
+ while (list != NULL) {
23
+ print_beamer_node(out, list, scratch);
24
+ list = list->next;
25
+ }
26
+ }
27
+
28
+ /* print_beamer_node -- convert given node to LaTeX and append */
29
+ void print_beamer_node(GString *out, node *n, scratch_pad *scratch) {
30
+ int lev;
31
+ char *temp;
32
+
33
+ /* If we are forcing a complete document, and METADATA isn't the first thing,
34
+ we need to close <head> */
35
+ if ((scratch->extensions & EXT_COMPLETE)
36
+ && !(scratch->extensions & EXT_HEAD_CLOSED) &&
37
+ !((n->key == FOOTER) || (n->key == METADATA))) {
38
+ pad(out, 2, scratch);
39
+ scratch->extensions = scratch->extensions | EXT_HEAD_CLOSED;
40
+ }
41
+ switch (n->key) {
42
+ case FOOTER:
43
+ print_beamer_endnotes(out, scratch);
44
+ g_string_append_printf(out, "\\mode<all>\n");
45
+ if (scratch->latex_footer != NULL) {
46
+ pad(out, 2, scratch);
47
+ g_string_append_printf(out,"\\input{%s}\n", scratch->latex_footer);
48
+ }
49
+ if (scratch->extensions & EXT_COMPLETE) {
50
+ g_string_append_printf(out, "\n\\end{document}");
51
+ }
52
+ g_string_append_printf(out, "\\mode*\n");
53
+ break;
54
+ case LISTITEM:
55
+ pad(out, 1, scratch);
56
+ g_string_append_printf(out, "\\item<+-> ");
57
+ scratch->padded = 2;
58
+ print_latex_node_tree(out, n->children, scratch);
59
+ g_string_append_printf(out, "\n");
60
+ break;
61
+ case HEADINGSECTION:
62
+ if (n->children->key -H1 + scratch->baseheaderlevel == 3) {
63
+ pad(out, 2, scratch);
64
+ g_string_append_printf(out, "\\begin{frame}");
65
+ /* TODO: Fix this */
66
+ if (tree_contains_key(n->children,VERBATIM)) {
67
+ g_string_append_printf(out, "[fragile]");
68
+ }
69
+ scratch->padded = 0;
70
+ print_beamer_node_tree(out, n->children, scratch);
71
+ g_string_append_printf(out, "\n\n\\end{frame}\n\n");
72
+ scratch->padded = 2;
73
+ } else if (n->children->key -H1 + scratch->baseheaderlevel == 4) {
74
+ pad(out, 1, scratch);
75
+ g_string_append_printf(out, "\\mode<article>{\n");
76
+ scratch->padded = 0;
77
+ print_beamer_node_tree(out, n->children->next, scratch);
78
+ g_string_append_printf(out, "\n\n}\n\n");
79
+ scratch->padded = 2;
80
+ } else {
81
+ print_beamer_node_tree(out, n->children, scratch);
82
+ }
83
+ break;
84
+ case H1: case H2: case H3: case H4: case H5: case H6:
85
+ pad(out, 2, scratch);
86
+ lev = n->key - H1 + scratch->baseheaderlevel; /* assumes H1 ... H6 are in order */
87
+ switch (lev) {
88
+ case 1:
89
+ g_string_append_printf(out, "\\part{");
90
+ break;
91
+ case 2:
92
+ g_string_append_printf(out, "\\section{");
93
+ break;
94
+ case 3:
95
+ g_string_append_printf(out, "\\frametitle{");
96
+ break;
97
+ default:
98
+ g_string_append_printf(out, "\\emph{");
99
+ break;
100
+ }
101
+ /* generate a label for each header (MMD);
102
+ don't allow footnotes since invalid here */
103
+ scratch->no_latex_footnote = TRUE;
104
+ if (n->children->key == AUTOLABEL) {
105
+ temp = label_from_string(n->children->str);
106
+ print_latex_node_tree(out, n->children->next, scratch);
107
+ g_string_append_printf(out, "}\n\\label{%s}", temp);
108
+ free(temp);
109
+ } else {
110
+ print_latex_node_tree(out, n->children, scratch);
111
+ temp = label_from_node_tree(n->children);
112
+ g_string_append_printf(out, "}\n\\label{%s}", temp);
113
+ free(temp);
114
+ }
115
+ scratch->no_latex_footnote = FALSE;
116
+ scratch->padded = 0;
117
+ break;
118
+ default:
119
+ /* most things are not changed for memoir output */
120
+ print_latex_node(out, n, scratch);
121
+ }
122
+ }
123
+
124
+ /* print_beamer_endnotes */
125
+ void print_beamer_endnotes(GString *out, scratch_pad *scratch) {
126
+ scratch->used_notes = reverse_list(scratch->used_notes);
127
+ node *note = scratch->used_notes;
128
+ #ifdef DEBUG_ON
129
+ fprintf(stderr, "start endnotes\n");
130
+ #endif
131
+
132
+ if ((note == NULL) || ((note->key == KEY_COUNTER) && (note->next == NULL)))
133
+ return;
134
+ while (note != NULL) {
135
+ if (note->key == CITATIONSOURCE)
136
+ break;
137
+ note = note->next;
138
+ }
139
+
140
+ if (note == NULL)
141
+ return;
142
+
143
+ note = scratch->used_notes;
144
+
145
+ /* TODO: need CITATIONSOURCE to print bibliography */
146
+ #ifdef DEBUG_ON
147
+ fprintf(stderr, "there are endnotes to print\n");
148
+ #endif
149
+
150
+ pad(out, 2, scratch);
151
+ g_string_append_printf(out, "\\part{Bibliography}\n\\begin{frame}[allowframebreaks]\n\\frametitle{Bibliography}\n\\def\\newblock{}\n\\begin{thebibliography}{0}\n");
152
+ while ( note != NULL) {
153
+ if (note->key == KEY_COUNTER) {
154
+ note = note->next;
155
+ continue;
156
+ }
157
+
158
+ pad(out, 1, scratch);
159
+
160
+ if (note->key == CITATIONSOURCE) {
161
+ g_string_append_printf(out, "\\bibitem{%s}\n", note->str);
162
+ scratch->padded = 2;
163
+
164
+ print_latex_node(out, note, scratch);
165
+ pad(out, 1, scratch);
166
+ scratch->padded = 1;
167
+ } else {
168
+ /* footnotes handled elsewhere */
169
+ }
170
+
171
+ note = note->next;
172
+ }
173
+ pad(out,2, scratch);
174
+ g_string_append_printf(out, "\\end{thebibliography}\n\\end{frame}\n\n");
175
+ scratch->padded = 0;
176
+ #ifdef DEBUG_ON
177
+ fprintf(stderr, "finish endnotes\n");
178
+ #endif
179
+ }
@@ -0,0 +1,11 @@
1
+ #ifndef BEAMER_PARSER_H
2
+ #define BEAMER_PARSER_H
3
+
4
+ #include "parser.h"
5
+ #include "latex.h"
6
+
7
+ void print_beamer_node_tree(GString *out, node *list, scratch_pad *scratch);
8
+ void print_beamer_node(GString *out, node *n, scratch_pad *scratch);
9
+ void print_beamer_endnotes(GString *out, scratch_pad *scratch);
10
+
11
+ #endif
@@ -0,0 +1,111 @@
1
+ /*
2
+
3
+ critic.c -- CriticMarkup preprocessor
4
+
5
+ <http://criticmarkup.com>
6
+
7
+ (c) 2013 Fletcher T. Penney (http://fletcherpenney.net/).
8
+
9
+ This program is free software; you can redistribute it and/or modify
10
+ it under the terms of the GNU General Public License or the MIT
11
+ license. See LICENSE for details.
12
+
13
+ This program is distributed in the hope that it will be useful,
14
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ GNU General Public License for more details.
17
+
18
+ */
19
+
20
+ #include "critic.h"
21
+
22
+ void print_critic_accept_node_tree(GString *out, node *list, scratch_pad *scratch) {
23
+ while (list != NULL) {
24
+ print_critic_accept_node(out, list, scratch);
25
+ list = list->next;
26
+ }
27
+ }
28
+
29
+ void print_critic_reject_node_tree(GString *out, node *list, scratch_pad *scratch) {
30
+ while (list != NULL) {
31
+ print_critic_reject_node(out, list, scratch);
32
+ list = list->next;
33
+ }
34
+ }
35
+
36
+ void print_critic_html_highlight_node_tree(GString *out, node *list, scratch_pad *scratch) {
37
+ while (list != NULL) {
38
+ print_critic_html_highlight_node(out, list, scratch);
39
+ list = list->next;
40
+ }
41
+ }
42
+
43
+ void print_critic_accept_node(GString *out, node *n, scratch_pad *scratch) {
44
+ if (n == NULL)
45
+ return;
46
+
47
+ switch (n->key) {
48
+ case LIST:
49
+ case CRITICSUBSTITUTION:
50
+ print_critic_accept_node_tree(out, n->children, scratch);
51
+ break;
52
+ case CRITICDELETION:
53
+ case CRITICCOMMENT:
54
+ break;
55
+ case CRITICHIGHLIGHT:
56
+ case CRITICADDITION:
57
+ default:
58
+ g_string_append_printf(out,"%s",n->str);
59
+ break;
60
+ }
61
+ }
62
+
63
+ void print_critic_reject_node(GString *out, node *n, scratch_pad *scratch) {
64
+ if (n == NULL)
65
+ return;
66
+
67
+ switch (n->key) {
68
+ case LIST:
69
+ case CRITICSUBSTITUTION:
70
+ print_critic_reject_node_tree(out, n->children, scratch);
71
+ break;
72
+ case CRITICADDITION:
73
+ case CRITICCOMMENT:
74
+ break;
75
+ case CRITICHIGHLIGHT:
76
+ case CRITICDELETION:
77
+ default:
78
+ g_string_append_printf(out,"%s",n->str);
79
+ break;
80
+ }
81
+ }
82
+
83
+ void print_critic_html_highlight_node(GString *out, node *n, scratch_pad *scratch) {
84
+ if (n == NULL)
85
+ return;
86
+
87
+ switch (n->key) {
88
+ case LIST:
89
+ print_critic_html_highlight_node_tree(out, n->children, scratch);
90
+ break;
91
+ case CRITICSUBSTITUTION:
92
+ print_critic_html_highlight_node_tree(out, n->children, scratch);
93
+ break;
94
+ case CRITICADDITION:
95
+ g_string_append_printf(out,"<ins>%s</ins>",n->str);
96
+ break;
97
+ case CRITICCOMMENT:
98
+ /* Hide comments for now */
99
+ /* g_string_append_printf(out, "<span class=\"critic comment\">%s</span>", n->str); */
100
+ break;
101
+ case CRITICHIGHLIGHT:
102
+ g_string_append_printf(out,"<mark>%s</mark>",n->str);
103
+ break;
104
+ case CRITICDELETION:
105
+ g_string_append_printf(out,"<del>%s</del>",n->str);
106
+ break;
107
+ default:
108
+ g_string_append_printf(out,"%s",n->str);
109
+ break;
110
+ }
111
+ }
@@ -0,0 +1,15 @@
1
+ #ifndef CRITIC_PARSER_H
2
+ #define CRITIC_PARSER_H
3
+
4
+ #include "parser.h"
5
+ #include "writer.h"
6
+
7
+
8
+ void print_critic_accept_node_tree(GString *out, node *list, scratch_pad *scratch);
9
+ void print_critic_reject_node_tree(GString *out, node *list, scratch_pad *scratch);
10
+ void print_critic_html_highlight_node_tree(GString *out, node *list, scratch_pad *scratch);
11
+ void print_critic_accept_node(GString *out, node *list, scratch_pad *scratch);
12
+ void print_critic_reject_node(GString *out, node *list, scratch_pad *scratch);
13
+ void print_critic_html_highlight_node(GString *out, node *list, scratch_pad *scratch);
14
+
15
+ #endif
@@ -0,0 +1,11 @@
1
+ /*
2
+ * glib.h
3
+ * MultiMarkdown
4
+ *
5
+ * Created by Daniel Jalkut on 7/26/11.
6
+ * Copyright 2011 __MyCompanyName__. All rights reserved.
7
+ *
8
+ */
9
+
10
+ /* Just a dummy file to keep the glib-dependent sources compiling as we would hope */
11
+ #include "GLibFacade.h"
@@ -0,0 +1,1060 @@
1
+ /*
2
+
3
+ html.c -- HTML writer
4
+
5
+ (c) 2013 Fletcher T. Penney (http://fletcherpenney.net/).
6
+
7
+ Derived from peg-multimarkdown, which was forked from peg-markdown,
8
+ which is (c) 2008 John MacFarlane (jgm at berkeley dot edu), and
9
+ licensed under GNU GPL or MIT.
10
+
11
+ This program is free software; you can redistribute it and/or modify
12
+ it under the terms of the GNU General Public License or the MIT
13
+ license. See LICENSE for details.
14
+
15
+ This program is distributed in the hope that it will be useful,
16
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
+ GNU General Public License for more details.
19
+
20
+ */
21
+
22
+ #include "html.h"
23
+
24
+ bool is_html_complete_doc(node *meta);
25
+ void print_col_group(GString *out,scratch_pad *scratch);
26
+
27
+
28
+ /* print_html_node_tree -- convert node tree to HTML */
29
+ void print_html_node_tree(GString *out, node *list, scratch_pad *scratch) {
30
+ while (list != NULL) {
31
+ print_html_node(out, list, scratch);
32
+ list = list->next;
33
+ }
34
+ }
35
+
36
+ /* print_html_node -- convert given node to HTML and append */
37
+ void print_html_node(GString *out, node *n, scratch_pad *scratch) {
38
+ node *temp_node;
39
+ link_data *temp_link_data = NULL;
40
+ char *temp;
41
+ int lev;
42
+ int random;
43
+ char temp_type;
44
+ char *width = NULL;
45
+ char *height = NULL;
46
+ GString *temp_str;
47
+
48
+ if (n == NULL)
49
+ return;
50
+
51
+ /* debugging statement */
52
+ #ifdef DEBUG_ON
53
+ fprintf(stderr, "print_html_node: %d\n",n->key);
54
+ #endif
55
+
56
+ /* If we are forcing a complete document, and METADATA isn't the first thing,
57
+ we need to close <head> */
58
+ if ((scratch->extensions & EXT_COMPLETE)
59
+ && !(scratch->extensions & EXT_HEAD_CLOSED) &&
60
+ !((n->key == FOOTER) || (n->key == METADATA))) {
61
+ g_string_append_printf(out, "</head>\n<body>\n");
62
+ scratch->extensions = scratch->extensions | EXT_HEAD_CLOSED;
63
+ }
64
+ switch (n->key) {
65
+ case NO_TYPE:
66
+ break;
67
+ case LIST:
68
+ print_html_node_tree(out,n->children,scratch);
69
+ break;
70
+ case STR:
71
+ print_html_string(out,n->str, scratch);
72
+ break;
73
+ case SPACE:
74
+ g_string_append_printf(out,"%s",n->str);
75
+ break;
76
+ case PLAIN:
77
+ pad(out,1, scratch);
78
+ print_html_node_tree(out,n->children, scratch);
79
+ scratch->padded = 0;
80
+ break;
81
+ case PARA:
82
+ pad(out, 2, scratch);
83
+ g_string_append_printf(out, "<p>");
84
+ print_html_node_tree(out,n->children,scratch);
85
+ if (scratch->footnote_to_print != 0){
86
+ scratch->footnote_para_counter --;
87
+ if (scratch->footnote_para_counter == 0) {
88
+ if (scratch->extensions & EXT_RANDOM_FOOT) {
89
+ srand(scratch->random_seed_base + scratch->footnote_to_print);
90
+ random = rand() % 99999 + 1;
91
+ } else {
92
+ random = scratch->footnote_to_print;
93
+ }
94
+
95
+ g_string_append_printf(out, " <a href=\"#fnref:%d\" title=\"return to article\" class=\"reversefootnote\">&#160;&#8617;</a>", random);
96
+ scratch->footnote_to_print = 0;
97
+ }
98
+ }
99
+ g_string_append_printf(out, "</p>");
100
+ scratch->padded = 0;
101
+ break;
102
+ case HRULE:
103
+ pad(out, 2, scratch);
104
+ g_string_append_printf(out, "<hr />");
105
+ scratch->padded = 0;
106
+ break;
107
+ case HTMLBLOCK:
108
+ pad(out, 2, scratch);
109
+ g_string_append_printf(out, "%s", n->str);
110
+ scratch->padded = 0;
111
+ break;
112
+ case VERBATIM:
113
+ pad(out, 2, scratch);
114
+ if ((n->children != NULL) && (n->children->key == VERBATIMTYPE)) {
115
+ trim_trailing_whitespace(n->children->str);
116
+ if (strlen(n->children->str) > 0)
117
+ g_string_append_printf(out, "<pre><code class=\"%s\">", n->children->str);
118
+ else
119
+ g_string_append_printf(out, "%s", "<pre><code>");
120
+ } else {
121
+ g_string_append_printf(out, "%s", "<pre><code>");
122
+ }
123
+ print_html_string(out, n->str, scratch);
124
+ g_string_append_printf(out, "%s", "</code></pre>");
125
+ scratch->padded = 0;
126
+ break;
127
+ case BULLETLIST:
128
+ pad(out, 2, scratch);
129
+ g_string_append_printf(out, "%s", "<ul>");
130
+ scratch->padded = 0;
131
+ print_html_node_tree(out, n->children, scratch);
132
+ pad(out, 1, scratch);
133
+ g_string_append_printf(out, "%s", "</ul>");
134
+ scratch->padded = 0;
135
+ break;
136
+ case ORDEREDLIST:
137
+ pad(out, 2, scratch);
138
+ g_string_append_printf(out, "%s", "<ol>");
139
+ scratch->padded = 0;
140
+ print_html_node_tree(out, n->children, scratch);
141
+ pad(out, 1, scratch);
142
+ g_string_append_printf(out, "</ol>");
143
+ scratch->padded = 0;
144
+ break;
145
+ case LISTITEM:
146
+ pad(out, 1, scratch);
147
+ g_string_append_printf(out, "<li>");
148
+ scratch->padded = 2;
149
+ print_html_node_tree(out, n->children, scratch);
150
+ g_string_append_printf(out, "</li>");
151
+ scratch->padded = 0;
152
+ break;
153
+ case METADATA:
154
+ /* Not if snippet only */
155
+ if (scratch->extensions & EXT_SNIPPET) {
156
+ print_html_node_tree(out,n->children, scratch);
157
+ break;
158
+ }
159
+
160
+ if (!(scratch->extensions & EXT_COMPLETE) && (is_html_complete_doc(n))) {
161
+ /* We have metadata to include, and didn't already force complete */
162
+ g_string_append_printf(out,
163
+ "<!DOCTYPE html>\n<html>\n<head>\n\t<meta charset=\"utf-8\"/>\n");
164
+ /* either way, now we need to be a complete doc */
165
+ scratch->extensions = scratch->extensions | EXT_COMPLETE;
166
+ } else {
167
+ /* Ensure we lowercase metadata */
168
+ is_html_complete_doc(n);
169
+ }
170
+ /* print the metadata */
171
+ scratch->extensions = scratch->extensions | EXT_HEAD_CLOSED;
172
+ print_html_node_tree(out,n->children, scratch);
173
+ if (scratch->extensions & EXT_COMPLETE) {
174
+ /* need to close head and open body */
175
+ g_string_append_printf(out, "</head>\n<body>\n\n");
176
+ }
177
+ break;
178
+ case METAKEY:
179
+ if (strcmp(n->str, "baseheaderlevel") == 0) {
180
+ scratch->baseheaderlevel = atoi(n->children->str);
181
+ break;
182
+ } else if (strcmp(n->str, "xhtmlheaderlevel") == 0) {
183
+ scratch->baseheaderlevel = atoi(n->children->str);
184
+ break;
185
+ } else if (strcmp(n->str, "htmlheaderlevel") == 0) {
186
+ scratch->baseheaderlevel = atoi(n->children->str);
187
+ break;
188
+ } else if (strcmp(n->str, "quoteslanguage") == 0) {
189
+ temp = label_from_node_tree(n->children);
190
+ if ((strcmp(temp, "nl") == 0) || (strcmp(temp, "dutch") == 0)) { scratch->language = DUTCH; } else
191
+ if ((strcmp(temp, "de") == 0) || (strcmp(temp, "german") == 0)) { scratch->language = GERMAN; } else
192
+ if (strcmp(temp, "germanguillemets") == 0) { scratch->language = GERMANGUILL; } else
193
+ if ((strcmp(temp, "fr") == 0) || (strcmp(temp, "french") == 0)) { scratch->language = FRENCH; } else
194
+ if ((strcmp(temp, "sv") == 0) || (strcmp(temp, "swedish") == 0)) { scratch->language = SWEDISH; }
195
+ free(temp);
196
+ break;
197
+ }
198
+
199
+ /* Don't handle other metadata if we're snippet only */
200
+ if (scratch->extensions & EXT_SNIPPET)
201
+ break;
202
+
203
+ if (strcmp(n->str, "title") == 0) {
204
+ g_string_append_printf(out, "\t<title>");
205
+ print_html_node(out, n->children, scratch);
206
+ g_string_append_printf(out, "</title>\n");
207
+ } else if (strcmp(n->str, "css") == 0) {
208
+ g_string_append_printf(out, "\t<link type=\"text/css\" rel=\"stylesheet\" href=\"");
209
+ print_html_node(out, n->children, scratch);
210
+ g_string_append_printf(out, "\"/>\n");
211
+ } else if (strcmp(n->str, "xhtmlheader") == 0) {
212
+ trim_trailing_whitespace(n->children->str);
213
+ print_raw_node(out, n->children);
214
+ g_string_append_printf(out, "\n");
215
+ } else if (strcmp(n->str, "htmlheader") == 0) {
216
+ trim_trailing_whitespace(n->children->str);
217
+ print_raw_node(out, n->children);
218
+ g_string_append_printf(out, "\n");
219
+ } else {
220
+ g_string_append_printf(out,"\t<meta name=\"%s\" content=\"",n->str);
221
+ print_html_node(out,n->children,scratch);
222
+ g_string_append_printf(out,"\"/>\n");
223
+ }
224
+ break;
225
+ case METAVALUE:
226
+ trim_trailing_whitespace(n->str);
227
+ print_html_string(out,n->str, scratch);
228
+ break;
229
+ case FOOTER:
230
+ break;
231
+ case HEADINGSECTION:
232
+ print_html_node_tree(out,n->children,scratch);
233
+ break;
234
+ case H1: case H2: case H3: case H4: case H5: case H6:
235
+ lev = n->key - H1 + scratch->baseheaderlevel; /* assumes H1 ... H6 are in order */
236
+ if (lev > 6)
237
+ lev = 6; /* Max at level 6 */
238
+ pad(out, 2, scratch);
239
+ if ( scratch->extensions & EXT_COMPATIBILITY ) {
240
+ /* Use regular Markdown header format */
241
+ g_string_append_printf(out, "<h%1d>", lev);
242
+ print_html_node_tree(out, n->children, scratch);
243
+ } else if (n->children->key == AUTOLABEL) {
244
+ temp = label_from_string(n->children->str);
245
+ /* use label for header since one was specified (MMD)*/
246
+ g_string_append_printf(out, "<h%d id=\"%s\">", lev,temp);
247
+ print_html_node_tree(out, n->children->next, scratch);
248
+ free(temp);
249
+ } else if ( scratch->extensions & EXT_NO_LABELS ) {
250
+ /* Don't generate a label */
251
+ g_string_append_printf(out, "<h%1d>", lev);
252
+ print_html_node_tree(out, n->children, scratch);
253
+ } else {
254
+ /* generate a label by default for MMD */
255
+ temp = label_from_node_tree(n->children);
256
+ g_string_append_printf(out, "<h%d id=\"%s\">", lev, temp);
257
+ print_html_node_tree(out, n->children, scratch);
258
+ free(temp);
259
+ }
260
+ g_string_append_printf(out, "</h%1d>", lev);
261
+ scratch->padded = 0;
262
+ break;
263
+ case APOSTROPHE:
264
+ print_html_localized_typography(out, APOS, scratch);
265
+ break;
266
+ case ELLIPSIS:
267
+ print_html_localized_typography(out, ELLIP, scratch);
268
+ break;
269
+ case EMDASH:
270
+ print_html_localized_typography(out, MDASH, scratch);
271
+ break;
272
+ case ENDASH:
273
+ print_html_localized_typography(out, NDASH, scratch);
274
+ break;
275
+ case SINGLEQUOTED:
276
+ print_html_localized_typography(out, LSQUOTE, scratch);
277
+ print_html_node_tree(out, n->children, scratch);
278
+ print_html_localized_typography(out, RSQUOTE, scratch);
279
+ break;
280
+ case DOUBLEQUOTED:
281
+ print_html_localized_typography(out, LDQUOTE, scratch);
282
+ print_html_node_tree(out, n->children, scratch);
283
+ print_html_localized_typography(out, RDQUOTE, scratch);
284
+ break;
285
+ case LINEBREAK:
286
+ g_string_append_printf(out, "<br/>\n");
287
+ break;
288
+ case MATHSPAN:
289
+ if (n->str[0] == '$') {
290
+ n->str[strlen(n->str)-1] = '\0';
291
+ if (n->str[1] == '$') {
292
+ n->str[strlen(n->str)-1] = '\0';
293
+ g_string_append_printf(out, "<span class=\"math\">\\[%s\\]</span>",&n->str[2]);
294
+ } else {
295
+ g_string_append_printf(out, "<span class=\"math\">\\(%s\\)</span>",&n->str[1]);
296
+ }
297
+ } else if (n->str[strlen(n->str) - 1] == ']') {
298
+ n->str[strlen(n->str) - 3] = '\0';
299
+ g_string_append_printf(out, "<span class=\"math\">%s\\]</span>",n->str);
300
+ } else {
301
+ n->str[strlen(n->str) - 3] = '\0';
302
+ g_string_append_printf(out, "<span class=\"math\">%s\\)</span>",n->str);
303
+ }
304
+ break;
305
+ case STRONG:
306
+ g_string_append_printf(out, "<strong>");
307
+ print_html_node_tree(out,n->children,scratch);
308
+ g_string_append_printf(out, "</strong>");
309
+ break;
310
+ case EMPH:
311
+ g_string_append_printf(out, "<em>");
312
+ print_html_node_tree(out,n->children,scratch);
313
+ g_string_append_printf(out, "</em>");
314
+ break;
315
+ case LINKREFERENCE:
316
+ break;
317
+ case LINK:
318
+ #ifdef DEBUG_ON
319
+ fprintf(stderr, "print html link: '%s'\n",n->str);
320
+ #endif
321
+ /* Stash a copy of the link data */
322
+ if (n->link_data != NULL)
323
+ temp_link_data = mk_link_data(n->link_data->label, n->link_data->source, n->link_data->title, n->link_data->attr);
324
+
325
+ /* Do we have proper info? */
326
+ if ((n->link_data->label == NULL) &&
327
+ (n->link_data->source == NULL)) {
328
+ /* we seem to be a [foo][] style link */
329
+ /* so load a label */
330
+ temp_str = g_string_new("");
331
+ print_raw_node_tree(temp_str, n->children);
332
+ n->link_data->label = temp_str->str;
333
+ g_string_free(temp_str, FALSE);
334
+ }
335
+ /* Load reference data */
336
+ if (n->link_data->label != NULL) {
337
+ temp = strdup(n->link_data->label);
338
+
339
+ n->link_data->attr = NULL;
340
+ free_link_data(n->link_data);
341
+
342
+ n->link_data = extract_link_data(temp, scratch);
343
+ if (n->link_data == NULL) {
344
+ /* replace original text since no definition found */
345
+ g_string_append_printf(out, "[");
346
+ print_html_node(out, n->children, scratch);
347
+ g_string_append_printf(out,"]");
348
+ if (n->children->next != NULL) {
349
+ g_string_append_printf(out, "[");
350
+ print_html_node_tree(out, n->children->next, scratch);
351
+ g_string_append_printf(out,"]");
352
+ } else if (n->str != NULL) {
353
+ /* no title label, so see if we stashed str*/
354
+ g_string_append_printf(out, "%s", n->str);
355
+ } else {
356
+ g_string_append_printf(out, "[%s]",temp);
357
+ }
358
+
359
+ free(temp);
360
+
361
+ /* Restore stashed copy */
362
+ n->link_data = temp_link_data;
363
+
364
+ break;
365
+ }
366
+ free(temp);
367
+ }
368
+ g_string_append_printf(out, "<a");
369
+ if (n->link_data->source != NULL) {
370
+ g_string_append_printf(out, " href=\"");
371
+ if (strncmp(n->link_data->source,"mailto:", 6) == 0) {
372
+ scratch->obfuscate = 1; /* flag obfuscated */
373
+ }
374
+ print_html_string(out,n->link_data->source, scratch);
375
+ g_string_append_printf(out, "\"");
376
+ }
377
+ if ((n->link_data->title != NULL) && (strlen(n->link_data->title) > 0)) {
378
+ g_string_append_printf(out, " title=\"");
379
+ print_html_string(out, n->link_data->title, scratch);
380
+ g_string_append_printf(out, "\"");
381
+ }
382
+ print_html_node_tree(out, n->link_data->attr, scratch);
383
+ g_string_append_printf(out, ">");
384
+ if (n->children != NULL)
385
+ print_html_node_tree(out,n->children,scratch);
386
+ g_string_append_printf(out, "</a>");
387
+ scratch->obfuscate = 0;
388
+
389
+ /* Restore stashed copy */
390
+ n->link_data->attr = NULL;
391
+ free_link_data(n->link_data);
392
+ n->link_data = temp_link_data;
393
+
394
+ break;
395
+ case ATTRKEY:
396
+ if ( (strcmp(n->str,"height") == 0) || (strcmp(n->str, "width") == 0)) {
397
+ } else {
398
+ g_string_append_printf(out, " %s=\"%s\"", n->str,
399
+ n->children->str);
400
+ }
401
+ break;
402
+ case REFNAME:
403
+ case SOURCE:
404
+ case TITLE:
405
+ break;
406
+ case IMAGEBLOCK:
407
+ pad(out,2, scratch);
408
+ case IMAGE:
409
+ #ifdef DEBUG_ON
410
+ fprintf(stderr, "print image\n");
411
+ #endif
412
+ /* Stash a copy of the link data */
413
+ if (n->link_data != NULL)
414
+ temp_link_data = mk_link_data(n->link_data->label, n->link_data->source, n->link_data->title, n->link_data->attr);
415
+
416
+ if (n->key == IMAGEBLOCK)
417
+ g_string_append_printf(out, "<figure>\n");
418
+ /* Do we have proper info? */
419
+ if ((n->link_data->label == NULL) &&
420
+ (n->link_data->source == NULL)) {
421
+ /* we seem to be a [foo][] style link */
422
+ /* so load a label */
423
+ temp_str = g_string_new("");
424
+ print_raw_node_tree(temp_str, n->children);
425
+ n->link_data->label = temp_str->str;
426
+ g_string_free(temp_str, FALSE);
427
+ }
428
+ #ifdef DEBUG_ON
429
+ fprintf(stderr, "load reference data\n");
430
+ #endif
431
+ /* Load reference data */
432
+ if (n->link_data->label != NULL) {
433
+ temp = strdup(n->link_data->label);
434
+
435
+ n->link_data->attr = NULL;
436
+ free_link_data(n->link_data);
437
+
438
+ n->link_data = extract_link_data(temp, scratch);
439
+
440
+ if (n->link_data == NULL) {
441
+ g_string_append_printf(out, "![");
442
+ print_html_node_tree(out, n->children, scratch);
443
+ g_string_append_printf(out,"][%s]",temp);
444
+
445
+ /* Restore stashed copy */
446
+ n->link_data = temp_link_data;
447
+
448
+ free(temp);
449
+
450
+ break;
451
+ }
452
+ free(temp);
453
+ }
454
+ #ifdef DEBUG_ON
455
+ fprintf(stderr, "create img\n");
456
+ #endif
457
+ g_string_append_printf(out, "<img");
458
+ if (n->link_data->source != NULL)
459
+ g_string_append_printf(out, " src=\"%s\"",n->link_data->source);
460
+ if (n->children != NULL) {
461
+ g_string_append_printf(out, " alt=\"");
462
+ temp_str = g_string_new("");
463
+ print_raw_node_tree(temp_str, n->children);
464
+ print_html_string(out, temp_str->str, scratch);
465
+ g_string_free(temp_str, true);
466
+ g_string_append_printf(out, "\"");
467
+ } else {
468
+ g_string_append_printf(out, " alt=\"%s\"",n->link_data->title);
469
+ }
470
+ if (!(scratch->extensions & EXT_COMPATIBILITY)) {
471
+ if (n->link_data->label != NULL) {
472
+ temp = label_from_string(n->link_data->label);
473
+ g_string_append_printf(out, " id=\"%s\"",temp);
474
+ free(temp);
475
+ }
476
+ }
477
+ if ((n->link_data->title != NULL) && (strlen(n->link_data->title) > 0)) {
478
+ g_string_append_printf(out, " title=\"");
479
+ print_html_string(out, n->link_data->title, scratch);
480
+ g_string_append_printf(out, "\"");
481
+ }
482
+ #ifdef DEBUG_ON
483
+ fprintf(stderr, "attributes\n");
484
+ #endif
485
+ if (n->link_data->attr != NULL) {
486
+ temp_node = node_for_attribute("height",n->link_data->attr);
487
+ if (temp_node != NULL)
488
+ height = strdup(temp_node->children->str);
489
+ temp_node = node_for_attribute("width",n->link_data->attr);
490
+ if (temp_node != NULL)
491
+ width = strdup(temp_node->children->str);
492
+ if ((height != NULL) || (width != NULL)) {
493
+ #ifdef DEBUG_ON
494
+ fprintf(stderr, "width/height\n");
495
+ #endif
496
+ g_string_append_printf(out, " style=\"");
497
+ if (height != NULL)
498
+ g_string_append_printf(out, "height:%s;", height);
499
+ if (width != NULL)
500
+ g_string_append_printf(out, "width:%s;", width);
501
+ g_string_append_printf(out, "\"");
502
+ }
503
+ #ifdef DEBUG_ON
504
+ fprintf(stderr, "other attributes\n");
505
+ #endif
506
+ print_html_node_tree(out, n->link_data->attr, scratch);
507
+ free(height);
508
+ free(width);
509
+ }
510
+ g_string_append_printf(out, " />");
511
+ if (n->key == IMAGEBLOCK) {
512
+ if (n->children != NULL) {
513
+ g_string_append_printf(out, "\n<figcaption>");
514
+ print_html_node(out,n->children,scratch);
515
+ g_string_append_printf(out, "</figcaption>");
516
+ }
517
+ g_string_append_printf(out,"</figure>");
518
+ scratch->padded = 0;
519
+ }
520
+
521
+ /* Restore stashed copy */
522
+ n->link_data->attr = NULL;
523
+ free_link_data(n->link_data);
524
+ n->link_data = temp_link_data;
525
+
526
+ break;
527
+ #ifdef DEBUG_ON
528
+ fprintf(stderr, "finish image\n");
529
+ #endif
530
+ case NOTEREFERENCE:
531
+ lev = note_number_for_node(n, scratch);
532
+ temp_node = node_for_count(scratch->used_notes, lev);
533
+
534
+ if (scratch->extensions & EXT_RANDOM_FOOT) {
535
+ srand(scratch->random_seed_base + lev);
536
+ random = rand() % 99999 + 1;
537
+ } else {
538
+ random = lev;
539
+ }
540
+
541
+ if (temp_node->key == GLOSSARYSOURCE) {
542
+ if (lev > scratch->max_footnote_num) {
543
+ g_string_append_printf(out, "<a href=\"#fn:%d\" id=\"fnref:%d\" title=\"see footnote\" class=\"footnote glossary\">[%d]</a>",
544
+ random, random, lev);
545
+ scratch->max_footnote_num = lev;
546
+ } else {
547
+ g_string_append_printf(out, "<a href=\"#fn:%d\" title=\"see footnote\" class=\"footnote glossary\">[%d]</a>",
548
+ random, lev);
549
+ }
550
+ } else {
551
+ if (lev > scratch->max_footnote_num) {
552
+ g_string_append_printf(out, "<a href=\"#fn:%d\" id=\"fnref:%d\" title=\"see footnote\" class=\"footnote\">[%d]</a>",
553
+ random, random, lev);
554
+ scratch->max_footnote_num = lev;
555
+ } else {
556
+ g_string_append_printf(out, "<a href=\"#fn:%d\" title=\"see footnote\" class=\"footnote\">[%d]</a>",
557
+ random, lev);
558
+ }
559
+ }
560
+ break;
561
+ case NOCITATION:
562
+ case CITATION:
563
+ #ifdef DEBUG_ON
564
+ fprintf(stderr, "print cite\n");
565
+ #endif
566
+ if ((n->link_data != NULL) && (strncmp(n->link_data->label,"[#",2) == 0)) {
567
+ fprintf(stderr, "external cite\n");
568
+ /* external citation (e.g. BibTeX) */
569
+ if (n->key == NOCITATION) {
570
+ g_string_append_printf(out, "<span class=\"notcited\" id=\"%s\"/>",n->str);
571
+ } else {
572
+ g_string_append_printf(out, "<span class=\"externalcitation\">");
573
+ g_string_append_printf(out, "</span>");
574
+ }
575
+ } else {
576
+ #ifdef DEBUG_ON
577
+ fprintf(stderr, "internal cite\n");
578
+ #endif
579
+ /* MMD citation, so output as footnote */
580
+ /* TODO: create separate stream from footnotes */
581
+ lev = 0;
582
+ if (n->link_data != NULL)
583
+ lev = note_number_for_label(n->link_data->label, scratch);
584
+ if (lev != 0) {
585
+ #ifdef DEBUG_ON
586
+ fprintf(stderr, "matching cite found\n");
587
+ #endif
588
+ if (scratch->extensions & EXT_RANDOM_FOOT) {
589
+ srand(scratch->random_seed_base + lev);
590
+ random = rand() % 99999 + 1;
591
+ } else {
592
+ random = lev;
593
+ }
594
+
595
+ temp_node = node_for_count(scratch->used_notes, lev);
596
+ /* flag that this is used as a citation */
597
+ temp_node->key = CITATIONSOURCE;
598
+ if (lev > scratch->max_footnote_num) {
599
+ scratch->max_footnote_num = lev;
600
+ }
601
+ if (n->key == NOCITATION) {
602
+ g_string_append_printf(out, "<span class=\"notcited\" id=\"%d\">",random);
603
+ } else {
604
+ g_string_append_printf(out, "<a class=\"citation\" href=\"#fn:%d\" title=\"Jump to citation\">[",
605
+ random);
606
+ if (n->children != NULL) {
607
+ g_string_append_printf(out, "<span class=\"locator\">");
608
+ print_html_node(out, n->children, scratch);
609
+ g_string_append_printf(out, "</span>, %d]", lev);
610
+ } else {
611
+ g_string_append_printf(out, "%d]", lev);
612
+ }
613
+ }
614
+ g_string_append_printf(out, "<span class=\"citekey\" style=\"display:none\">%s</span>", n->link_data->label);
615
+ if (n->key == NOCITATION) {
616
+ g_string_append_printf(out, "</span>");
617
+ } else {
618
+ g_string_append_printf(out, "</a>");
619
+ }
620
+ } else {
621
+ /* not located -- this is external cite */
622
+ #ifdef DEBUG_ON
623
+ fprintf(stderr, "no match for cite: '%s'\n",n->link_data->label);
624
+ #endif
625
+ if ((n->link_data != NULL) && (n->key == NOCITATION)) {
626
+ g_string_append_printf(out, "<span class=\"notcited\" id=\"%s\"/>",n->link_data->label);
627
+ } else if (n->link_data != NULL) {
628
+ g_string_append_printf(out, "<span class=\"externalcitation\">[");
629
+ if (n->children != NULL) {
630
+ print_html_node(out, n->children, scratch);
631
+ g_string_append_printf(out, "][");
632
+ }
633
+ g_string_append_printf(out, "#%s]</span>",n->link_data->label);
634
+ }
635
+ }
636
+ }
637
+ #ifdef DEBUG_ON
638
+ fprintf(stderr, "finish cite\n");
639
+ #endif
640
+ break;
641
+ case VARIABLE:
642
+ temp = metavalue_for_key(n->str,scratch->result_tree);
643
+ if (temp == NULL) {
644
+ g_string_append_printf(out, "[%%%s]",n->str);
645
+ } else {
646
+ g_string_append_printf(out, temp);
647
+ free(temp);
648
+ }
649
+ break;
650
+ case GLOSSARYTERM:
651
+ g_string_append_printf(out,"<span class=\"glossary name\">");
652
+ print_html_string(out, n->children->str, scratch);
653
+ g_string_append_printf(out, "</span>");
654
+ if ((n->next != NULL) && (n->next->key == GLOSSARYSORTKEY) ) {
655
+ g_string_append_printf(out, "<span class=\"glossary sort\" style=\"display:none\">");
656
+ print_html_string(out, n->next->str, scratch);
657
+ g_string_append_printf(out, "</span>");
658
+ }
659
+ g_string_append_printf(out, ": ");
660
+ break;
661
+ case GLOSSARYSORTKEY:
662
+ break;
663
+ case CODE:
664
+ g_string_append_printf(out, "<code>");
665
+ print_html_string(out, n->str, scratch);
666
+ g_string_append_printf(out, "</code>");
667
+ break;
668
+ case BLOCKQUOTEMARKER:
669
+ print_html_node_tree(out, n->children, scratch);
670
+ break;
671
+ case BLOCKQUOTE:
672
+ pad(out,2, scratch);
673
+ g_string_append_printf(out, "<blockquote>\n");
674
+ scratch->padded = 2;
675
+ print_html_node_tree(out, n->children, scratch);
676
+ pad(out,1, scratch);
677
+ g_string_append_printf(out, "</blockquote>");
678
+ scratch->padded = 0;
679
+ break;
680
+ case RAW:
681
+ g_string_append_printf(out, "RAW:");
682
+ g_string_append_printf(out,"%s",n->str);
683
+ break;
684
+ case HTML:
685
+ g_string_append_printf(out, "%s", n->str);
686
+ break;
687
+ case DEFLIST:
688
+ pad(out,2, scratch);
689
+ scratch->padded = 1;
690
+ g_string_append_printf(out, "<dl>\n");
691
+ print_html_node_tree(out, n->children, scratch);
692
+ g_string_append_printf(out, "</dl>");
693
+ scratch->padded = 0;
694
+ break;
695
+ case TERM:
696
+ pad(out,1, scratch);
697
+ g_string_append_printf(out, "<dt>");
698
+ print_html_node_tree(out, n->children, scratch);
699
+ g_string_append_printf(out, "</dt>\n");
700
+ scratch->padded = 1;
701
+ break;
702
+ case DEFINITION:
703
+ pad(out,1, scratch);
704
+ scratch->padded = 1;
705
+ g_string_append_printf(out, "<dd>");
706
+ print_html_node_tree(out, n->children, scratch);
707
+ g_string_append_printf(out, "</dd>\n");
708
+ scratch->padded = 0;
709
+ break;
710
+ case TABLE:
711
+ pad(out,2, scratch);
712
+ g_string_append_printf(out, "<table>\n");
713
+ print_html_node_tree(out, n->children, scratch);
714
+ g_string_append_printf(out, "</table>\n");
715
+ scratch->cell_type = 0;
716
+ scratch->padded = 1;
717
+ break;
718
+ case TABLESEPARATOR:
719
+ scratch->table_alignment = n->str;
720
+ if (scratch->cell_type == 0)
721
+ print_col_group(out, scratch);
722
+ scratch->cell_type = 'd';
723
+ break;
724
+ case TABLECAPTION:
725
+ if ((n->children != NULL) && (n->children->key == TABLELABEL)) {
726
+ temp = label_from_string(n->children->str);
727
+ } else {
728
+ temp = label_from_node_tree(n->children);
729
+ }
730
+ g_string_append_printf(out, "<caption id=\"%s\">", temp);
731
+ print_html_node_tree(out, n->children, scratch);
732
+ g_string_append_printf(out, "</caption>\n");
733
+ free(temp);
734
+ break;
735
+ case TABLELABEL:
736
+ break;
737
+ case TABLEHEAD:
738
+ /* print column alignment for XSLT processing if needed */
739
+ if (scratch->cell_type == 0)
740
+ print_col_group(out, scratch);
741
+ scratch->cell_type = 'h';
742
+ g_string_append_printf(out, "\n<thead>\n");
743
+ print_html_node_tree(out, n->children, scratch);
744
+ g_string_append_printf(out, "</thead>\n");
745
+ scratch->cell_type = 'd';
746
+ break;
747
+ case TABLEBODY:
748
+ g_string_append_printf(out, "\n<tbody>\n");
749
+ print_html_node_tree(out, n->children, scratch);
750
+ g_string_append_printf(out, "</tbody>\n");
751
+ break;
752
+ case TABLEROW:
753
+ g_string_append_printf(out, "<tr>\n");
754
+ scratch->table_column = 0;
755
+ print_html_node_tree(out, n->children, scratch);
756
+ g_string_append_printf(out, "</tr>\n");
757
+ break;
758
+ case TABLECELL:
759
+ temp = scratch->table_alignment;
760
+ if (strncmp(&temp[scratch->table_column],"h",1) == 0) {
761
+ temp_type = 'h';
762
+ scratch->table_column++;
763
+ } else {
764
+ temp_type = scratch->cell_type;
765
+ }
766
+ lev = scratch->table_column;
767
+ if ( strncmp(&temp[lev],"r",1) == 0) {
768
+ g_string_append_printf(out, "\t<t%c style=\"text-align:right;\"", temp_type);
769
+ } else if ( strncmp(&temp[lev],"R",1) == 0) {
770
+ g_string_append_printf(out, "\t<t%c style=\"text-align:right;\"", temp_type);
771
+ } else if ( strncmp(&temp[lev],"c",1) == 0) {
772
+ g_string_append_printf(out, "\t<t%c style=\"text-align:center;\"", temp_type);
773
+ } else if ( strncmp(&temp[lev],"C",1) == 0) {
774
+ g_string_append_printf(out, "\t<t%c style=\"text-align:center;\"", temp_type);
775
+ } else {
776
+ g_string_append_printf(out, "\t<t%c style=\"text-align:left;\"", temp_type);
777
+ }
778
+ if ((n->children != NULL) && (n->children->key == CELLSPAN)) {
779
+ g_string_append_printf(out, " colspan=\"%d\"",(int)strlen(n->children->str)+1);
780
+ }
781
+ g_string_append_printf(out, ">");
782
+ scratch->padded = 2;
783
+ print_html_node_tree(out, n->children, scratch);
784
+ g_string_append_printf(out, "</t%c>\n", temp_type);
785
+ scratch->table_column++;
786
+ break;
787
+ case CELLSPAN:
788
+ break;
789
+ case GLOSSARYSOURCE:
790
+ if (scratch->printing_notes)
791
+ print_html_node_tree(out, n->children, scratch);
792
+ break;
793
+ case CITATIONSOURCE:
794
+ case NOTESOURCE:
795
+ if (scratch->printing_notes)
796
+ print_html_node_tree(out, n->children, scratch);
797
+ break;
798
+ case SOURCEBRANCH:
799
+ fprintf(stderr,"SOURCEBRANCH\n");
800
+ break;
801
+ case NOTELABEL:
802
+ break;
803
+ case SUPERSCRIPT:
804
+ g_string_append_printf(out, "<sup>%s</sup>",n->str);
805
+ break;
806
+ case SUBSCRIPT:
807
+ g_string_append_printf(out, "<sub>%s</sub>",n->str);
808
+ break;
809
+ case KEY_COUNTER:
810
+ break;
811
+ default:
812
+ fprintf(stderr, "print_html_node encountered unknown node key = %d\n",n->key);
813
+ exit(EXIT_FAILURE);
814
+ }
815
+ }
816
+
817
+ /* print_html_endnotes */
818
+ void print_html_endnotes(GString *out, scratch_pad *scratch) {
819
+ int counter = 0;
820
+ int random;
821
+
822
+ scratch->used_notes = reverse_list(scratch->used_notes);
823
+ scratch->printing_notes = 1;
824
+
825
+ node *note = scratch->used_notes;
826
+ #ifdef DEBUG_ON
827
+ fprintf(stderr, "start endnotes\n");
828
+ #endif
829
+
830
+ if ((note == NULL) || ((note->key == KEY_COUNTER) && (note->next == NULL)))
831
+ return;
832
+
833
+ #ifdef DEBUG_ON
834
+ fprintf(stderr, "there are endnotes to print\n");
835
+ #endif
836
+
837
+ pad(out,2, scratch);
838
+ g_string_append_printf(out, "<div class=\"footnotes\">\n<hr />\n<ol>");
839
+ while ( note != NULL) {
840
+ if (note->key == KEY_COUNTER) {
841
+ note = note->next;
842
+ continue;
843
+ }
844
+
845
+ counter++;
846
+ pad(out, 1, scratch);
847
+
848
+ if (scratch->extensions & EXT_RANDOM_FOOT) {
849
+ srand(scratch->random_seed_base + counter);
850
+ random = rand() % 99999 + 1;
851
+ } else {
852
+ random = counter;
853
+ }
854
+
855
+ if (note->key == CITATIONSOURCE) {
856
+ g_string_append_printf(out, "<li id=\"fn:%d\" class=\"citation\"><span class=\"citekey\" style=\"display:none\">%s</span>",
857
+ random, note->str);
858
+ } else {
859
+ g_string_append_printf(out, "<li id=\"fn:%d\">\n", random);
860
+ }
861
+
862
+
863
+ scratch->padded = 2;
864
+ if ((note->key == NOTESOURCE) || (note->key == GLOSSARYSOURCE))
865
+ scratch->footnote_to_print = counter;
866
+ scratch->footnote_para_counter = tree_contains_key_count(note->children,PARA);
867
+ print_html_node(out, note, scratch);
868
+ pad(out, 1, scratch);
869
+ g_string_append_printf(out, "</li>");
870
+
871
+ note = note->next;
872
+ }
873
+ pad(out,1, scratch);
874
+ g_string_append_printf(out, "</ol>\n</div>\n");
875
+ scratch->padded = 0;
876
+ #ifdef DEBUG_ON
877
+ fprintf(stderr, "finish endnotes\n");
878
+ #endif
879
+ }
880
+
881
+ /* Check metadata keys and determine if we need a complete document */
882
+ /* We also preconvert metadata keys to proper formatting -- lowercase with no spaces */
883
+ bool is_html_complete_doc(node *meta) {
884
+ node *step;
885
+ char *temp;
886
+ step = meta->children;
887
+
888
+ while (step != NULL) {
889
+ /* process key to proper label */
890
+ temp = step->str; /* store pointer to original str */
891
+ step->str = label_from_string(step->str);
892
+ free(temp); /* free original since we don't need it */
893
+ step = step->next;
894
+ }
895
+
896
+ step = meta->children;
897
+ while (step != NULL) {
898
+ /* the following types of metadata do not require a complete document */
899
+ if ((strcmp(step->str, "baseheaderlevel") != 0) &&
900
+ (strcmp(step->str, "xhtmlheaderlevel") != 0) &&
901
+ (strcmp(step->str, "htmlheaderlevel") != 0) &&
902
+ (strcmp(step->str, "latexheaderlevel") != 0) &&
903
+ (strcmp(step->str, "odfheaderlevel") != 0) &&
904
+ (strcmp(step->str, "quoteslanguage") != 0))
905
+ { return TRUE;}
906
+ step = step->next;
907
+ }
908
+
909
+ return FALSE;
910
+ }
911
+
912
+ /* print_html_localized_typography -- convert to "smart" typography */
913
+ void print_html_localized_typography(GString *out, int character, scratch_pad *scratch) {
914
+ if (!extension(EXT_SMART, scratch->extensions)) {
915
+ g_string_append_c(out, character);
916
+ return;
917
+ }
918
+ switch (character) {
919
+ case LSQUOTE:
920
+ switch (scratch->language) {
921
+ case SWEDISH:
922
+ g_string_append_printf(out, "&#8217;");
923
+ break;
924
+ case FRENCH:
925
+ g_string_append_printf(out,"&#39;");
926
+ break;
927
+ case GERMAN:
928
+ g_string_append_printf(out,"&#8218;");
929
+ break;
930
+ case GERMANGUILL:
931
+ g_string_append_printf(out,"&#8250;");
932
+ break;
933
+ default:
934
+ g_string_append_printf(out,"&#8216;");
935
+ }
936
+ break;
937
+ case RSQUOTE:
938
+ switch (scratch->language) {
939
+ case GERMAN:
940
+ g_string_append_printf(out,"&#8216;");
941
+ break;
942
+ case GERMANGUILL:
943
+ g_string_append_printf(out,"&#8249;");
944
+ break;
945
+ default:
946
+ g_string_append_printf(out,"&#8217;");
947
+ }
948
+ break;
949
+ case APOS:
950
+ g_string_append_printf(out,"&#8217;");
951
+ break;
952
+ case LDQUOTE:
953
+ switch (scratch->language) {
954
+ case DUTCH:
955
+ case GERMAN:
956
+ g_string_append_printf(out,"&#8222;");
957
+ break;
958
+ case GERMANGUILL:
959
+ g_string_append_printf(out,"&#187;");
960
+ break;
961
+ case FRENCH:
962
+ g_string_append_printf(out,"&#171;");
963
+ break;
964
+ case SWEDISH:
965
+ g_string_append_printf(out, "&#8221;");
966
+ break;
967
+ default:
968
+ g_string_append_printf(out,"&#8220;");
969
+ }
970
+ break;
971
+ case RDQUOTE:
972
+ switch (scratch->language) {
973
+ case SWEDISH:
974
+ case DUTCH:
975
+ g_string_append_printf(out,"&#8221;");
976
+ break;
977
+ case GERMAN:
978
+ g_string_append_printf(out,"&#8220;");
979
+ break;
980
+ case GERMANGUILL:
981
+ g_string_append_printf(out,"&#171;");
982
+ break;
983
+ case FRENCH:
984
+ g_string_append_printf(out,"&#187;");
985
+ break;
986
+ default:
987
+ g_string_append_printf(out,"&#8221;");
988
+ }
989
+ break;
990
+ case NDASH:
991
+ g_string_append_printf(out,"&#8211;");
992
+ break;
993
+ case MDASH:
994
+ g_string_append_printf(out,"&#8212;");
995
+ break;
996
+ case ELLIP:
997
+ g_string_append_printf(out,"&#8230;");
998
+ break;
999
+ default:;
1000
+ }
1001
+ }
1002
+
1003
+ /* print_html_string - print string, escaping for HTML */
1004
+ long ran_num_next(); /* Use Knuth's pseudo random generator */
1005
+
1006
+ void print_html_string(GString *out, char *str, scratch_pad *scratch) {
1007
+ if (str == NULL)
1008
+ return;
1009
+ while (*str != '\0') {
1010
+ switch (*str) {
1011
+ case '&':
1012
+ g_string_append_printf(out, "&amp;");
1013
+ break;
1014
+ case '<':
1015
+ g_string_append_printf(out, "&lt;");
1016
+ break;
1017
+ case '>':
1018
+ g_string_append_printf(out, "&gt;");
1019
+ break;
1020
+ case '"':
1021
+ g_string_append_printf(out, "&quot;");
1022
+ break;
1023
+ default:
1024
+ if ((scratch->obfuscate == true) && (extension(EXT_OBFUSCATE, scratch->extensions))
1025
+ && ((int) *str == (((int) *str) & 127))) {
1026
+ if (ran_num_next() % 2 == 0)
1027
+ g_string_append_printf(out, "&#%d;", (int) *str);
1028
+ else
1029
+ g_string_append_printf(out, "&#x%x;", (unsigned int) *str);
1030
+ } else {
1031
+ g_string_append_c(out, *str);
1032
+ }
1033
+ }
1034
+ str++;
1035
+ }
1036
+ }
1037
+
1038
+ /* print_col_group - print column alignment config (used in XSLT processing) */
1039
+ void print_col_group(GString *out,scratch_pad *scratch) {
1040
+ char *temp;
1041
+ int lev;
1042
+ g_string_append_printf(out, "<colgroup>\n");
1043
+ temp = scratch->table_alignment;
1044
+ for (lev=0;lev<strlen(temp);lev++) {
1045
+ if ( strncmp(&temp[lev],"r",1) == 0) {
1046
+ g_string_append_printf(out, "<col style=\"text-align:right;\"/>\n");
1047
+ } else if ( strncmp(&temp[lev],"R",1) == 0) {
1048
+ g_string_append_printf(out, "<col style=\"text-align:right;\" class=\"extended\"/>\n");
1049
+ } else if ( strncmp(&temp[lev],"c",1) == 0) {
1050
+ g_string_append_printf(out, "<col style=\"text-align:center;\"/>\n");
1051
+ } else if ( strncmp(&temp[lev],"C",1) == 0) {
1052
+ g_string_append_printf(out, "<col style=\"text-align:center;\" class=\"extended\"/>\n");
1053
+ } else if ( strncmp(&temp[lev],"L",1) == 0) {
1054
+ g_string_append_printf(out, "<col style=\"text-align:left;\" class=\"extended\"/>\n");
1055
+ } else {
1056
+ g_string_append_printf(out, "<col style=\"text-align:left;\"/>\n");
1057
+ }
1058
+ }
1059
+ g_string_append_printf(out, "</colgroup>\n");
1060
+ }