rmultimarkdown 4.7.1.1 → 6.2.2.1

Sign up to get free protection for your applications and to get access to all the features.
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,16 +0,0 @@
1
- #ifndef LATEX_PARSER_H
2
- #define LATEX_PARSER_H
3
-
4
- #include "parser.h"
5
- #include "writer.h"
6
-
7
-
8
- void print_latex_node_tree(GString *out, node *list, scratch_pad *scratch);
9
- void print_latex_node(GString *out, node *n, scratch_pad *scratch);
10
- void print_latex_localized_typography(GString *out, int character, scratch_pad *scratch);
11
- void print_latex_string(GString *out, char *str, scratch_pad *scratch);
12
- void print_latex_url(GString *out, char *str, scratch_pad *scratch);
13
- void print_latex_endnotes(GString *out, scratch_pad *scratch);
14
- int find_latex_mode(int format, node *n);
15
-
16
- #endif
@@ -1,177 +0,0 @@
1
- /*
2
-
3
- libMultiMarkdown.h -- MultiMarkdown library header
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 "parser.h"
19
-
20
- /* Main API commands */
21
-
22
- char * markdown_to_string(const char * source, unsigned long extensions, int format);
23
- bool has_metadata(const char *source, unsigned long extensions);
24
- char * extract_metadata_keys(const char *source, unsigned long extensions);
25
- char * extract_metadata_value(const char *source, unsigned long extensions, char *key);
26
- char * mmd_version(void);
27
-
28
-
29
- /* These are the basic extensions */
30
- enum parser_extensions {
31
- EXT_COMPATIBILITY = 1 << 0, /* Markdown compatibility mode */
32
- EXT_COMPLETE = 1 << 1, /* Create complete document */
33
- EXT_SNIPPET = 1 << 2, /* Create snippet only */
34
- EXT_HEAD_CLOSED = 1 << 3, /* for use by parser */
35
- EXT_SMART = 1 << 4, /* Enable Smart quotes */
36
- EXT_NOTES = 1 << 5, /* Enable Footnotes */
37
- EXT_NO_LABELS = 1 << 6, /* Don't add anchors to headers, etc. */
38
- EXT_FILTER_STYLES = 1 << 7, /* Filter out style blocks */
39
- EXT_FILTER_HTML = 1 << 8, /* Filter out raw HTML */
40
- EXT_PROCESS_HTML = 1 << 9, /* Process Markdown inside HTML */
41
- EXT_NO_METADATA = 1 << 10, /* Don't parse Metadata */
42
- EXT_OBFUSCATE = 1 << 11, /* Mask email addresses */
43
- EXT_CRITIC = 1 << 12, /* Critic Markup Support */
44
- EXT_CRITIC_ACCEPT = 1 << 13, /* Accept all proposed changes */
45
- EXT_CRITIC_REJECT = 1 << 14, /* Reject all proposed changes */
46
- EXT_RANDOM_FOOT = 1 << 15, /* Use random numbers for footnote links */
47
- EXT_HEADINGSECTION = 1 << 16, /* Group blocks under parent heading */
48
- EXT_ESCAPED_LINE_BREAKS = 1 << 17, /* Escaped line break */
49
- EXT_FAKE = 1 << 31, /* 31 is highest number allowed */
50
- };
51
-
52
- /* Define output formats we support -- first in list is default */
53
- enum export_formats {
54
- HTML_FORMAT,
55
- TEXT_FORMAT,
56
- LATEX_FORMAT,
57
- MEMOIR_FORMAT,
58
- BEAMER_FORMAT,
59
- OPML_FORMAT,
60
- ODF_FORMAT,
61
- RTF_FORMAT,
62
- ORIGINAL_FORMAT, /* Not currently used */
63
- CRITIC_ACCEPT_FORMAT,
64
- CRITIC_REJECT_FORMAT,
65
- CRITIC_HTML_HIGHLIGHT_FORMAT,
66
- LYX_FORMAT,
67
- TOC_FORMAT,
68
- };
69
-
70
- /* These are the identifiers for node types */
71
- enum keys {
72
- NO_TYPE,
73
- LIST,
74
- STR,
75
- APOSTROPHE,
76
- FOOTER,
77
- PARA,
78
- PLAIN,
79
- LINEBREAK,
80
- SPACE,
81
- HEADINGSECTION,
82
- H1, H2, H3, H4, H5, H6, H7, /* Keep these in order */
83
- METADATA,
84
- METAKEY,
85
- METAVALUE,
86
- MATHSPAN,
87
- STRONG,
88
- EMPH,
89
- LINK,
90
- SOURCE,
91
- TITLE,
92
- REFNAME,
93
- AUTOLABEL,
94
- IMAGE,
95
- IMAGEBLOCK,
96
- NOTEREFERENCE,
97
- CODE,
98
- HTML,
99
- ELLIPSIS,
100
- ENDASH,
101
- EMDASH,
102
- SINGLEQUOTED,
103
- DOUBLEQUOTED,
104
- BLOCKQUOTE,
105
- BLOCKQUOTEMARKER,
106
- RAW,
107
- VERBATIM,
108
- VERBATIMTYPE,
109
- VERBATIMFENCE,
110
- DEFLIST,
111
- TERM,
112
- DEFINITION,
113
- HRULE,
114
- ORDEREDLIST,
115
- BULLETLIST,
116
- LISTITEM,
117
- HTMLBLOCK,
118
- TABLE,
119
- TABLECAPTION,
120
- TABLELABEL,
121
- TABLESEPARATOR,
122
- TABLECELL,
123
- CELLSPAN,
124
- TABLEROW,
125
- TABLEBODY,
126
- TABLEHEAD,
127
- LINKREFERENCE,
128
- NOTESOURCE,
129
- CITATIONSOURCE,
130
- SOURCEBRANCH,
131
- NOTELABEL,
132
- GLOSSARYLABEL,
133
- ATTRVALUE,
134
- ATTRKEY,
135
- GLOSSARYSOURCE,
136
- GLOSSARYSORTKEY,
137
- GLOSSARYTERM,
138
- CITATION,
139
- NOCITATION,
140
- CRITICADDITION,
141
- CRITICDELETION,
142
- CRITICSUBSTITUTION,
143
- CRITICHIGHLIGHT,
144
- CRITICCOMMENT,
145
- SUPERSCRIPT,
146
- SUBSCRIPT,
147
- VARIABLE,
148
- ABBREVIATION,
149
- ABBR,
150
- ABBRSTART,
151
- ABBRSTOP,
152
- TOC,
153
- KEY_COUNTER /* This *MUST* be the last item in the list */
154
- };
155
-
156
-
157
- /* This is the element used in the resulting parse tree */
158
- struct node {
159
- short key; /* what type of element are we? */
160
- char *str; /* relevant string from source for element */
161
- struct link_data *link_data; /* store link info when relevant */
162
- struct node *children; /* child elements */
163
- struct node *next; /* next element */
164
- };
165
-
166
- typedef struct node node;
167
-
168
-
169
- /* Define a structure to simplify handling of links */
170
- struct link_data {
171
- char *label; /* if this is a reference link */
172
- char *source; /* source URL */
173
- char *title; /* title string */
174
- node *attr; /* attribute tree */
175
- };
176
-
177
- typedef struct link_data link_data;
@@ -1,2265 +0,0 @@
1
- /*
2
-
3
- lyx.c -- LyX writer
4
-
5
- (c) 2013 Charles R. Cowan
6
- (c) 2013 Fletcher T. Penney (http://fletcherpenney.net/).
7
-
8
- Derived from MultiMarkdown by Fletcher T. Penney - added code to support the LyX format directly
9
-
10
- Derived from peg-multimarkdown, which was forked from peg-markdown,
11
- which is (c) 2008 John MacFarlane (jgm at berkeley dot edu), and
12
- licensed under GNU GPL or MIT.
13
-
14
- This program is free software; you can redistribute it and/or modify
15
- it under the terms of the GNU General Public License or the MIT
16
- license. See LICENSE for details.
17
-
18
- This program is distributed in the hope that it will be useful,
19
- but WITHOUT ANY WARRANTY; without even the implied warranty of
20
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
- GNU General Public License for more details.
22
-
23
- */
24
-
25
- #include "lyx.h"
26
-
27
- /* #define DEBUG_ON */
28
-
29
- /* #define DUMP_TREES */
30
-
31
- /* allow the user to change the heading levels */
32
-
33
- GString *heading_name[7];
34
- GString *used_abbreviations;
35
-
36
- #if defined(DEBUG_ON) || defined(DUMP_TREES)
37
- const char * const node_types[] = {
38
- "NO_TYPE",
39
- "LIST",
40
- "STR",
41
- "APOSTROPHE",
42
- "FOOTER",
43
- "PARA",
44
- "PLAIN",
45
- "LINEBREAK",
46
- "SPACE",
47
- "HEADINGSECTION",
48
- "H1",
49
- "H2",
50
- "H3",
51
- "H4",
52
- "H5",
53
- "H6",
54
- "H7",
55
- "METADATA",
56
- "METAKEY",
57
- "METAVALUE",
58
- "MATHSPAN",
59
- "STRONG",
60
- "EMPH",
61
- "LINK",
62
- "SOURCE",
63
- "TITLE",
64
- "REFNAME",
65
- "AUTOLABEL",
66
- "IMAGE",
67
- "IMAGEBLOCK",
68
- "NOTEREFERENCE",
69
- "CODE",
70
- "HTML",
71
- "ELLIPSIS",
72
- "ENDASH",
73
- "EMDASH",
74
- "SINGLEQUOTED",
75
- "DOUBLEQUOTED",
76
- "BLOCKQUOTE",
77
- "BLOCKQUOTEMARKER",
78
- "RAW",
79
- "VERBATIM",
80
- "VERBATIMTYPE",
81
- "DEFLIST",
82
- "TERM",
83
- "DEFINITION",
84
- "HRULE",
85
- "ORDEREDLIST",
86
- "BULLETLIST",
87
- "LISTITEM",
88
- "HTMLBLOCK",
89
- "TABLE",
90
- "TABLECAPTION",
91
- "TABLELABEL",
92
- "TABLESEPARATOR",
93
- "TABLECELL",
94
- "CELLSPAN",
95
- "TABLEROW",
96
- "TABLEBODY",
97
- "TABLEHEAD",
98
- "LINKREFERENCE",
99
- "NOTESOURCE",
100
- "CITATIONSOURCE",
101
- "SOURCEBRANCH",
102
- "NOTELABEL",
103
- "GLOSSARYLABEL",
104
- "ATTRVALUE",
105
- "ATTRKEY",
106
- "GLOSSARYSOURCE",
107
- "GLOSSARYSORTKEY",
108
- "GLOSSARYTERM",
109
- "CITATION",
110
- "NOCITATION",
111
- "CRITICADDITION",
112
- "CRITICDELETION",
113
- "CRITICSUBSTITUTION",
114
- "CRITICHIGHLIGHT",
115
- "CRITICCOMMENT",
116
- "SUPERSCRIPT",
117
- "SUBSCRIPT",
118
- "VARIABLE",
119
- "ABBREVIATION",
120
- "ABBR",
121
- "ABBRSTART",
122
- "ABBRSTOP",
123
- "KEY_COUNTER"
124
- };
125
-
126
-
127
- #endif
128
-
129
-
130
- #ifdef DUMP_TREES
131
-
132
- void dump_tree(node* n, scratch_pad *scratch)
133
- {
134
- int i;
135
- while(n != NULL){
136
- scratch->lyx_debug_nest++;
137
- g_string_append(scratch->lyx_debug_pad," "); /* add a level */
138
- fprintf(stderr, "\n\n%sNode: %s",scratch->lyx_debug_pad->str,node_types[n->key]);
139
- fprintf(stderr, "\n%s str: %s",scratch->lyx_debug_pad->str,n->str);
140
- if (n->link_data != NULL){
141
- fprintf(stderr, "\n%s label: %s",scratch->lyx_debug_pad->str,n->link_data->label);
142
- fprintf(stderr, "\n%s source: %s",scratch->lyx_debug_pad->str,n->link_data->source);
143
- fprintf(stderr, "\n%s title: %s",scratch->lyx_debug_pad->str,n->link_data->title);
144
- }
145
- dump_tree(n->children,scratch);
146
- scratch->lyx_debug_nest--;
147
- g_string_free(scratch->lyx_debug_pad,TRUE); /* don' see a way to shorten the string */
148
- scratch->lyx_debug_pad = g_string_new(""); /* so create a new, shorter one */
149
- for(i=0;i<scratch->lyx_debug_nest;i++){
150
- g_string_append(scratch->lyx_debug_pad," ");
151
- }
152
-
153
- n = n->next;
154
- }
155
- }
156
- #endif
157
-
158
-
159
- void perform_lyx_output(GString *out, node* list, scratch_pad *scratch)
160
- {
161
- node *headings;
162
- node *base_header_level;
163
- char *key;
164
-
165
-
166
- #ifdef DUMP_TREES
167
- fprintf(stderr, "\n*** Base Tree ***\n");
168
- dump_tree(list,scratch);
169
- fprintf (stderr, "\n*** End Base Tree ***\n");
170
-
171
- fprintf(stderr, "\n*** LINK Tree ***\n");
172
- dump_tree(scratch->links,scratch);
173
- fprintf(stderr, "\n*** END LINK Tree ***\n");
174
-
175
- #endif
176
-
177
- /* initialize the heading names */
178
- heading_name[0] = g_string_new("Part");
179
- heading_name[1] = g_string_new("Chapter");
180
- heading_name[2] = g_string_new("Section");
181
- heading_name[3] = g_string_new("Subsection");
182
- heading_name[4] = g_string_new("Subsubsection");
183
- heading_name[5] = g_string_new("Paragraph");
184
- heading_name[6] = g_string_new("Subparagraph");
185
-
186
- /* get user supplied heading section names and base header level these both
187
- affect creating the prefixes */
188
-
189
- GString *lyx_headings = g_string_new("");
190
- used_abbreviations = g_string_new("");
191
- int hcount;
192
- hcount = 0;
193
- const char s[2] = ",";
194
- char *token;
195
- char *cleaned;
196
- if (tree_contains_key(list, METAKEY)) {
197
- headings = metadata_for_key("lyxheadings",list);
198
- if (headings != NULL) {
199
- key = metavalue_for_key("lyxheadings",list);
200
- g_string_append(lyx_headings,key);
201
- token = strtok(lyx_headings->str, s);
202
- while( token != NULL ) {
203
- g_string_free(heading_name[hcount],TRUE);
204
- cleaned = clean_string(token);
205
- heading_name[hcount] = g_string_new(cleaned);
206
- free(cleaned);
207
- token = strtok(NULL, s);
208
- hcount++;
209
- if (hcount>6){ /* only 7 allowed */
210
- break;
211
- }
212
- }
213
- free(key);
214
- free(token);
215
- }
216
- }
217
- g_string_free(lyx_headings,TRUE);
218
-
219
- /* get base heading level */
220
- scratch->baseheaderlevel = 1;
221
- if (tree_contains_key(list, METAKEY)) {
222
- base_header_level = metadata_for_key("baseheaderlevel",list);
223
- if (base_header_level != NULL) {
224
- key = metavalue_for_key("baseheaderlevel",list);
225
- scratch->baseheaderlevel = atoi(key);
226
- free(key);
227
- };
228
- };
229
-
230
-
231
- /* add prefixes for LyX references */
232
- add_prefixes(list, list, scratch);
233
-
234
- bool isbeamer;
235
- isbeamer = begin_lyx_output(out,list,scratch); /* get Metadata controls */
236
- if (isbeamer){
237
- g_string_free(heading_name[1],TRUE);
238
- heading_name[1] = g_string_new("Section");
239
- g_string_free(heading_name[2],TRUE);
240
- heading_name[2] = g_string_new("Frame");
241
- print_lyxbeamer_node_tree(out,list,scratch,FALSE);
242
- } else {
243
- print_lyx_node_tree(out,list,scratch,FALSE);
244
- }
245
- end_lyx_output(out,list,scratch); /* Close the document */
246
-
247
- /* clean up the heading names */
248
- int i;
249
- for (i=0;i<=6;i++){
250
- g_string_free(heading_name[i],TRUE);
251
- }
252
- g_string_free(used_abbreviations,TRUE);
253
- }
254
-
255
- /* begin_lyx_output -- Check metadata and open the document */
256
- bool begin_lyx_output(GString *out, node* list, scratch_pad *scratch) {
257
- #ifdef DEBUG_ON
258
- fprintf(stderr, "begin_lyx_output\n");
259
- #endif
260
- node *content;
261
- node *latex_mode;
262
- node *number_headings;
263
- node *clean_pdf;
264
- node *quote_language;
265
- node *modules;
266
- node *packages;
267
- char short_prefix[6];
268
- int i,j;
269
- const char s[2] = ",";
270
- char *key;
271
- char *label;
272
- char *value;
273
- char *temp;
274
- char *token;
275
- char *tmp;
276
- char *cleaned;
277
- bool isbeamer; /* beamer has different processing */
278
-
279
- isbeamer = FALSE; /* only for beamer */
280
-
281
-
282
- /* check for numbered versus unnumbered headings */
283
- scratch->lyx_number_headers = TRUE; /* default - numbering */
284
- if (tree_contains_key(list, METAKEY)) {
285
- number_headings = metadata_for_key("numberheadings",list);
286
- if (number_headings != NULL) {
287
- key = metavalue_for_key("numberheadings",list);
288
- label = label_from_string(key);
289
- if (strcmp(label, "yes") == 0) {
290
- scratch->lyx_number_headers = TRUE;
291
- } else if (strcmp(label, "no") == 0) {
292
- scratch->lyx_number_headers = FALSE;
293
- }
294
- free(label);
295
- free(key);
296
- }
297
- }
298
-
299
- /* Get the language for quotes */
300
- if (tree_contains_key(list, METAKEY)) {
301
- quote_language = metadata_for_key("quoteslanguage",list);
302
- if (quote_language != NULL) {
303
- key = metavalue_for_key("quoteslanguage",list);
304
- temp = label_from_node_tree(quote_language->children);
305
- if ((strcmp(temp, "nl") == 0) || (strcmp(temp, "dutch") == 0)) { scratch->language = DUTCH; } else
306
- if ((strcmp(temp, "de") == 0) || (strcmp(temp, "german") == 0)) { scratch->language = GERMAN; } else
307
- if (strcmp(temp, "germanguillemets") == 0) { scratch->language = GERMANGUILL; } else
308
- if ((strcmp(temp, "fr") == 0) || (strcmp(temp, "french") == 0)) { scratch->language = FRENCH; } else
309
- if ((strcmp(temp, "sv") == 0) || (strcmp(temp, "swedish") == 0)) { scratch->language = SWEDISH; }
310
- free(temp);
311
- free(key);
312
- }
313
- }
314
-
315
- g_string_append(out, "#LyX File created by multimarkdown\n");
316
- g_string_append(out,"\\lyxformat 413\n");
317
- g_string_append(out, "\\begin_document\n");
318
- g_string_append(out, "\\begin_header\n");
319
-
320
- GString *lyx_class = g_string_new("");
321
- if (tree_contains_key(list, METAKEY)) {
322
- latex_mode = metadata_for_key("latexmode",list);
323
- if (latex_mode != NULL) {
324
- key = metavalue_for_key("latexmode",list);
325
- label = label_from_string(key);
326
- g_string_append(lyx_class,label);
327
- if (strcmp(label,"beamer")==0){
328
- isbeamer = TRUE;
329
- }
330
- free(label);
331
- free(key);
332
- } else {
333
- g_string_append(lyx_class,"memoir");
334
- }
335
-
336
- }else{
337
- g_string_append(lyx_class,"memoir");
338
- }
339
- g_string_append(out,"\\textclass ");
340
- g_string_append_printf(out,"%s",lyx_class->str);
341
- g_string_append(out,"\n");
342
-
343
- g_string_append(out,"\\begin_preamble\n");
344
- g_string_append(out,"\\usepackage{listings}\n");
345
- g_string_append(out,"\\usepackage{natbib}\n");
346
- g_string_append(out,"\\usepackage{nomencl}\n");
347
- g_string_append(out,"\\usepackage{booktabs}\n");
348
- g_string_append(out,"\\usepackage{refstyle}\n");
349
- g_string_append(out,"\\usepackage{varioref}\n");
350
-
351
-
352
- if (tree_contains_key(list, METAKEY)) {
353
- packages = metadata_for_key("packages",list);
354
- if (packages != NULL) {
355
- key = metavalue_for_key("packages",list);
356
- tmp = strdup(key);
357
- token = strtok(tmp, s);
358
- while( token != NULL ) {
359
- g_string_append_printf(out,"\\usepackage{%s}\n",clean_string(token));
360
- token = strtok(NULL, s);
361
- }
362
- free(key);
363
- free(tmp);
364
- }
365
- }
366
-
367
- if(isbeamer){
368
- if (tree_contains_key(list, METAKEY)) {
369
- content = metadata_for_key("theme", list);
370
- if (content != NULL) {
371
- value = metavalue_for_key("theme",list);
372
- g_string_append_printf(out,"\\usetheme{%s}\n",value);
373
- free(value);
374
- } else{
375
- g_string_append(out,"\\usetheme{warsaw}\n");
376
- }
377
- } else {
378
- g_string_append(out,"\\usetheme{warsaw}\n");
379
- }
380
- g_string_append(out,"\\setbeamercovered{transparent}\n");
381
- }
382
-
383
- if (tree_contains_key(list, METAKEY)) {
384
- content = metadata_for_key("latex input", list);
385
- if (content != NULL) {
386
- value = metavalue_for_key("latex input",list);
387
- if (strcmp(value,"mmd-natbib-plain")==0){
388
- g_string_append(out,"\\bibpunct{[}{]}{;}{n}{}{,}\n");
389
- }else{
390
- g_string_append(out,"\\bibpunct{(}{)}{,}{a}{,}{,}\n");
391
- }
392
- free(value);
393
- } else{
394
- g_string_append(out,"\\bibpunct{(}{)}{,}{a}{,}{,}\n");
395
- }
396
- } else {
397
- g_string_append(out,"\\bibpunct{(}{)}{,}{a}{,}{,}\n");
398
- }
399
-
400
- /* set up nice referencing */
401
-
402
- if (scratch->lyx_number_headers){
403
- for(i=0;i<7;i++){
404
- strncpy(short_prefix,heading_name[i]->str,5);
405
- short_prefix[5]= '\0'; /* no terminator if strncpy ends because of length */
406
- for(j = 0; short_prefix[j]; j++){
407
- short_prefix[j] = tolower(short_prefix[j]);
408
- }
409
- g_string_append_printf(out,"\\newref{%s}{refcmd={%s \\ref{#1} \\vpageref{#1}}}\n",short_prefix,heading_name[i]->str);
410
- }
411
- g_string_append(out,"\\newref{tab}{refcmd={Table \\ref{#1} \\vpageref{#1}}}\n");
412
- g_string_append(out,"\\newref{fig}{refcmd={Figure \\ref{#1} \\vpageref{#1}}}\n");
413
- } else {
414
- for(i=0;i<7;i++){
415
- strncpy(short_prefix,heading_name[i]->str,5);
416
- short_prefix[5]= '\0'; /* no terminator if strncpy ends because of length */
417
- for(j = 0; short_prefix[j]; j++){
418
- short_prefix[j] = tolower(short_prefix[j]);
419
- }
420
- g_string_append_printf(out,"\\newref{%s}{refcmd={``\\nameref{#1}'' \\vpageref{#1}}}\n",short_prefix);
421
- }
422
- g_string_append(out,"\\newref{tab}{refcmd={Table \\ref{#1} \\vpageref{#1}}}\n");
423
- g_string_append(out,"\\newref{fig}{refcmd={Figure \\ref{#1} \\vpageref{#1}}}\n");
424
-
425
- }
426
-
427
- g_string_append(out,"\\end_preamble\n");
428
-
429
- GString *class_options = g_string_new("\\options refpage");
430
-
431
- if (tree_contains_key(list, METAKEY)) {
432
- clean_pdf = metadata_for_key("cleanpdf",list);
433
- if (clean_pdf != NULL) {
434
- key = metavalue_for_key("cleanpdf",list);
435
- label = label_from_string(key);
436
- if (strcmp(label, "yes") == 0) {
437
- g_string_append(class_options,",hidelinks");
438
- }
439
- free(label);
440
- free(key);
441
- }
442
- }
443
-
444
- if (tree_contains_key(list, METAKEY)) {
445
- content = metadata_for_key("class options", list);
446
- if (content != NULL) {
447
- value = metavalue_for_key("class options",list);
448
- g_string_append(class_options,",");
449
- g_string_append(class_options,value);
450
- free(value);
451
- }
452
- }
453
- g_string_append(class_options,"\n");
454
- g_string_append(out,class_options->str);
455
- g_string_free(class_options,TRUE);
456
-
457
-
458
-
459
- g_string_append(out,"\\begin_modules\n");
460
- if (tree_contains_key(list, METAKEY)) {
461
- modules = metadata_for_key("modules",list);
462
- if (modules != NULL) {
463
- key = metavalue_for_key("modules",list);
464
- tmp = strdup(key);
465
- token = strtok(tmp, s);
466
- while( token != NULL ) {
467
- cleaned = clean_string(token);
468
- g_string_append_printf(out,"%s\n",cleaned);
469
- free(cleaned);
470
- token = strtok(NULL, s);
471
- }
472
- free(key);
473
- free(tmp);
474
- free(token);
475
- }
476
- }
477
- g_string_append(out,"\\end_modules\n");
478
-
479
- g_string_append(out,"\\bibtex_command default\n");
480
- g_string_append(out,"\\cite_engine natbib_authoryear\n");
481
-
482
- g_string_free(lyx_class,TRUE);
483
-
484
- g_string_append(out,"\\end_header\n");
485
- g_string_append(out,"\\begin_body\n");
486
-
487
- if (tree_contains_key(list, METAKEY)) {
488
- content = metadata_for_key("title", list);
489
- if (content != NULL) {
490
- g_string_append(out, "\n\\begin_layout Title\n");
491
- value = metavalue_for_key("title",list);
492
- print_lyx_string(out,value,scratch,LYX_NONE);
493
- free(value);
494
- g_string_append(out, "\n\\end_layout\n");
495
- }
496
- }
497
-
498
- if ((isbeamer) && (tree_contains_key(list, METAKEY))) {
499
- content = metadata_for_key("subtitle", list);
500
- if (content != NULL) {
501
- g_string_append(out, "\n\\begin_layout Subtitle\n");
502
- value = metavalue_for_key("subtitle",list);
503
- print_lyx_string(out,value,scratch,LYX_NONE);
504
- free(value);
505
- g_string_append(out, "\n\\end_layout\n");
506
- }
507
- }
508
-
509
- if (tree_contains_key(list, METAKEY)) {
510
- content = metadata_for_key("author", list);
511
- if (content != NULL) {
512
- g_string_append(out, "\n\\begin_layout Author\n");
513
- value = metavalue_for_key("author",list);
514
- print_lyx_string(out,value,scratch,LYX_NONE);
515
- free(value);
516
- g_string_append(out, "\n\\end_layout\n");
517
- }
518
- }
519
-
520
- if ((isbeamer) && (tree_contains_key(list, METAKEY))){
521
- content = metadata_for_key("affiliation", list);
522
- if (content != NULL) {
523
- g_string_append(out, "\n\\begin_layout Institute\n");
524
- value = metavalue_for_key("affiliation",list);
525
- print_lyx_string(out,value,scratch,LYX_NONE);
526
- free(value);
527
- g_string_append(out, "\n\\end_layout\n");
528
- }
529
- }
530
-
531
- if (tree_contains_key(list, METAKEY)) {
532
- content = metadata_for_key("date", list);
533
- if (content != NULL) {
534
- g_string_append(out, "\n\\begin_layout Date\n");
535
- value = metavalue_for_key("date",list);
536
- print_lyx_string(out,value,scratch,LYX_NONE);
537
- free(value);
538
- g_string_append(out, "\n\\end_layout\n");
539
- }
540
- }
541
-
542
- if (tree_contains_key(list, METAKEY)) {
543
- content = metadata_for_key("abstract", list);
544
- if (content != NULL) {
545
- g_string_append(out, "\n\\begin_layout Abstract\n");
546
- value = metavalue_for_key("abstract",list);
547
- print_lyx_string(out,value,scratch,LYX_NONE);
548
- free(value);
549
- g_string_append(out, "\n\\end_layout\n");
550
- }
551
- }
552
- return isbeamer;
553
- }
554
-
555
- /* end_lyx_output -- close the document */
556
- void end_lyx_output(GString *out, node* list, scratch_pad *scratch) {
557
- node *content;
558
- char *value;
559
- #ifdef DEBUG_ON
560
- fprintf(stderr, "end_lyx_output\n");
561
- #endif
562
-
563
-
564
- /* Handle BibTeX */
565
-
566
- if (tree_contains_key(list, METAKEY)) {
567
- content = metadata_for_key("bibtex",list);
568
- if (content != NULL) {
569
- g_string_append(out, "\n\\begin_layout Standard\n");
570
- g_string_append(out,"\n\\begin_inset CommandInset bibtex");
571
- g_string_append(out,"\nLatexCommand bibtex");
572
- value = metavalue_for_key("bibtex",list);
573
- g_string_append_printf(out,"\nbibfiles \"%s\"",value);
574
- free(value);
575
- g_string_append(out,"\noptions \"plainnat\"");
576
- g_string_append(out,"\n\n\\end_inset");
577
- g_string_append(out, "\n\n\\end_layout\n");
578
- }
579
- }
580
-
581
- g_string_append(out, "\n\\end_body\n");
582
- g_string_append(out, "\\end_document\n");
583
- }
584
-
585
- bool is_lyx_complete_doc(node *meta);
586
-
587
-
588
- /* print_lyx_node_tree -- convert node tree to Lyx */
589
- void print_lyx_node_tree(GString *out, node *list, scratch_pad *scratch, bool no_newline) {
590
- #ifdef DEBUG_ON
591
- int i;
592
- scratch->lyx_debug_nest++;
593
- g_string_append(scratch->lyx_debug_pad," "); /* add a level */
594
- fprintf(stderr, "\n%sStart_print_Node_Tree: %s\n",scratch->lyx_debug_pad->str,node_types[scratch->lyx_para_type]);
595
- scratch->lyx_debug_nest++;
596
- g_string_append(scratch->lyx_debug_pad," "); /* add a level */
597
- #endif
598
- while (list != NULL) {
599
- print_lyx_node(out, list, scratch, no_newline);
600
- list = list->next;
601
- }
602
- #ifdef DEBUG_ON
603
- scratch->lyx_debug_nest--;
604
- g_string_free(scratch->lyx_debug_pad,TRUE); /* don' see a way to shorten the string */
605
- scratch->lyx_debug_pad = g_string_new(""); /* so create a new, shorter one */
606
- for(i=0;i<scratch->lyx_debug_nest;i++)
607
- g_string_append(scratch->lyx_debug_pad," ");
608
- fprintf(stderr, "\n%sEnd_print_Node_Tree: %s\n",scratch->lyx_debug_pad->str,node_types[scratch->lyx_para_type]);
609
- scratch->lyx_debug_nest--;
610
- g_string_free(scratch->lyx_debug_pad,TRUE); /* don' see a way to shorten the string */
611
- scratch->lyx_debug_pad = g_string_new(""); /* so create a new, shorter one */
612
- for(i=0;i<scratch->lyx_debug_nest;i++)
613
- g_string_append(scratch->lyx_debug_pad," ");
614
- #endif
615
- }
616
-
617
- /* print_lyx_node -- convert given node to Lyx and append */
618
- void print_lyx_node(GString *out, node *n, scratch_pad *scratch, bool no_newline) {
619
- node *temp_node;
620
- node *tcaption;
621
- char *temp;
622
- char *prefixed_label;
623
- int lev;
624
- char *width = NULL;
625
- char *height = NULL;
626
- GString *temp_str;
627
- GString *raw_str;
628
- char char_temp;
629
- int i;
630
- int old_type;
631
- int rows;
632
- int cols;
633
- int multicol;
634
- int colwidth;
635
-
636
- if (n == NULL)
637
- return;
638
-
639
- /* debugging statement */
640
- #ifdef DEBUG_ON
641
- fprintf(stderr, "\n%sprint_lyx_node: %s\n",scratch->lyx_debug_pad->str,node_types[n->key]);
642
- fprintf(stderr,"%scontent: %s\n",scratch->lyx_debug_pad->str,n->str);
643
- #endif
644
-
645
- switch (n->key) {
646
- case NO_TYPE:
647
- break;
648
- case LIST:
649
- print_lyx_node_tree(out,n->children,scratch, no_newline);
650
- break;
651
- case STR:
652
- print_lyx_string(out,n->str, scratch,LYX_NONE);
653
- break;
654
- case ABBREVIATION:
655
- // this work was done in writer.c
656
- break;
657
- case ABBRSTART:
658
- /* Strip out nodes that are being replaced with the abbreviation */
659
- temp_node = n->next;
660
- while (temp_node->key != ABBRSTOP) {
661
- n->next = temp_node->next;
662
- temp_node->next = NULL;
663
- free_node(temp_node);
664
- temp_node = n->next;
665
- }
666
- n->next = temp_node->next;
667
- temp_node->next = NULL;
668
- free_node(temp_node);
669
- case ABBR:
670
- /* In either case, now we call on the abbreviation */
671
- // width = ascii_label_from_node(n->children->children);
672
- width = string_from_node_tree(n->children->children);
673
- // temp = ascii_label_from_string(n->children->str);
674
- temp_str = g_string_new("");
675
- g_string_append_printf(temp_str,"[%s]",width);
676
- if(strstr(used_abbreviations->str,temp_str->str)){
677
- g_string_append(out,width); // just the abbrev
678
- }
679
- else
680
- {
681
- g_string_append(used_abbreviations,temp_str->str);
682
-
683
-
684
- g_string_append(out,n->children->str);
685
- g_string_append_printf(out," (%s)",width);
686
-
687
-
688
- g_string_append(out,"\n\\begin_inset CommandInset nomenclature");
689
- g_string_append(out,"\nLatexCommand nomenclature");
690
- g_string_append_printf(out,"\nsymbol \"%s\"",width);
691
- g_string_append(out,"\ndescription \"");
692
- // g_string_append(out,n->children->str);
693
- temp = escape_string(n->children->str);
694
- g_string_append(out,temp);
695
- g_string_append(out,"\"");
696
- g_string_append(out, "\n\\end_inset\n");
697
- free(temp);
698
- }
699
- g_string_free(temp_str,TRUE);
700
- free(width);
701
- break;
702
- case ABBRSTOP:
703
- break;
704
- case SPACE:
705
- if (strncmp(n->str,"\n",1)==0){
706
- if (no_newline){
707
- g_string_append(out," "); /* just a space */
708
- } else{
709
- g_string_append_printf(out,"%s ",n->str); /* lyx needs the space */
710
- }
711
- }else{
712
- g_string_append_printf(out,"%s",n->str);
713
- }
714
- break;
715
- case PLAIN: /* act as if all items are wrapped in a paragraph */
716
- case PARA:
717
- #ifdef DEBUG_ON
718
- fprintf(stderr, "\n%sprint_lyx_paragraph: %s\n",scratch->lyx_debug_pad->str,node_types[scratch->lyx_para_type]);
719
- fprintf(stderr,"%scontent: %s\n",scratch->lyx_debug_pad->str,n->str);
720
- #endif
721
- /* definition list special case, must append first definition to the term */
722
- if (scratch -> lyx_para_type == DEFINITION){
723
- if (!scratch->lyx_definition_open){ /* first definition after a term */
724
- g_string_append(out,"\n ");
725
- print_lyx_node_tree(out,n->children,scratch, FALSE); /* stick on the end of the term */
726
- g_string_append(out,"\n\\end_layout\n");
727
- scratch->lyx_definition_open = TRUE; /* first definition after a term hit */
728
- } else{
729
- g_string_append(out,"\n\n\\begin_deeper\n"); // second (or nth definition)
730
- g_string_append(out, "\n\\begin_layout Standard\n"); /* treat it as a paragraph */
731
- print_lyx_node_tree(out,n->children,scratch, FALSE);
732
- g_string_append(out, "\n\\end_layout\n");
733
- g_string_append(out,"\n\\end_deeper\n");
734
- }
735
- break;
736
- }
737
- switch (scratch->lyx_para_type) {
738
- case BLOCKQUOTE:
739
- g_string_append(out, "\n\\begin_layout Quote\n");
740
- break;
741
- case ORDEREDLIST:
742
- g_string_append(out, "\n\\begin_layout Enumerate\n");
743
- if (scratch-> lyx_beamerbullet){
744
- g_string_append(out,"\n\\begin_inset Argument 1");
745
- g_string_append(out,"\nstatus open\n");
746
- g_string_append(out,"\n\\begin_layout Plain Layout");
747
- g_string_append(out,"\n<+->");
748
- g_string_append(out,"\n\\end_layout\n");
749
- g_string_append(out,"\n\\end_inset\n");
750
- scratch -> lyx_beamerbullet = FALSE;
751
- }
752
- break;
753
- case BULLETLIST:
754
- g_string_append(out, "\n\\begin_layout Itemize\n");
755
- if (scratch-> lyx_beamerbullet){
756
- g_string_append(out,"\n\\begin_inset Argument 1");
757
- g_string_append(out,"\nstatus open\n");
758
- g_string_append(out,"\n\\begin_layout Plain Layout");
759
- g_string_append(out,"\n+-");
760
- g_string_append(out,"\n\\end_layout\n");
761
- g_string_append(out,"\n\\end_inset\n");
762
- scratch -> lyx_beamerbullet = FALSE;
763
- }
764
- break;
765
- case NOTEREFERENCE:
766
- case CITATION:
767
- case NOCITATION:
768
- g_string_append(out, "\n\\begin_inset Foot");
769
- g_string_append(out, "\nstatus collapsed\n");
770
- g_string_append(out, "\n\\begin_layout Plain Layout");
771
- break;
772
- case NOTESOURCE:
773
- case CITATIONSOURCE:
774
- break; /* no enclosure by an environment */
775
- case GLOSSARYSOURCE:
776
- g_string_append(out,"\ndescription \"");
777
- break;
778
- default:
779
- g_string_append(out, "\n\\begin_layout Standard\n");
780
- break;
781
- }
782
- print_lyx_node_tree(out,n->children,scratch, FALSE);
783
- if (scratch->lyx_para_type == GLOSSARYSOURCE){
784
- g_string_append(out,"\"\n");
785
- } else if ((scratch->lyx_para_type != NOTESOURCE) &&
786
- (scratch->lyx_para_type != CITATIONSOURCE)){
787
- g_string_append(out, "\n\\end_layout\n");
788
- }
789
- if ((scratch->lyx_para_type == CITATION) ||
790
- (scratch->lyx_para_type == NOCITATION)) {
791
- g_string_append(out,"\n\\end_layout\n");
792
- g_string_append(out,"\n\\end_inset");
793
- }
794
- break;
795
- case HRULE:
796
- g_string_append(out,"\n\\begin_layout Standard\n");
797
- g_string_append(out,"\n\\begin_inset CommandInset line\n");
798
- g_string_append(out,"LatexCommand rule\n");
799
- g_string_append(out,"offset \"0.5ex\"\n");
800
- g_string_append(out,"width \"100col%\"\n");
801
- g_string_append(out,"height \"1pt\"\n");
802
- g_string_append(out,"\n\\end_inset\n");
803
- g_string_append(out,"\n\\end_layout\n");
804
- break;
805
- case HTMLBLOCK:
806
- /* don't print HTML block */
807
- /* but do print HTML comments for raw LaTeX */
808
- if (strncmp(n->str,"<!--",4) == 0) {
809
- /* trim "-->" from end */
810
- n->str[strlen(n->str)-3] = '\0';
811
- g_string_append(out, "\n\\begin_layout Plain Layout\n\\begin_inset ERT\nstatus collapsed\n\n\\begin_layout Plain Layout\n\n");
812
- print_latex_string(out,&n->str[4],scratch);
813
- g_string_append(out,"\n\n\\end_layout\n\n\\end_inset\n\\end_layout\n");
814
- }
815
- break;
816
- case VERBATIM:
817
- case VERBATIMFENCE:
818
- old_type = scratch->lyx_para_type;
819
- scratch->lyx_para_type = VERBATIM;
820
- scratch->lyx_level++;
821
- if (scratch->lyx_level > 1){
822
- g_string_append(out,"\n\\begin_deeper\n");
823
- }
824
- g_string_append(out,"\\begin_layout Standard\n");
825
- g_string_append(out,"\\begin_inset listings\n");
826
- if ((n->children != NULL) && (n->children->key == VERBATIMTYPE)) {
827
- trim_trailing_whitespace(n->children->str);
828
- if (strlen(n->children->str) > 0) {
829
- // NOTE: the language must match the LyX (LaTex) languages (e.g: Perl, not perl)
830
- g_string_append_printf(out, "lstparams \"basicstyle={\\footnotesize\\ttfamily},language=%s\"\n", n->children->str,n->str);
831
- }
832
- else {
833
- g_string_append(out,"lstparams \"basicstyle={\\footnotesize\\ttfamily}\"\n");
834
- }
835
- } else {
836
- g_string_append(out,"lstparams \"basicstyle={\\footnotesize\\ttfamily}\"\n");
837
- }
838
- g_string_append(out,"inline false\n");
839
- g_string_append(out,"status collapsed\n");
840
- print_lyx_string(out, n->str, scratch,LYX_PLAIN); /* it is not children - just \n separated lines */
841
- g_string_append(out,"\n\\end_inset\n");
842
- g_string_append(out,"\\end_layout\n");
843
- scratch->lyx_level--;
844
- if (scratch->lyx_level > 0){
845
- g_string_append(out,"\n\\end_deeper\n");
846
- }
847
- scratch->lyx_para_type = old_type;
848
- break;
849
- case BULLETLIST:
850
- case ORDEREDLIST:
851
- case DEFLIST:
852
- if (n->key == DEFLIST){
853
- scratch->lyx_definition_hit = TRUE;
854
- scratch->lyx_definition_open = FALSE;
855
- }
856
- old_type = scratch->lyx_para_type;
857
- scratch->lyx_para_type = n->key;
858
- scratch->lyx_level++;
859
- if (scratch->lyx_level > 1){
860
- g_string_append(out,"\n\\begin_deeper\n");
861
- }
862
- print_lyx_node_tree(out, n->children, scratch, FALSE);
863
- scratch->lyx_level--;
864
- if (scratch->lyx_level > 0){
865
- g_string_append(out,"\n\\end_deeper\n");
866
- }
867
- scratch->lyx_para_type = old_type;
868
- scratch->lyx_definition_open = FALSE;
869
- break;
870
- case LISTITEM:
871
- #ifdef DEBUG_ON
872
- fprintf(stderr, "\nStart List Item\n");
873
- #endif
874
- old_type = scratch->lyx_para_type;
875
- temp_node = n-> children; /* should be a list node */
876
- if(temp_node->children == NULL) {
877
- g_string_append(out,"\n\\begin_layout Itemize\n\\end_layout\n"); /* empty list item */
878
- }
879
- else {
880
- i = 0;
881
- temp_node = temp_node-> children; /* process the list */
882
- /* the first paragraph is the list item's first paragraph */
883
- print_lyx_node(out,temp_node,scratch,no_newline);
884
- /* now process any other content, including additional lists */
885
- temp_node = temp_node-> next;
886
- while ((temp_node != NULL) && (temp_node->key != BULLETLIST)
887
- && (temp_node->key != ORDEREDLIST) && (temp_node->key != DEFLIST)){
888
- i++;
889
- if (i == 1){
890
- g_string_append(out,"\n\\begin_deeper\n");
891
- old_type = scratch->lyx_para_type;
892
- scratch->lyx_para_type = PARA; /* and make it a paragraph, not a list item */
893
- }
894
- print_lyx_node(out, temp_node, scratch, no_newline);
895
- temp_node = temp_node->next;
896
- }
897
- if (i>0){
898
- i--;
899
- scratch->lyx_para_type = old_type; /* reset the paragraph type */
900
- g_string_append(out,"\n\\end_deeper\n");
901
- }
902
- if (temp_node != NULL){ /* have hid an imbedded list */
903
- print_lyx_node(out,temp_node,scratch,no_newline);
904
- }
905
- }
906
- #ifdef DEBUG_ON
907
- fprintf(stderr, "\nEnd List Item\n");
908
- #endif
909
- break;
910
- case METADATA:
911
- /* metadata we care about already handled */
912
- break;
913
- case METAKEY:
914
- /* metadata we care about already handled */
915
- break;
916
- case METAVALUE:
917
- /* metadata we care about already handled */
918
- break;
919
- case FOOTER:
920
- print_lyx_endnotes(out, scratch);
921
- break;
922
- case HEADINGSECTION:
923
- print_lyx_node_tree(out,n->children,scratch , FALSE);
924
- break;
925
- case H1: case H2: case H3: case H4: case H5: case H6:
926
- lev = n->key - H1 + scratch->baseheaderlevel; /* assumes H1 ... H6 are in order */
927
- if (lev > 7)
928
- lev = 7; /* Max at level 7 */
929
- GString *environment = g_string_new("\n\\begin_layout ");
930
- g_string_append(environment,heading_name[lev-1]->str); /* get the (possibly user modified) section name */
931
-
932
- if (!scratch->lyx_number_headers){
933
- g_string_append(environment,"*\n");} /* mark as unnumbered */
934
- else{
935
- g_string_append(environment,"\n");
936
- };
937
- /* Begin the environment */
938
- g_string_append_printf(out,"%s",environment->str);
939
- g_string_free(environment,true);
940
- /* Don't allow footnotes */
941
- scratch->no_lyx_footnote = TRUE;
942
- if (n->children->key == AUTOLABEL) {
943
- /* use label for header since one was specified (MMD)*/
944
- temp = label_from_string(n->children->str);
945
- prefixed_label = prefix_label(heading_name[lev-1]->str,temp,FALSE);
946
- print_lyx_node_tree(out, n->children->next, scratch , FALSE);
947
- g_string_append(out,"\n\\begin_inset CommandInset label\n");
948
- g_string_append(out,"LatexCommand label\n");
949
- g_string_append_printf(out, "name \"%s\"",prefixed_label);
950
- g_string_append(out,"\n\\end_inset\n");
951
- free(prefixed_label);
952
- free(temp);
953
- } else {
954
- /* generate a label by default for MMD */
955
- temp = label_from_node_tree(n->children);
956
- prefixed_label = prefix_label(heading_name[lev-1]->str,temp,FALSE);
957
- print_lyx_node_tree(out, n->children, scratch, FALSE);
958
- g_string_append(out,"\n\\begin_inset CommandInset label\n");
959
- g_string_append(out,"LatexCommand label\n");
960
- g_string_append_printf(out, "name \"%s\"",prefixed_label);
961
- g_string_append(out,"\n\\end_inset\n");
962
- free(prefixed_label);
963
- free(temp);
964
- }
965
- scratch->no_lyx_footnote = FALSE;
966
- g_string_append(out,"\n\\end_layout\n");
967
- break;
968
- case APOSTROPHE:
969
- print_lyx_localized_typography(out, APOS, scratch);
970
- break;
971
- case ELLIPSIS:
972
- print_lyx_localized_typography(out, ELLIP, scratch);
973
- break;
974
- case EMDASH:
975
- print_lyx_localized_typography(out, MDASH, scratch);
976
- break;
977
- case ENDASH:
978
- print_lyx_localized_typography(out, NDASH, scratch);
979
- break;
980
- case SINGLEQUOTED:
981
- print_lyx_localized_typography(out, LSQUOTE, scratch);
982
- print_lyx_node_tree(out, n->children, scratch, FALSE);
983
- print_lyx_localized_typography(out, RSQUOTE, scratch);
984
- break;
985
- case DOUBLEQUOTED:
986
- print_lyx_localized_typography(out, LDQUOTE, scratch);
987
- print_lyx_node_tree(out, n->children, scratch, FALSE);
988
- print_lyx_localized_typography(out, RDQUOTE, scratch);
989
- break;
990
- case LINEBREAK:
991
- g_string_append(out, "\n\\begin_inset Newline newline\n\\end_inset\n");
992
- break;
993
- case MATHSPAN:
994
- if (n->str[0] == '$') {
995
- if (n->str[1] == '$') {
996
- if (strncmp(&n->str[2],"\\begin",5) == 0) {
997
- n->str[strlen(n->str)-2] = '\0';
998
- g_string_append_printf(out, "\n\\begin_inset Formula %s\n\\end_inset\n",&n->str[1]);
999
- } else {
1000
- g_string_append_printf(out, "\n\\begin_inset Formula %s\n\\end_inset\n",n->str);
1001
- }
1002
- } else {
1003
- if (strncmp(&n->str[1],"\\begin",5) == 0) {
1004
- n->str[strlen(n->str)-1] = '\0';
1005
- g_string_append_printf(out, "\n\\begin_inset Formula %s\n\\end_inset\n",&n->str[1]);
1006
- } else {
1007
- g_string_append_printf(out, "\n\\begin_inset Formula %s\n\\end_inset\n",n->str);
1008
- }
1009
- }
1010
- } else if (strncmp(&n->str[2],"\\begin",5) == 0) {
1011
- /* trim */
1012
- n->str[strlen(n->str)-3] = '\0';
1013
- g_string_append_printf(out, "\n\\begin_inset Formula %s\n\\end_inset\n", &n->str[2]);
1014
- } else {
1015
- if (n->str[strlen(n->str)-1] == ']') {
1016
- n->str[strlen(n->str)-3] = '\0';
1017
- g_string_append(out,"\\begin_inset Formula \n\\[");
1018
- g_string_append_printf(out, "\n%s\n\\]\n\\end_inset\n", &n->str[2]);
1019
- } else {
1020
- n->str[strlen(n->str)-3] = '\0';
1021
- g_string_append_printf(out, "\n\\begin_inset Formula $%s$\n\\end_inset\n", &n->str[2]);
1022
- }
1023
- }
1024
- break;
1025
- case STRONG:
1026
- g_string_append(out, "\n\\series bold\n");
1027
- print_lyx_node_tree(out,n->children,scratch, FALSE);
1028
- g_string_append(out, "\n\\series default\n");
1029
- break;
1030
- case EMPH:
1031
- g_string_append(out, "\n\\emph on\n");
1032
- print_lyx_node_tree(out,n->children,scratch, FALSE);
1033
- g_string_append(out, "\n\\emph default\n");
1034
- break;
1035
- case LINKREFERENCE:
1036
- break;
1037
- case LINK:
1038
- #ifdef DEBUG_ON
1039
- fprintf(stderr, "print LyX link: '%s'\n",n->str);
1040
- #endif
1041
-
1042
- /* Do we have proper info? */
1043
-
1044
- if (n->link_data == NULL) {
1045
- /* NULL link_data could occur if we parsed this link before and it didn't
1046
- match anything */
1047
- n->link_data = mk_link_data(NULL, NULL, NULL, NULL);
1048
- }
1049
-
1050
- if ((n->link_data->label == NULL) &&
1051
- (n->link_data->source == NULL)) {
1052
- #ifdef DEBUG_ON
1053
- fprintf(stderr, "print LyX link: '%s'\n",n->str);
1054
- #endif
1055
- /* we seem to be a [foo][] style link */
1056
- /* so load a label */
1057
- temp_str = g_string_new("");
1058
- print_raw_node_tree(temp_str, n->children);
1059
- /* replace new-lines with spaces */
1060
- temp = temp_str->str;
1061
- while (*temp != '\0'){
1062
- if (*temp == '\n'){
1063
- *temp = ' ';
1064
- }
1065
- temp++;
1066
- }
1067
- free(n->link_data->label);
1068
- n->link_data->label = temp_str->str;
1069
- g_string_free(temp_str, FALSE);
1070
- }
1071
- #ifdef DEBUG_ON
1072
- fprintf(stderr, "look for reference data for LyX link: '%s'\n",n->str);
1073
- #endif
1074
- /* Load reference data */
1075
- if (n->link_data->label != NULL) {
1076
- #ifdef DEBUG_ON
1077
- fprintf(stderr, "have label for LyX link: '%s'\n",n->str);
1078
- #endif
1079
- temp = strdup(n->link_data->label);
1080
- free_link_data(n->link_data);
1081
- n->link_data = extract_link_data(temp, scratch);
1082
-
1083
- if (n->link_data == NULL) {
1084
- /* replace original text since no definition found */
1085
- g_string_append(out, "[");
1086
- print_lyx_node(out, n->children, scratch, FALSE);
1087
- g_string_append(out,"]");
1088
- if (n->children->next != NULL) {
1089
- g_string_append(out, "[");
1090
- print_lyx_node_tree(out, n->children->next, scratch, FALSE);
1091
- g_string_append(out,"]");
1092
- } else if (n->str != NULL) {
1093
- /* no title label, so see if we stashed str*/
1094
- g_string_append_printf(out, "%s", n->str);
1095
- } else {
1096
- g_string_append_printf(out, "[%s]",temp);
1097
- }
1098
- free(temp);
1099
- break;
1100
- }
1101
- free(temp);
1102
- }
1103
- temp_str = g_string_new("");
1104
- print_lyx_node_tree(temp_str, n->children, scratch, TRUE);
1105
- raw_str = g_string_new("");
1106
- print_raw_node_tree(raw_str, n->children);
1107
- /* replace new-lines with spaces */
1108
- temp = raw_str->str;
1109
- while (*temp != '\0'){
1110
- if (*temp == '\n'){
1111
- *temp = ' ';
1112
- }
1113
- temp++;
1114
- }
1115
- if ((n->link_data->source != NULL) && (n->link_data->source[0] == '#' )) {
1116
-
1117
- /* link to anchor within the document */
1118
- if (strlen(temp_str->str) > 0) {
1119
- /* We have text before the link */
1120
- g_string_append_printf(out, "%s (", temp_str->str);
1121
- }
1122
-
1123
- if (n->link_data->label == NULL) {
1124
- if ((n->link_data->source != NULL) && (n->link_data->source[0] == '#' )) {
1125
- /* This link was specified as [](#bar) */
1126
- g_string_append(out,"\n\\begin_inset CommandInset ref");
1127
- g_string_append_printf(out,"\nLatexCommand formatted");
1128
- g_string_append_printf(out,"\nreference \"%s\"\n",n->link_data->source + 1);
1129
- g_string_append(out,"\n\\end_inset\n");
1130
-
1131
- } else {
1132
- g_string_append_printf(out, "\n\\begin_inset CommandInset href\nLatexCommand href\ntarget \"%s\"\n", n->link_data->source);
1133
- g_string_append(out, "\"\n\n\\end_inset\n");
1134
-
1135
- }
1136
- } else {
1137
- g_string_append(out,"\n\\begin_inset CommandInset ref");
1138
- g_string_append_printf(out,"\nLatexCommand formatted");
1139
- g_string_append_printf(out,"\nreference \"%s\"\n",n->link_data->source + 1);
1140
- g_string_append(out,"\n\\end_inset\n");
1141
- }
1142
- if (strlen(temp_str->str) > 0) {
1143
- g_string_append(out, ")");
1144
- }
1145
- } else if (strcmp(raw_str->str, n->link_data->source) == 0){
1146
- /* This is a <link> */
1147
- g_string_append_printf(out, "\n\\begin_inset CommandInset href\nLatexCommand href\ntarget \"%s\"\n", n->link_data->source);
1148
- g_string_append_printf(out,"name \"%s\"",temp_str->str);
1149
- g_string_append(out, "\n\n\\end_inset\n");
1150
- } else if (strcmp(raw_str->str,&n->link_data->source[7]) == 0) {
1151
- /*This is a <mailto> */
1152
- g_string_append_printf(out, "\n\\begin_inset CommandInset href\nLatexCommand href\ntarget \"%s\"\n", n->link_data->source);
1153
- g_string_append_printf(out,"name \"%s\"",temp_str->str);
1154
- g_string_append(out,"\ntype \"mailto:\"");
1155
- g_string_append(out, "\n\n\\end_inset\n");
1156
- } else {
1157
- g_string_append_printf(out, "\n\\begin_inset CommandInset href\nLatexCommand href\ntarget \"%s\"\n", n->link_data->source);
1158
- g_string_append(out,"name \"");
1159
-
1160
- g_string_free(temp_str,TRUE);
1161
- temp_str = g_string_new("");
1162
- print_escaped_node_tree(out,n->children);
1163
-
1164
- g_string_append(out, "\"\n\n\\end_inset\n");
1165
- if (scratch->no_lyx_footnote == FALSE) {
1166
- g_string_append(out, "\n\\begin_inset Foot\nstatus collapsed\n\n\\begin_layout Plain Layout\n");
1167
- g_string_append(out, "\n\\begin_inset CommandInset href\nLatexCommand href\n");
1168
- g_string_append_printf(out,"\nname \"%s\"",n->link_data->source);
1169
- g_string_append_printf(out,"\ntarget \"%s\"",n->link_data->source);
1170
- g_string_append(out,"\n\n\\end_inset");
1171
- g_string_append(out, "\n\\end_layout\n\n\\end_inset\n");
1172
- }
1173
- }
1174
- g_string_free(temp_str, TRUE);
1175
- g_string_free(raw_str, true);
1176
- n->link_data->attr = NULL;
1177
- break;
1178
- case ATTRKEY:
1179
- g_string_append_printf(out, " %s=\"%s\"", n->str,
1180
- n->children->str);
1181
- break;
1182
- case REFNAME:
1183
- case SOURCE:
1184
- case TITLE:
1185
- break;
1186
- case IMAGEBLOCK:
1187
- case IMAGE:
1188
- #ifdef DEBUG_ON
1189
- fprintf(stderr, "print image\n");
1190
- #endif
1191
- /* Do we have proper info? */
1192
- if ((n->link_data->label == NULL) &&
1193
- (n->link_data->source == NULL)) {
1194
- /* we seem to be a [foo][] style link */
1195
- /* so load a label */
1196
- temp_str = g_string_new("");
1197
- print_raw_node_tree(temp_str, n->children);
1198
- n->link_data->label = temp_str->str;
1199
- g_string_free(temp_str, FALSE);
1200
- }
1201
- /* Load reference data */
1202
- if (n->link_data->label != NULL) {
1203
- temp = strdup(n->link_data->label);
1204
- free_link_data(n->link_data);
1205
- n->link_data = extract_link_data(temp, scratch);
1206
-
1207
- if (n->link_data == NULL) {
1208
- /* replace original text since no definition found */
1209
- g_string_append(out, "![");
1210
- print_lyx_node(out, n->children, scratch, FALSE);
1211
- g_string_append(out,"]");
1212
- if (n->children->next != NULL) {
1213
- g_string_append(out, "[");
1214
- print_lyx_node_tree(out, n->children->next, scratch, FALSE);
1215
- g_string_append(out,"]");
1216
- } else if (n->str != NULL) {
1217
- /* no title label, so see if we stashed str*/
1218
- g_string_append_printf(out, "%s", n->str);
1219
- } else {
1220
- g_string_append_printf(out, "[%s]",temp);
1221
- }
1222
- free(temp);
1223
- break;
1224
- }
1225
- free(temp);
1226
- }
1227
-
1228
- if (n->key == IMAGEBLOCK){
1229
- g_string_append(out,"\n\\begin_layout Standard"); /* needs to be in an environment */
1230
- g_string_append(out,"\n\\begin_inset Float figure");
1231
- g_string_append(out,"\nwide false");
1232
- g_string_append(out,"\nsideways false");
1233
- g_string_append(out,"\nstatus collapsed");
1234
- g_string_append(out, "\n\n\\begin_layout Plain Layout");
1235
- }
1236
-
1237
- g_string_append(out,"\n\\begin_inset Graphics");
1238
-
1239
- g_string_append_printf(out, "\n\t filename %s\n",n->link_data->source);
1240
-
1241
- #ifdef DEBUG_ON
1242
- fprintf(stderr, "attributes\n");
1243
- #endif
1244
-
1245
- if (n->link_data->attr != NULL) {
1246
- temp_node = node_for_attribute("height",n->link_data->attr);
1247
- if (temp_node != NULL)
1248
- height = correct_dimension_units(temp_node->children->str);
1249
- temp_node = node_for_attribute("width",n->link_data->attr);
1250
- if (temp_node != NULL)
1251
- width = correct_dimension_units(temp_node->children->str);
1252
- }
1253
-
1254
- if (width != NULL) {
1255
- if (width[strlen(width)-1] == '%') {
1256
- width[strlen(width)-1] = '\0';
1257
- g_string_append_printf(out, "\tlyxscale %s\n", width);
1258
- g_string_append_printf(out, "\tscale %s\n",width);
1259
- } else {
1260
- g_string_append_printf(out, "\twidth %s\n",width);
1261
- }
1262
- }
1263
-
1264
- if (height != NULL) {
1265
- if (height[strlen(height)-1] == '%') {
1266
- height[strlen(height)-1] = '\0';
1267
- g_string_append_printf(out, "\tlyxscale %s\n",height);
1268
- g_string_append_printf(out, "\tscale %s\n",height);
1269
- } else {
1270
- g_string_append_printf(out, "\theight %s\n",height);
1271
- }
1272
- }
1273
- g_string_append(out,"\n\\end_inset\n");
1274
-
1275
- if (n->key == IMAGEBLOCK) {
1276
- g_string_append(out,"\n\n\\end_layout\n");
1277
- if (n->children != NULL) {
1278
- g_string_append(out,"\n\\begin_layout Plain Layout");
1279
- g_string_append(out,"\n\\begin_inset Caption");
1280
- g_string_append(out,"\n\n\\begin_layout Plain Layout\n");
1281
- print_lyx_node_tree(out, n->children, scratch, FALSE);
1282
- g_string_append(out,"\n\\end_layout\n");
1283
- g_string_append(out,"\n\\end_inset");
1284
- if (n->link_data->label != NULL) {
1285
- g_string_append(out,"\n\n\\begin_inset CommandInset label");
1286
- g_string_append(out,"\nLatexCommand label\n");
1287
- temp = label_from_string(n->link_data->label);
1288
- g_string_append_printf(out, "\nname \"fig:%s\"",temp);
1289
- g_string_append(out,"\n\\end_inset");
1290
- free(temp);
1291
- }
1292
- g_string_append(out,"\n\\end_layout\n");
1293
- g_string_append(out,"\n\\end_inset\n");
1294
- }
1295
-
1296
- g_string_append(out, "\n\\end_layout\n");
1297
- }
1298
-
1299
- free(height);
1300
- free(width);
1301
- n->link_data->attr = NULL; /* We'll delete these elsewhere */
1302
- break;
1303
- #ifdef DEBUG_ON
1304
- fprintf(stderr, "finish image\n");
1305
- #endif
1306
- case NOTEREFERENCE:
1307
- lev = note_number_for_node(n, scratch);
1308
- temp_node = node_for_count(scratch->used_notes, lev);
1309
- if (temp_node->key == GLOSSARYSOURCE) {
1310
- g_string_append(out,"\n\\begin_inset CommandInset nomenclature");
1311
- g_string_append(out,"\nLatexCommand nomenclature");
1312
- scratch->lyx_para_type = temp_node->key;
1313
- print_lyx_node_tree(out, temp_node->children, scratch, FALSE);
1314
- scratch->lyx_para_type = NO_TYPE;
1315
- g_string_append(out, "\n\\end_inset\n");
1316
- } else {
1317
- g_string_append(out, "\n\\begin_inset Foot");
1318
- g_string_append(out,"\nstatus collapsed\n\n");
1319
- old_type = scratch->lyx_para_type;
1320
- scratch->lyx_para_type = PARA;
1321
- print_lyx_node_tree(out, temp_node->children, scratch, FALSE);
1322
- scratch->lyx_para_type = old_type;
1323
- g_string_append(out, "\n\n\\end_inset\n");
1324
- }
1325
- break;
1326
- case NOCITATION:
1327
- case CITATION:
1328
- #ifdef DEBUG_ON
1329
- fprintf(stderr, "\nprint cite\n");
1330
- #endif
1331
- if ((n->link_data != NULL) && (strncmp(n->link_data->label,"[#",2) == 0)) {
1332
- /* external citation (e.g. BibTeX) */
1333
- n->link_data->label[strlen(n->link_data->label)-1] = '\0';
1334
- if (n->key == NOCITATION) {
1335
- g_string_append(out,"\n\\begin_inset CommandInset citation");
1336
- g_string_append(out,"\nLatexCommand nocite");
1337
- g_string_append_printf(out,"\nkey \"%s\"",&n->str[2]);
1338
- g_string_append(out,"\n\n\\end_inset\n");
1339
- } else {
1340
- g_string_append(out, "<FAKE span class=\"externalcitation\">");
1341
- g_string_append(out, "</span>");
1342
- }
1343
- } else {
1344
- #ifdef DEBUG_ON
1345
- fprintf(stderr, "internal cite\n");
1346
- #endif
1347
- /* MMD citation, so output as footnote */
1348
- /* TODO: create separate stream from footnotes */
1349
- lev = note_number_for_label(n->link_data->label, scratch);
1350
- if (lev != 0) {
1351
- #ifdef DEBUG_ON
1352
- fprintf(stderr, "matching cite found\n");
1353
- #endif
1354
- temp_node = node_for_count(scratch->used_notes, lev);
1355
- /* flag that this is used as a citation */
1356
- temp_node->key = CITATIONSOURCE;
1357
- if (lev > scratch->max_footnote_num) {
1358
- scratch->max_footnote_num = lev;
1359
- }
1360
- if (n->key == NOCITATION) {
1361
- g_string_append(out,"\n\\begin_inset CommandInset citation");
1362
- g_string_append(out,"\nLatexCommand nocite");
1363
- g_string_append_printf(out,"\nkey \"%s\"",n->link_data->label);
1364
- g_string_append(out,"\n\n\\end_inset\n");
1365
- } else {
1366
- if (n->children != NULL) {
1367
- g_string_append(out,"\n\\begin_inset CommandInset citation");
1368
- g_string_append(out,"\nLatexCommand cite");
1369
- g_string_append(out, "\nafter \"");
1370
- print_lyx_node(out, n->children, scratch, FALSE);
1371
- g_string_append_printf(out,"\"\nkey \"%s\"",n->link_data->label);
1372
- g_string_append(out,"\n\n\\end_inset\n");
1373
- } else {
1374
- g_string_append(out,"\n\\begin_inset CommandInset citation");
1375
- g_string_append(out,"\nLatexCommand cite");
1376
- g_string_append_printf(out,"\nkey \"%s\"",n->link_data->label);
1377
- g_string_append(out,"\n\n\\end_inset\n");
1378
- }
1379
- }
1380
- } else {
1381
- /* not located -- this is external cite */
1382
- #ifdef DEBUG_ON
1383
- fprintf(stderr, "no match for cite: '%s'\n",n->link_data->label);
1384
- #endif
1385
- temp = n->link_data->label;
1386
- if (n->key == NOCITATION) {
1387
- g_string_append(out,"\n\\begin_inset CommandInset citation");
1388
- g_string_append(out,"\nLatexCommand nocite");
1389
- g_string_append_printf(out,"\nkey \"%s\"",n->link_data->label);
1390
- g_string_append(out,"\n\n\\end_inset\n");
1391
- } else {
1392
- if (n->children != NULL) {
1393
- #ifdef DEBUG_ON
1394
- fprintf(stderr, "cite with children\n");
1395
- #endif
1396
- if (strcmp(&temp[strlen(temp) - 1],";") == 0) {
1397
- g_string_append(out, " \\citet[");
1398
- temp[strlen(temp) - 1] = '\0';
1399
- } else {
1400
- g_string_append(out,"\n\\begin_inset CommandInset citation");
1401
- g_string_append(out,"\nLatexCommand cite");
1402
- g_string_append(out, "\nafter \"");
1403
- }
1404
- print_lyx_node(out, n->children, scratch, FALSE);
1405
- g_string_append_printf(out,"\"\nkey \"%s\"",temp);
1406
- g_string_append(out,"\n\n\\end_inset\n");
1407
- } else {
1408
- #ifdef DEBUG_ON
1409
- fprintf(stderr, "cite without children. locat:'%s'\n",n->str);
1410
- #endif
1411
- if (strcmp(&temp[strlen(temp) - 1],";") == 0) {
1412
- temp[strlen(temp) - 1] = '\0';
1413
- g_string_append_printf(out, " \\citet{%s}",temp);
1414
- } else {
1415
- g_string_append(out,"\n\\begin_inset CommandInset citation");
1416
- g_string_append(out,"\nLatexCommand cite");
1417
- g_string_append_printf(out,"\nkey \"%s\"",temp);
1418
- g_string_append(out,"\n\n\\end_inset\n");
1419
- }
1420
- }
1421
- }
1422
- }
1423
- }
1424
- #ifdef DEBUG_ON
1425
- fprintf(stderr, "finish cite\n");
1426
- #endif
1427
- break;
1428
- case VARIABLE:
1429
- temp = metavalue_for_key(n->str,scratch->result_tree);
1430
- if (temp == NULL) {
1431
- g_string_append_printf(out, "[%%%s]",n->str);
1432
- } else {
1433
- g_string_append_printf(out, temp);
1434
- free(temp);
1435
- }
1436
- break;
1437
- case GLOSSARYTERM:
1438
- if ((n->next != NULL) && (n->next->key == GLOSSARYSORTKEY) ) {
1439
- g_string_append(out, "\nprefix \"");
1440
- print_lyx_string(out, n->next->str, scratch,LYX_NONE);
1441
- g_string_append(out, "\"");
1442
- }
1443
- g_string_append(out,"\nsymbol \"");
1444
- print_latex_string(out, n->children->str, scratch);
1445
- g_string_append(out, "\"");
1446
- break;
1447
- case GLOSSARYSORTKEY:
1448
- break;
1449
- case CODE:
1450
- g_string_append(out, "\n\\family typewriter\n");
1451
- print_lyx_string(out, n->str, scratch,LYX_CODE);
1452
- g_string_append(out, "\n\\family default\n");
1453
- break;
1454
- case BLOCKQUOTEMARKER:
1455
- print_lyx_node_tree(out, n->children, scratch, FALSE);
1456
- break;
1457
- case BLOCKQUOTE: /* can be nested - make it work like lists */
1458
- old_type = scratch->lyx_para_type;
1459
- scratch->lyx_para_type = n->key;
1460
- scratch->lyx_level++;
1461
- if (scratch->lyx_level > 1){
1462
- g_string_append(out,"\n\\begin_deeper\n");
1463
- }
1464
- print_lyx_node_tree(out, n->children, scratch, FALSE);
1465
- scratch->lyx_level--;
1466
- if (scratch->lyx_level > 0){
1467
- g_string_append(out,"\n\\end_deeper\n");
1468
- }
1469
- scratch->lyx_para_type = old_type;
1470
- break;
1471
- case RAW:
1472
- /* This shouldn't happen */
1473
- g_string_append(out, "RAW:");
1474
- g_string_append_printf(out,"%s",n->str);
1475
- break;
1476
- case HTML:
1477
- /* Handle HTML Reserved Characters */
1478
- if (strncmp(n->str,"&quot;",6) == 0){
1479
- g_string_append(out,"\"");
1480
- break;
1481
- } else if (strncmp(n->str,"&apos;",6) == 0){
1482
- g_string_append(out,"'");
1483
- break;
1484
- } else if (strncmp(n->str,"&amp;",5) == 0){
1485
- g_string_append(out,"&");
1486
- break;
1487
- } else if (strncmp(n->str,"&lt;",4) == 0){
1488
- g_string_append(out,"<");
1489
- break;
1490
- } else if (strncmp(n->str,"&gt;",4) == 0){
1491
- g_string_append(out,">");
1492
- break;
1493
- };
1494
-
1495
- /* don't print HTML block */
1496
- /* but do print HTML comments for raw LaTeX */
1497
- if (strncmp(n->str,"<!--",4) == 0) {
1498
- /* trim "-->" from end */
1499
- n->str[strlen(n->str)-3] = '\0';
1500
- // g_string_append(out, "\n\\begin_layout Plain Layout\n\\begin_inset ERT\nstatus collapsed\n\n\\begin_layout Plain Layout\n\n");
1501
- g_string_append(out, "\n\\begin_inset ERT\nstatus collapsed\n\n\\begin_layout Plain Layout\n\n");
1502
- print_lyx_string(out,&n->str[4],scratch,LYX_NONE);
1503
- // g_string_append(out,"\n\n\\end_layout\n\\end_inset\n\\end_layout\n");
1504
- g_string_append(out,"\n\n\\end_layout\n\\end_inset\n");
1505
- }
1506
- break;
1507
- case TERM:
1508
- scratch->lyx_definition_open = FALSE; /* and it is closed */
1509
- old_type = scratch->lyx_para_type;
1510
- scratch->lyx_para_type = n->key;
1511
- if (scratch->lyx_definition_hit){
1512
- g_string_append(out,"\n\\begin_layout Labeling");
1513
- g_string_append(out,"\n\\labelwidthstring 00.00.0000\n");
1514
- g_string_append(out,"\n\\series bold\n");
1515
- scratch -> lyx_definition_hit = FALSE; /* waiting for it to start a new set of terms */
1516
- } else { /* multiple terms, join with commas */
1517
- g_string_append(out,",");
1518
- g_string_append(out,"\n\\begin_inset space ~\n\\end_inset\n");
1519
- }
1520
- temp_str = g_string_new("");
1521
- print_lyx_node_tree(temp_str, n->children, scratch, FALSE);
1522
- /* replace spaces with protected spaces */
1523
- temp = temp_str->str;
1524
- while (*temp != '\0'){
1525
- if (*temp == ' '){
1526
- g_string_append(out,"\n\\begin_inset space ~\n\\end_inset\n");
1527
- } else{
1528
- g_string_append_printf(out,"%c",*temp);
1529
- }
1530
- temp++;
1531
- }
1532
- g_string_free(temp_str,TRUE);
1533
- scratch->lyx_para_type = old_type;
1534
- break;
1535
- case DEFINITION:
1536
- if (!scratch -> lyx_definition_hit){
1537
- g_string_append(out,"\n\\series default\n"); /* close bolding */
1538
- }
1539
- scratch -> lyx_definition_hit = TRUE; /* have hit the definiton thus we can start a new one */
1540
- old_type = scratch->lyx_para_type;
1541
- scratch->lyx_para_type = n->key;
1542
- print_lyx_node_tree(out, n->children, scratch, FALSE);
1543
- scratch->lyx_para_type = old_type;
1544
- break;
1545
- case TABLE:
1546
- scratch->lyx_table_caption = NULL;
1547
- /* need to check the caption here in order to decide whether to increment the number of rows */
1548
- tcaption = n->children;
1549
- if (tcaption->key == TABLECAPTION) {
1550
- scratch->lyx_table_caption = tcaption;
1551
- }
1552
- scratch->table_row = 0;
1553
- scratch->table_column = 0;
1554
- lyx_get_table_dimensions(n->children,&rows,&cols,scratch);
1555
- scratch->lyx_table_total_rows = rows;
1556
- if (scratch->lyx_table_caption != NULL){
1557
- rows++; /* caption goes on the first row */
1558
- }
1559
- scratch->lyx_table_total_cols = cols;
1560
- g_string_append(out,"\n\\begin_layout Standard");
1561
- g_string_append(out,"\n\\begin_inset Tabular");
1562
- g_string_append_printf(out,"\n<lyxtabular version=\"3\" rows=\"%d\" columns=\"%d\">",rows, cols);
1563
- g_string_append(out,"\n<features booktabs=\"true\" tabularvalignment=\"middle\" islongtable=\"true\" longtabularalignment=\"center\">");
1564
-
1565
- print_lyx_node_tree(out, n->children, scratch, FALSE); /* table body */
1566
- g_string_append(out, "\n</lyxtabular>");
1567
- g_string_append(out,"\n\\end_inset");
1568
- g_string_append(out, "\n\\end_layout\n");
1569
- scratch->lyx_table_caption = NULL;
1570
- scratch->table_alignment = NULL;
1571
- break;
1572
- case TABLESEPARATOR:
1573
- colwidth = 100/scratch->lyx_table_total_cols;
1574
- scratch->table_alignment = n->str;
1575
- for (i=0;i<scratch->lyx_table_total_cols;i++){
1576
- temp_str = g_string_new("");
1577
- char_temp = scratch->table_alignment[i];
1578
- switch(char_temp){
1579
- case 'c':
1580
- case 'C':
1581
- g_string_append(temp_str,"center");
1582
- break;
1583
- case 'r':
1584
- case 'R':
1585
- g_string_append(temp_str,"right");
1586
- break;
1587
- case 'l':
1588
- case 'L':
1589
- g_string_append(temp_str,"left");
1590
- break;
1591
- }
1592
- g_string_append_printf(out,"\n<column alignment=\"%s\" valignment=\"top\" width=\"%dcol%%\">",temp_str->str,colwidth);
1593
- g_string_free(temp_str,TRUE);
1594
- }
1595
- break;
1596
- case TABLECAPTION:
1597
- /* handled above */
1598
- break;
1599
- case TABLELABEL:
1600
- break;
1601
- case TABLEHEAD:
1602
- if (scratch-> lyx_table_caption != NULL){ /* if there is a caption */
1603
- g_string_append(out,"\n<row caption=\"true\">");
1604
- g_string_append(out,"\n<cell multicolumn=\"1\" alignment=\"left\" valignment=\"top\" usebox=\"none\">");
1605
- g_string_append(out,"\n\\begin_inset Text\n");
1606
- g_string_append(out,"\n\\begin_layout Plain Layout");
1607
- g_string_append(out,"\n\\begin_inset Caption\n");
1608
- g_string_append(out,"\n\\begin_layout Plain Layout\n");
1609
- print_lyx_node_tree(out, scratch->lyx_table_caption->children, scratch, FALSE);
1610
- if ((scratch->lyx_table_caption->children != NULL) && (scratch->lyx_table_caption->children->key == TABLELABEL)) {
1611
- temp = label_from_string(scratch->lyx_table_caption->children->str);
1612
- } else {
1613
- temp = label_from_node_tree(scratch->lyx_table_caption->children);
1614
- }
1615
- g_string_append(out,"\n\\end_layout\n");
1616
- g_string_append(out,"\n\\end_inset");
1617
- g_string_append(out,"\n\n\\begin_inset CommandInset label");
1618
- g_string_append(out,"\nLatexCommand label\n");
1619
- g_string_append_printf(out, "\nname \"tab:%s\"",temp);
1620
- g_string_append(out,"\n\\end_inset");
1621
- g_string_append(out,"\n\\end_layout\n");
1622
- g_string_append(out,"\n\\end_inset\n");
1623
- g_string_append(out,"\n</cell>");
1624
- for (i=0;i<scratch->lyx_table_total_cols-1;i++){
1625
- g_string_append(out,"\n<cell multicolumn=\"2\" alignment=\"center\" valignment=\"top\" topline=\"true\" bottomline=\"true\" leftline=\"true\" usebox=\"none\">");
1626
- g_string_append(out,"\n\\begin_inset Text\n");
1627
- g_string_append(out,"\n\\begin_layout Plain Layout\n");
1628
- g_string_append(out,"\n\\end_layout\n");
1629
- g_string_append(out,"\n\\end_inset");
1630
- g_string_append(out,"\n</cell>");
1631
- }
1632
- g_string_append(out,"\n</row>");
1633
- free(temp);
1634
- }
1635
- scratch->lyx_table_need_line = TRUE;
1636
- scratch->lyx_in_header = TRUE;
1637
- print_lyx_node_tree(out, n->children, scratch, FALSE);
1638
- scratch->lyx_in_header = FALSE;
1639
- break;
1640
- case TABLEBODY:
1641
- scratch->lyx_table_need_line = TRUE;
1642
- print_lyx_node_tree(out, n->children, scratch, FALSE);
1643
- break;
1644
- case TABLEROW:
1645
- if (scratch->lyx_in_header){
1646
- g_string_append(out, "\n<row endhead=\"true\" endfirsthead=\"true\">");
1647
- } else {
1648
- g_string_append(out, "\n<row>");
1649
- }
1650
- scratch->table_column = 0;
1651
- print_lyx_node_tree(out, n->children, scratch, FALSE);
1652
- g_string_append(out,"\n</row>");
1653
- scratch->lyx_table_need_line = FALSE;
1654
- scratch->table_row++;
1655
- break;
1656
- case TABLECELL:
1657
- temp_str = g_string_new("");
1658
- char_temp = scratch->table_alignment[scratch->table_column];
1659
- switch(char_temp){
1660
- case 'c':
1661
- case 'C':
1662
- g_string_append(temp_str,"center");
1663
- break;
1664
- case 'r':
1665
- case 'R':
1666
- g_string_append(temp_str,"right");
1667
- break;
1668
- case 'l':
1669
- case 'L':
1670
- g_string_append(temp_str,"left");
1671
- break;
1672
- }
1673
- multicol = 1;
1674
- if ((n->children != NULL) && (n->children->key == CELLSPAN)){
1675
- multicol = (int)strlen(n->children->str)+1;
1676
- }
1677
- for(i=1;i<=multicol;i++){
1678
-
1679
- g_string_append(out,"\n<cell" ) ;
1680
- if (multicol > 1) {
1681
- g_string_append_printf(out, " multicolumn=\"%d\"",i);
1682
- }
1683
- g_string_append_printf(out, " alignment=\"%s\"",temp_str->str);
1684
- g_string_append(out, " valignment=\"top\"");
1685
-
1686
- if (scratch->lyx_table_need_line){
1687
- g_string_append(out," topline=\"true\"" );
1688
- }
1689
- if (scratch->table_row >= scratch->lyx_table_total_rows-1){
1690
- g_string_append(out," bottomline=\"true\"" );
1691
- }
1692
-
1693
- g_string_append(out," usebox=\"none\"");
1694
-
1695
- g_string_append(out,">");
1696
-
1697
- g_string_append(out,"\n\\begin_inset Text");
1698
- g_string_append(out,"\n\n\\begin_layout Plain Layout\n");
1699
-
1700
- print_lyx_node_tree(out, n->children, scratch, FALSE);
1701
-
1702
- g_string_append(out,"\n\\end_layout\n");
1703
- g_string_append(out,"\n\n\\end_inset");
1704
- g_string_append(out,"\n</cell>");
1705
- }
1706
- g_string_free(temp_str,TRUE);
1707
- scratch->table_column++;
1708
- break;
1709
- case CELLSPAN:
1710
- break;
1711
- case GLOSSARYSOURCE: /* handled inline */
1712
- break;
1713
- case NOTESOURCE: /* handled inline */
1714
- break;
1715
- case CITATIONSOURCE:
1716
- scratch->lyx_para_type = n-> key;
1717
- print_lyx_node(out, n->children, scratch, FALSE);
1718
- break;
1719
- case SOURCEBRANCH:
1720
- fprintf(stderr,"SOURCEBRANCH\n");
1721
- break;
1722
- case NOTELABEL:
1723
- case GLOSSARYLABEL:
1724
- break;
1725
- case SUPERSCRIPT:
1726
- g_string_append_printf(out, "\n\\begin_inset script superscript\n\n\\begin_layout Plain Layout\n%s\n\\end_layout\n\n\\end_inset\n",n->str);
1727
- break;
1728
- case SUBSCRIPT:
1729
- g_string_append_printf(out, "\n\\begin_inset script subscript\n\n\\begin_layout Plain Layout\n%s\n\\end_layout\n\n\\end_inset\n",n->str);
1730
- break;
1731
- case KEY_COUNTER:
1732
- break;
1733
- case TOC:
1734
- print_lyx_node_tree(out,n->children, scratch, false);
1735
- break;
1736
- default:
1737
- fprintf(stderr, "print_lyx_node encountered unknown node key = %d\n",n->key);
1738
- exit(EXIT_FAILURE);
1739
- }
1740
- }
1741
-
1742
- /* print_lyx_endnotes */
1743
- void print_lyx_endnotes(GString *out, scratch_pad *scratch) {
1744
- node *temp_node;
1745
- bool do_nomenclature;
1746
- scratch->used_notes = reverse_list(scratch->used_notes);
1747
- node *note = scratch->used_notes;
1748
- #ifdef DEBUG_ON
1749
- fprintf(stderr, "start endnotes\n");
1750
- #endif
1751
-
1752
- /* Handle Glossary or abbreviations */
1753
- do_nomenclature = false;
1754
- if (strcmp(used_abbreviations->str,"")!=0){ // if any abbreviations have been used, print a glossary
1755
- do_nomenclature = true;
1756
- } else
1757
- {
1758
- temp_node = note;
1759
- while (temp_node != NULL){
1760
- if(temp_node->key == GLOSSARYSOURCE){
1761
- do_nomenclature = true;
1762
- break;
1763
- }
1764
- temp_node = temp_node->next;
1765
- }
1766
- }
1767
-
1768
- if (do_nomenclature){
1769
- g_string_append(out,"\n\\begin_layout Standard");
1770
- g_string_append(out,"\n\\begin_inset CommandInset nomencl_print");
1771
- g_string_append(out,"\nLatexCommand printnomenclature");
1772
- g_string_append(out,"\nset_width \"auto\"\n");
1773
- g_string_append(out,"\n\\end_inset\n");
1774
- g_string_append(out,"\n\\end_layout\n");
1775
- }
1776
-
1777
- if (note == NULL)
1778
- return;
1779
-
1780
- note = scratch->used_notes;
1781
-
1782
- #ifdef DEBUG_ON
1783
- fprintf(stderr, "there are endnotes to print\n");
1784
- #endif
1785
-
1786
- while ( note != NULL) {
1787
- if (note->key == KEY_COUNTER) {
1788
- note = note->next;
1789
- continue;
1790
- }
1791
-
1792
- if (note->key == CITATIONSOURCE) {
1793
- g_string_append(out, "\n\\begin_layout Bibliography\n");
1794
- g_string_append(out,"\\begin_inset CommandInset bibitem\n");
1795
- g_string_append(out,"LatexCommand bibitem\n");
1796
- g_string_append_printf(out, "key \"%s\"\n", note->str);
1797
- g_string_append_printf(out, "label \"%s\"\n", note->str);
1798
- g_string_append(out,"\n\\end_inset\n");
1799
- print_lyx_node(out, note, scratch, FALSE);
1800
- g_string_append(out,"\n\\end_layout\n");
1801
- } else {
1802
- /* footnotes handled elsewhere */
1803
- }
1804
-
1805
- note = note->next;
1806
- }
1807
-
1808
-
1809
- #ifdef DEBUG_ON
1810
- fprintf(stderr, "\n\\end_layout\n");
1811
- #endif
1812
- }
1813
-
1814
- /* print_lyx_localized_typography -- convert to "smart" typography */
1815
- void print_lyx_localized_typography(GString *out, unsigned char character, scratch_pad *scratch) {
1816
- if (!extension(EXT_SMART, scratch->extensions)) {
1817
- g_string_append_c(out, character);
1818
- return;
1819
- }
1820
- switch (character) {
1821
- case LSQUOTE:
1822
- case 0x91:
1823
- switch (scratch->language) {
1824
- case SWEDISH:
1825
- g_string_append(out, "'");
1826
- break;
1827
- case FRENCH:
1828
- g_string_append(out,"'");
1829
- break;
1830
- case GERMAN:
1831
- g_string_append(out,"‚");
1832
- break;
1833
- case GERMANGUILL:
1834
- g_string_append(out,"›");
1835
- break;
1836
- default:
1837
- g_string_append(out,"\n\\begin_inset Quotes els\n\\end_inset\n");
1838
- }
1839
- break;
1840
- case RSQUOTE:
1841
- case 0x92:
1842
- switch (scratch->language) {
1843
- case GERMAN:
1844
- g_string_append(out,"`");
1845
- break;
1846
- case GERMANGUILL:
1847
- g_string_append(out,"‹");
1848
- break;
1849
- default:
1850
- g_string_append(out,"\n\\begin_inset Quotes ers\n\\end_inset\n");
1851
- }
1852
- break;
1853
- case APOS:
1854
- g_string_append(out,"'");
1855
- break;
1856
- case LDQUOTE:
1857
- case 0x93:
1858
- switch (scratch->language) {
1859
- case DUTCH:
1860
- case GERMAN:
1861
- g_string_append(out,"„");
1862
- break;
1863
- case GERMANGUILL:
1864
- g_string_append(out,"»");
1865
- break;
1866
- case FRENCH:
1867
- g_string_append(out,"«");
1868
- break;
1869
- case SWEDISH:
1870
- g_string_append(out, "''");
1871
- break;
1872
- default:
1873
- g_string_append(out,"\n\\begin_inset Quotes eld\n\\end_inset\n");
1874
- }
1875
- break;
1876
- case RDQUOTE:
1877
- case 0x94:
1878
- switch (scratch->language) {
1879
- case SWEDISH:
1880
- case DUTCH:
1881
- g_string_append(out,"''");
1882
- break;
1883
- case GERMAN:
1884
- g_string_append(out,"``");
1885
- break;
1886
- case GERMANGUILL:
1887
- g_string_append(out,"«");
1888
- break;
1889
- case FRENCH:
1890
- g_string_append(out,"»");
1891
- break;
1892
- default:
1893
- g_string_append(out,"\n\\begin_inset Quotes erd\n\\end_inset\n");
1894
- }
1895
- break;
1896
- case NDASH:
1897
- case 0x96:
1898
- g_string_append(out,"--");
1899
- break;
1900
- case MDASH:
1901
- case 0x97:
1902
- g_string_append(out,"---");
1903
- break;
1904
- case ELLIP:
1905
- case 0x85:
1906
- if(scratch->lyx_para_type != GLOSSARYSOURCE){
1907
- g_string_append(out,"\n\\SpecialChar \\ldots{}\n");
1908
- } else{
1909
- g_string_append(out,"...");
1910
- }
1911
- break;
1912
- default:;
1913
- }
1914
- }
1915
-
1916
- /* print_lyx_string - print string, escaping and formatting for LYX */
1917
- void print_lyx_string(GString *out, char *str, scratch_pad *scratch, short environment) {
1918
- char *tmp;
1919
- char *start;
1920
- unsigned char extended_character;
1921
- if (str == NULL)
1922
- return;
1923
- start = str; /* Store start of string */
1924
- if (environment == LYX_PLAIN) {
1925
- g_string_append(out,"\n\\begin_layout Plain Layout\n\n");
1926
- }
1927
- while (*str != '\0') {
1928
- /* first look for unicode so it doesn't get caught in the "smart quote" processing */
1929
- /* will use a huristic of looking for a sequence that begins with two bytes of */
1930
- /* the format 11xxxxxx 10xxxxxxxx to indicate a unicode sting */
1931
- /* this is Ok if the second byte is the terminator ('\0') because it is all zeros and won't match */
1932
- if ((((unsigned char)*str & 0xc0) == 0xc0) && ((((unsigned char)*(str+1)) & 0xc0) == 0x80)) { /* hit unicode (huristic */
1933
- g_string_append_c(out, *str);
1934
- str++;
1935
- while ((((unsigned char)*str != '\0')) && (((unsigned char)*str & 0xc0) == 0x80)){
1936
- g_string_append_c(out,*str); /* send out the other bytes */
1937
- str++;
1938
- }
1939
- } else {
1940
- switch ((unsigned char)*str) { /* cast to handle the "smart quotes" outside the ASCII range - they are in there */
1941
- case '\\':
1942
- g_string_append(out,"\n\\backslash\n\n");
1943
- break;
1944
- case '\"':
1945
- if (environment == LYX_PLAIN){
1946
- g_string_append(out,"\"");
1947
- } else {
1948
- g_string_append(out,"\n\\begin_inset Quotes erd\n\\end_inset\n");
1949
- }
1950
- break;
1951
- case '\n':
1952
- if(environment == LYX_PLAIN) {
1953
- if (*(str+1) == '\0'){ /* skip last new line */
1954
- break;
1955
- }
1956
- g_string_append(out,"\n\\end_layout\n\n\\begin_layout Plain Layout\n\n");
1957
- } else {
1958
- tmp = str;
1959
- tmp--;
1960
- if ((tmp > start) && (*tmp == ' ')) {
1961
- g_string_append(out,"\n");
1962
- } else {
1963
- g_string_append(out, "\n "); /* add a space */
1964
- }
1965
- }
1966
- break;
1967
- case '<': /* look for HTML comment LaTeX escape */
1968
- if ( (environment != LYX_CODE) && (environment != LYX_PLAIN) && (strncmp(str,"<!--",4) == 0)){
1969
- str+=4; /* move past delimeter */
1970
- g_string_append(out, "\n\\begin_layoutPlain Layout\n\\begin_inset ERT\nstatus collapsed\n\n\\begin_layout Plain Layout\n\n");
1971
- while(strncmp(str,"-->",3) !=0){
1972
- switch (*str){
1973
- case '\\':
1974
- g_string_append(out,"\n\\backslash\n\n");
1975
- break;
1976
- case '\"':
1977
- g_string_append(out,"\n\\begin_inset Quotes erd\n\\end_inset\n\\end_layout\n");
1978
- break;
1979
- default:
1980
- g_string_append_c(out,*str);
1981
- }
1982
- str++;
1983
- }
1984
- str+=2; /* and past the end delimeter */
1985
- g_string_append(out,"\n\n\\end_layout\n\\end_inset\n");
1986
- }
1987
- else {
1988
- g_string_append_c(out, *str);
1989
- }
1990
- break;
1991
- /* handle "smart Quotes" and other "non ASCII" characters */
1992
- case 0x91:
1993
- case 0x92:
1994
- case 0x93:
1995
- case 0x94:
1996
- case 0x96:
1997
- case 0x97:
1998
- case 0x85:
1999
- extended_character = str[0];
2000
- print_lyx_localized_typography(out,extended_character,scratch);
2001
- break;
2002
- default:
2003
- g_string_append_c(out, *str);
2004
- }
2005
- str++;
2006
- }
2007
- }
2008
- if (environment == LYX_PLAIN) {
2009
- g_string_append(out,"\n\\end_layout\n");
2010
- }
2011
- }
2012
-
2013
- /* print_lyx_url - print url, escaping for LYX */
2014
- void print_lyx_url(GString *out, char *str, scratch_pad *scratch) {
2015
- if (str == NULL)
2016
- return;
2017
- while (*str != '\0') {
2018
- switch (*str) {
2019
- case '$': case '%': case '!':
2020
- case '&': case '_': case '#':
2021
- g_string_append_printf(out, "\\%c", *str);
2022
- break;
2023
- case '^':
2024
- g_string_append(out, "\\^{}");
2025
- break;
2026
- default:
2027
- g_string_append_c(out, *str);
2028
- }
2029
- str++;
2030
- }
2031
- }
2032
-
2033
- /* lyx_get_table_dimensions - find the dimensions of a table (rows and columns) */
2034
- void lyx_get_table_dimensions(node* list, int *rows, int *cols, scratch_pad *scratch){
2035
- int tmp_rows;
2036
- int tmp_cols;
2037
- *rows = 0;
2038
- *cols = 0;
2039
- tmp_rows = 0;
2040
- tmp_cols = 0;
2041
- while (list != NULL) {
2042
- switch (list->key){
2043
- case TABLEHEAD:
2044
- case TABLEBODY:
2045
- lyx_get_table_dimensions(list->children, &tmp_rows, &tmp_cols, scratch);
2046
- *rows += tmp_rows;
2047
- if (tmp_cols > *cols) {*cols = tmp_cols;};
2048
- break;
2049
- case TABLEROW:
2050
- (*rows)++;
2051
- lyx_get_table_dimensions(list->children, &tmp_rows, &tmp_cols,scratch);
2052
- if (tmp_cols>*cols) {*cols = tmp_cols;};
2053
- break;
2054
- case TABLECELL:
2055
- (*cols)++;
2056
- break;
2057
- }
2058
- list = list->next;
2059
- }
2060
- }
2061
- /* add_prefixes -- go through node tree and find elements created from headers, figures, and tables
2062
- add the prefix so LyX can create proper references */
2063
- void add_prefixes(node *list, node *root, scratch_pad *scratch) {
2064
- char *label;
2065
- GString *pound_label;
2066
- int lev;
2067
-
2068
-
2069
- while (list != NULL) {
2070
- switch (list->key) {
2071
- case H1: case H2: case H3: case H4: case H5: case H6:
2072
- lev = list->key - H1 + scratch->baseheaderlevel;
2073
- if (lev > 7)
2074
- lev = 7; /* Max at level 7 */
2075
- if (list->children->key != AUTOLABEL) {
2076
- label = label_from_node_tree(list->children);
2077
- } else{
2078
- label = label_from_string(list->children->str);
2079
- }
2080
-
2081
- /* update any links in the tree */
2082
-
2083
- pound_label = g_string_new("#");
2084
- g_string_append(pound_label,label);
2085
- update_link_source(pound_label->str,heading_name[lev-1]->str,root);
2086
-
2087
-
2088
- /* and any in the "links" list */
2089
-
2090
- update_links(pound_label->str,heading_name[lev-1]->str,scratch);
2091
-
2092
- g_string_free(pound_label,TRUE);
2093
- free(label);
2094
- break;
2095
- case TABLE:
2096
- if (list->children->key == TABLECAPTION) {
2097
- if (list->children->children->key == TABLELABEL){
2098
- label = label_from_string(list->children->children->str);
2099
- } else {
2100
- label = label_from_node_tree(list->children->children);
2101
- }
2102
- pound_label = g_string_new("#");
2103
- g_string_append(pound_label,label);
2104
- update_links(pound_label->str,"tab",scratch);
2105
- g_string_free(pound_label,TRUE);
2106
- free(label);
2107
-
2108
- }
2109
- break;
2110
- case IMAGE:
2111
- case IMAGEBLOCK:
2112
- if ((list->link_data != NULL) && (list->link_data->label != NULL)) {
2113
- label = label_from_string(list->link_data->label);
2114
- pound_label = g_string_new("#");
2115
- g_string_append(pound_label,label);
2116
- update_link_source(pound_label->str,"fig",root);
2117
- g_string_free(pound_label,TRUE);
2118
- free(label);
2119
- }
2120
- break;
2121
- case HEADINGSECTION:
2122
- add_prefixes(list->children, root, scratch);
2123
- break;
2124
- default:
2125
- break;
2126
- }
2127
- list = list->next;
2128
- }
2129
- }
2130
- void update_links(char *source,char *prefix, scratch_pad *scratch) {
2131
- node* n = scratch->links;
2132
- link_data *l;
2133
- char* new_source;
2134
- while (n != NULL) {
2135
- l = n->link_data;
2136
- if ((l != NULL) && (l->source != NULL)) {
2137
- if (strcmp (l->source,source) == 0){
2138
- new_source = prefix_label(prefix,l->source,TRUE);
2139
- free(l->source);
2140
- l->source = strdup(new_source);
2141
- free(new_source);
2142
- }
2143
- }
2144
- n = n->next;
2145
- }
2146
- }
2147
-
2148
- /* update_link_source - walk the tree and add prefixes */
2149
- void update_link_source(char *source, char *prefix,node *n){
2150
- link_data *l;
2151
- char* new_source;
2152
- while(n != NULL){
2153
- if (n->key == LINK){
2154
- l = n->link_data;
2155
- if ((l != NULL) && (l->source != NULL)) {
2156
- if (strcmp (l->source,source) == 0){
2157
- new_source = prefix_label(prefix,l->source,TRUE);
2158
- free(l->source);
2159
- l->source = strdup(new_source);
2160
- free(new_source);
2161
- }
2162
- }
2163
- }
2164
- if(n->children != NULL) {
2165
- update_link_source(source,prefix,n->children);
2166
- }
2167
- n = n-> next;
2168
- }
2169
-
2170
- }
2171
-
2172
- /* prefix_label - Builds a label with a prefix - Returns a null-terminated string,
2173
- which must be freed after use. */
2174
- char *prefix_label(char *prefix, char *label, bool pound) {
2175
- char* function_result;
2176
- char short_prefix[6];
2177
- int i;
2178
- strncpy(short_prefix,prefix,5);
2179
- short_prefix[5]= '\0'; /* no terminator if strncpy ends because of length */
2180
- for(i = 0; short_prefix[i]; i++){
2181
- short_prefix[i] = tolower(short_prefix[i]);
2182
- }
2183
- GString *result = g_string_new("");
2184
- if (label[0]== '#'){
2185
- g_string_append(result,label+1); /* drop the pound */
2186
- } else{
2187
- g_string_append(result,label);
2188
- }
2189
- g_string_prepend(result,":"); /* prefix colon */
2190
- g_string_prepend(result,short_prefix); /* add the prefix */
2191
- if (pound){
2192
- g_string_prepend(result,"#"); /* add back in the pound if needed */
2193
- }
2194
- function_result = result->str;
2195
- g_string_free(result,FALSE); /* sending back the string */
2196
- return function_result;
2197
- }
2198
-
2199
- /* print_escaped_node_tree - print a list of elements as original text */
2200
- void print_escaped_node_tree(GString *out, node *n) {
2201
- #ifdef DEBUG_ON
2202
- if (n != NULL)
2203
- fprintf(stderr, "start print_escaped_node_tree: '%d'\n",n->key);
2204
- #endif
2205
- while (n != NULL) {
2206
- print_escaped_node(out, n);
2207
- n = n->next;
2208
- }
2209
- #ifdef DEBUG_ON
2210
- if (n != NULL)
2211
- fprintf(stderr, "finish print_escaped_node_tree: '%d'\n",n->key);
2212
- #endif
2213
- }
2214
-
2215
- /* print_escaped_node - print an element as original text with LyX escaping*/
2216
- void print_escaped_node(GString *out, node *n) {
2217
- switch (n->key) {
2218
- case STR:
2219
- g_string_append(out,n->str);
2220
- break;
2221
- case SPACE:
2222
- g_string_append(out," ");
2223
- break;
2224
- case APOSTROPHE:
2225
- g_string_append(out,"'");
2226
- break;
2227
- case SINGLEQUOTED:
2228
- g_string_append(out,"'");
2229
- print_escaped_node_tree(out,n->children);
2230
- g_string_append(out,"'");
2231
- return;
2232
- case DOUBLEQUOTED:
2233
- g_string_append(out,"\"");
2234
- print_escaped_node_tree(out,n->children);
2235
- g_string_append(out,"\"");
2236
- return;
2237
- case ELLIPSIS:
2238
- g_string_append(out,"...");
2239
- break;
2240
- case ENDASH:
2241
- g_string_append(out,"--");
2242
- break;
2243
- case EMDASH:
2244
- g_string_append(out,"---");
2245
- default:
2246
- break;
2247
- }
2248
- print_escaped_node_tree(out, n->children);
2249
- }
2250
- /* escape string - replace double quotes with escaped version */
2251
- char * escape_string(char *str) {
2252
- GString *out = g_string_new("");
2253
- char *clean;
2254
- while (*str != '\0') {
2255
- if (*str == '"') {
2256
- g_string_append(out, "\\\"");
2257
- } else {
2258
- g_string_append_c(out, *str);
2259
- }
2260
- str++;
2261
- }
2262
- clean = out->str;
2263
- g_string_free(out, false);
2264
- return clean;
2265
- }