rmultimarkdown 4.7.1.1 → 6.2.2.1

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