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,188 +0,0 @@
1
- /* ensure we only load this once */
2
-
3
- #ifndef PARSER_LIB_H
4
- #define PARSER_LIB_H
5
-
6
- #include <stdio.h>
7
- #include <string.h>
8
- #include <stdlib.h>
9
- #include <stdbool.h>
10
- #include <assert.h>
11
- #include <time.h>
12
- #include "glib.h"
13
- #include "libMultiMarkdown.h"
14
-
15
- #define TABSTOP 4
16
-
17
- #define MMD_VERSION "4.7.1"
18
-
19
- #define MMD_COPYRIGHT \
20
- "Copyright (c) 2013-2015 Fletcher T. Penney.\n\n" \
21
- "LyX export code (c) 2013-2014 Charles R. Cowan,\n" \
22
- "licensed under both GPL and MIT licenses.\n\n" \
23
- "portions based on peg-markdown - Copyright (c) 2008-2009 John MacFarlane.\n" \
24
- "peg-markdown is Licensed under either the GPLv2+ or MIT.\n" \
25
- "portions Copyright (c) 2011 Daniel Jalkut, MIT licensed.\n\n" \
26
- "This is free software: you are free to change and redistribute it.\n" \
27
- "There is NO WARRANTY, to the extent permitted by law.\n\n"
28
-
29
-
30
- #define DEBUG_OFF /* Turn on debugging statements (there's a bunch!)*/
31
-
32
-
33
- /* This is the type used for the $$ pseudovariable passed to parents */
34
- #define YYSTYPE node *
35
-
36
- /* This is the data we store in the parser context */
37
- typedef struct {
38
- const char *charbuf; /* Input buffer */
39
- const char *original; /* Original input buffer */
40
- node *result; /* Resulting parse tree */
41
- unsigned long extensions; /* Extension bitfield */
42
- node *autolabels; /* Store for later retrieval */
43
- bool parse_aborted; /* We got bogged down - fail parse */
44
- clock_t stop_time; /* Note the deadline to complete parsing */
45
- } parser_data;
46
-
47
- /* A "scratch pad" for storing data when writing output
48
- The structure will vary based on what you need */
49
- typedef struct {
50
- unsigned long extensions; /* Store copy of extensions for retrieval */
51
- int padded; /* Track newlines */
52
- int baseheaderlevel; /* Increase header levels when outputting */
53
- int language; /* For smart quotes */
54
- char *table_alignment; /* Hold the alignment string while parsing table */
55
- int table_column; /* Track the current column number */
56
- char cell_type; /* What sort of cell type are we in? */
57
- bool printing_notes; /* Are we printing notes/glossary/etc.? */
58
- node *notes; /* Store reference notes */
59
- node *links; /* ... links */
60
- node *glossary; /* ... glossary */
61
- node *citations; /* ... citations */
62
- node *abbreviations; /* ... abbreviations */
63
- node *used_notes; /* notes that have been referenced */
64
- node *result_tree; /* reference to entire result tree */
65
- int footnote_to_print; /* set while we are printing so we can reverse link */
66
- int footnote_para_counter; /* so we know which para is last */
67
- int max_footnote_num; /* so we know if current note is new or repeat */
68
- bool obfuscate; /* flag that we need to mask email addresses */
69
- char *latex_footer; /* store for appending at the end */
70
- bool no_latex_footnote; /* can't use footnotes in some places */
71
- int odf_para_type; /* what type of paragraph do we need? */
72
- bool odf_list_needs_end_p; /* is there a <p> that need to be closed */
73
- int random_seed_base; /* Allow random footnotes */
74
- int toc_level; /* Track depth for TOC */
75
- int table_row; /* CRC - Track the current row number */
76
- int lyx_para_type; /* CRC - the type of paragraph being processed */
77
- int lyx_level; /* CRC - nesting level */
78
- bool no_lyx_footnote; /* CRC - Can't use footnotes in some places */
79
- bool lyx_number_headers; /* CRC - Whether to number headers (with or without *) */
80
- bool lyx_definition_hit; /* CRC - True when a definition has been encountered */
81
- bool lyx_definition_open; /* CRC - Have not completed a definition list entry */
82
- bool lyx_in_header; /* CRC - In a table header */
83
- bool lyx_in_frame; /* CRC - in a beamer frame */
84
- bool lyx_beamerbullet; /* CRC - beamer bullet list (add <+->) */
85
- int lyx_debug_nest; /* CRC - nesting level for enhanced debugging */
86
- bool lyx_table_need_line; /* CRC - need a line at the top */
87
- int lyx_table_total_rows; /* CRC - The total number of rows in the table */
88
- int lyx_table_total_cols; /* CRC - The total number of columns in the table */
89
- node *lyx_table_caption; /* CRC - Hold the table caption */
90
- GString *lyx_debug_pad; /* CRC - padding to indent debugging informaiton */
91
- } scratch_pad;
92
-
93
- /* Define smart typography languages -- first in list is default */
94
- enum language {
95
- ENGLISH,
96
- DUTCH,
97
- FRENCH,
98
- GERMAN,
99
- GERMANGUILL,
100
- SWEDISH,
101
- };
102
-
103
- /* Character types for smart typography */
104
- enum smartelements {
105
- LSQUOTE,
106
- RSQUOTE,
107
- LDQUOTE,
108
- RDQUOTE,
109
- NDASH,
110
- MDASH,
111
- ELLIP,
112
- APOS,
113
- };
114
-
115
-
116
-
117
- /* parser utilities declarations */
118
- node * mk_node(int key);
119
- node * mk_str(char *string);
120
- node * mk_list(int key, node *list);
121
- node * mk_link(node *text, char *label, char *source, char *title, node *attr);
122
- node * mk_pos_node(int key, char *string, unsigned int start, unsigned int stop);
123
- node * mk_pos_str(char *string, unsigned int start, unsigned int stop);
124
- node * mk_pos_list(int key, node *list, unsigned int start, unsigned int stop);
125
-
126
- void free_node(node *n);
127
- void free_node_tree(node * n);
128
- void print_node_tree(node * n);
129
- node * copy_node(node *n);
130
- node * copy_node_tree(node *n);
131
-
132
- node * cons(node *new, node *list);
133
- node * reverse_list(node *list);
134
- void append_list(node *new, node *list);
135
-
136
- node * mk_str_from_list(node *list, bool extra_newline);
137
- GString * concat_string_list(node *list);
138
-
139
- parser_data * mk_parser_data(const char *charbuf, unsigned long extensions);
140
- void free_parser_data(parser_data *data);
141
-
142
- char * preformat_text(const char *text);
143
-
144
- scratch_pad * mk_scratch_pad(unsigned long extensions);
145
- void free_scratch_pad(scratch_pad *scratch);
146
-
147
- link_data * mk_link_data(char *label, char *source, char *title, node *attr);
148
- void free_link_data(link_data *l);
149
- link_data * extract_link_data(char *label, scratch_pad *scratch);
150
- node * mk_autolink(char *text);
151
-
152
- void extract_references(node *list, scratch_pad *scratch);
153
- void extract_abbreviations(node *list, scratch_pad *scratch);
154
-
155
- bool extension(int ext, unsigned long extensions);
156
-
157
- /* export utilities */
158
- void trim_trailing_whitespace(char *str);
159
- void trim_trailing_newlines(char *str);
160
-
161
- /* other utilities */
162
- char * label_from_string(char *str);
163
- char * ascii_label_from_string(char *str);
164
- char * clean_string(char *str);
165
- char * string_from_node_tree(node *n);
166
- char * label_from_node_tree(node *n);
167
- char * label_from_node(node *n);
168
- char * ascii_label_from_node_tree(node *n);
169
- char * ascii_label_from_node(node *n);
170
- void print_raw_node(GString *out, node *n);
171
- void print_raw_node_tree(GString *out, node*n);
172
-
173
- char * correct_dimension_units(char *original);
174
- char * metadata_keys(node *list);
175
- node * metadata_for_key(char *key, node *list);
176
- char * metavalue_for_key(char *key, node *list);
177
-
178
- bool tree_contains_key(node *list, int key);
179
- int tree_contains_key_count(node *list, int key);
180
-
181
- bool check_timeout();
182
-
183
- void debug_node(node *n);
184
- void debug_node_tree(node *n);
185
-
186
- char * my_strndup(const char * source, size_t n);
187
-
188
- #endif
@@ -1,665 +0,0 @@
1
- /*
2
-
3
- rtf.c -- RTF writer
4
-
5
- (c) 2013 Fletcher T. Penney (http://fletcherpenney.net/).
6
-
7
- This program is free software; you can redistribute it and/or modify
8
- it under the terms of the GNU General Public License or the MIT
9
- license. See LICENSE for details.
10
-
11
- This program is distributed in the hope that it will be useful,
12
- but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- GNU General Public License for more details.
15
-
16
- */
17
-
18
- #include "rtf.h"
19
-
20
-
21
- /* Since RTF sucks, we simplify here */
22
-
23
- #define kNormalStyle "\\s0 \\qj\\sa180\\f0\\fs24 "
24
- #define kH1 "\\s1 \\f1\\fs32\\ql\\sb240\\sa180\\b "
25
- #define kH2 "\\s2 \\f1\\fs28\\ql\\sb240\\sa180\\i\\b "
26
- #define kH3 "\\s3 \\f1\\fs28\\ql\\sb240\\sa180\\b "
27
- #define kH4 "\\s4 \\f1\\fs24\\ql\\sb240\\sa180\\i\\b "
28
- #define kH5 "\\s5 \\f1\\fs24\\ql\\sb240\\sa180\\b "
29
- #define kH6 "\\s6 \\f1\\fs22\\ql\\sb240\\sa180\\b "
30
- #define kQuoteStyle "\\s7 \\qj\\sa180\\f0\\fs24\\li720\\ri720 "
31
- #define kNoteStyle "\\s7 \\qj\\sa180\\f0\\fs24\\li360\\ri360 "
32
- #define kCodeStyle "\\s7 \\qj\\sa180\\f2\\fs20\\li360\\ri360 "
33
-
34
- /* print_rtf_node_tree -- convert node tree to RTF */
35
- void print_rtf_node_tree(GString *out, node *list, scratch_pad *scratch) {
36
- while (list != NULL) {
37
- print_rtf_node(out, list, scratch);
38
- list = list->next;
39
- }
40
- }
41
-
42
- /* print_rtf_node -- convert given node to RTF and append */
43
- void print_rtf_node(GString *out, node *n, scratch_pad *scratch) {
44
- int i;
45
- int lev;
46
- int old_type;
47
- char *temp;
48
- link_data *temp_link_data;
49
- node *temp_node;
50
-
51
- switch (n->key) {
52
- case SPACE:
53
- case STR:
54
- /* TODO: Some of the following need improvements */
55
- case MATHSPAN:
56
- print_rtf_string(out, n->str, scratch);
57
- break;
58
- case METADATA:
59
- if (scratch->extensions & EXT_SNIPPET)
60
- break;
61
- g_string_append_printf(out, "{\\info\n");
62
- print_rtf_node_tree(out,n->children,scratch);
63
- g_string_append_printf(out, "}\n");
64
- scratch->padded = 0;
65
- break;
66
- case METAKEY:
67
- /* Convert key */
68
- temp = label_from_string(n->str);
69
- free(n->str);
70
- n->str = temp;
71
- if (strcmp(n->str, "baseheaderlevel") == 0) {
72
- scratch->baseheaderlevel = atoi(n->children->str);
73
- break;
74
- } else if (strcmp(n->str, "rtfheaderlevel") == 0) {
75
- scratch->baseheaderlevel = atoi(n->children->str);
76
- break;
77
- } else if (strcmp(n->str, "quoteslanguage") == 0) {
78
- temp = label_from_node_tree(n->children);
79
- if ((strcmp(temp, "nl") == 0) || (strcmp(temp, "dutch") == 0)) { scratch->language = DUTCH; } else
80
- if ((strcmp(temp, "de") == 0) || (strcmp(temp, "german") == 0)) { scratch->language = GERMAN; } else
81
- if (strcmp(temp, "germanguillemets") == 0) { scratch->language = GERMANGUILL; } else
82
- if ((strcmp(temp, "fr") == 0) || (strcmp(temp, "french") == 0)) { scratch->language = FRENCH; } else
83
- if ((strcmp(temp, "sv") == 0) || (strcmp(temp, "swedish") == 0)) { scratch->language = SWEDISH; }
84
- free(temp);
85
- break;
86
- }
87
-
88
- if (strcmp(n->str, "title") == 0) {
89
- g_string_append_printf(out, "{\\title ");
90
- print_rtf_node(out, n->children, scratch);
91
- g_string_append_printf(out, "}\n");
92
- } else if (strcmp(n->str, "author") == 0) {
93
- g_string_append_printf(out, "{\\author ");
94
- print_rtf_node(out, n->children, scratch);
95
- g_string_append_printf(out, "}\n");
96
- } else if (strcmp(n->str, "affiliation") == 0) {
97
- g_string_append_printf(out, "{\\company ");
98
- print_rtf_node(out, n->children, scratch);
99
- g_string_append_printf(out, "}\n");
100
- } else if (strcmp(n->str, "company") == 0) {
101
- g_string_append_printf(out, "{\\company ");
102
- print_rtf_node(out, n->children, scratch);
103
- g_string_append_printf(out, "}\n");
104
- } else if (strcmp(n->str, "keywords") == 0) {
105
- g_string_append_printf(out, "{\\keywords ");
106
- print_rtf_node(out, n->children, scratch);
107
- g_string_append_printf(out, "}\n");
108
- } else if (strcmp(n->str, "copyright") == 0) {
109
- g_string_append_printf(out, "{\\*\\copyright ");
110
- print_rtf_node(out, n->children, scratch);
111
- g_string_append_printf(out, "}\n");
112
- } else if (strcmp(n->str, "comment") == 0) {
113
- g_string_append_printf(out, "{\\doccomm ");
114
- print_rtf_node(out, n->children, scratch);
115
- g_string_append_printf(out, "}\n");
116
- } else if (strcmp(n->str, "subject") == 0) {
117
- g_string_append_printf(out, "{\\subject ");
118
- print_rtf_node(out, n->children, scratch);
119
- g_string_append_printf(out, "}\n");
120
- }
121
- break;
122
- case METAVALUE:
123
- trim_trailing_whitespace(n->str);
124
- print_rtf_string(out, n->str, scratch);
125
- break;
126
- case BLOCKQUOTEMARKER:
127
- print_rtf_node_tree(out, n->children, scratch);
128
- break;
129
- case BLOCKQUOTE:
130
- old_type = scratch->odf_para_type;
131
- scratch->odf_para_type = BLOCKQUOTE;
132
- pad_rtf(out, 2, scratch);
133
- print_rtf_node_tree(out,n->children,scratch);
134
- scratch->padded = 1;
135
- scratch->odf_para_type = old_type;
136
- break;
137
- case VERBATIM:
138
- case VERBATIMFENCE:
139
- pad_rtf(out, 2, scratch);
140
- g_string_append_printf(out, "{\\pard " kCodeStyle);
141
- print_rtf_code_string(out,n->str,scratch);
142
- g_string_append_printf(out, "\n\\par}\n");
143
- scratch->padded = 0;
144
- break;
145
- case CODE:
146
- print_rtf_node_tree(out,n->children,scratch);
147
- // print_rtf_string(out, n->str, scratch);
148
- break;
149
- case PARA:
150
- pad_rtf(out, 2, scratch);
151
- switch (scratch->odf_para_type) {
152
- case BLOCKQUOTE:
153
- g_string_append_printf(out, "{\\pard " kQuoteStyle);
154
- break;
155
- case NOTEREFERENCE:
156
- case CITATION:
157
- g_string_append_printf(out, "{\\pard " kNoteStyle);
158
- break;
159
- case CODE:
160
- case VERBATIM:
161
- case VERBATIMFENCE:
162
- g_string_append_printf(out, "{\\pard " kCodeStyle);
163
- break;
164
- default:
165
- g_string_append_printf(out, "{\\pard " kNormalStyle);
166
- break;
167
- }
168
- print_rtf_node_tree(out,n->children,scratch);
169
- g_string_append_printf(out, "\n\\par}\n");
170
- scratch->padded = 1;
171
- break;
172
- case H1: case H2: case H3: case H4: case H5: case H6:
173
- lev = n->key - H1 + scratch->baseheaderlevel;
174
- if (lev > 6)
175
- lev = 6;
176
- pad_rtf(out, 2, scratch);
177
- switch (lev) {
178
- case 1:
179
- g_string_append_printf(out, "{\\pard " kH1);
180
- break;
181
- case 2:
182
- g_string_append_printf(out, "{\\pard " kH2);
183
- break;
184
- case 3:
185
- g_string_append_printf(out, "{\\pard " kH3);
186
- break;
187
- case 4:
188
- g_string_append_printf(out, "{\\pard " kH4);
189
- break;
190
- case 5:
191
- g_string_append_printf(out, "{\\pard " kH5);
192
- break;
193
- case 6:
194
- g_string_append_printf(out, "{\\pard " kH6);
195
- break;
196
- }
197
- if (n->children->key == AUTOLABEL) {
198
- temp = label_from_string(n->children->str);
199
- g_string_append_printf(out, "{\\*\\bkmkstart %s}{\\*\\bkmkend %s}",temp, temp);
200
- print_rtf_node_tree(out, n->children->next, scratch);
201
- } else {
202
- temp = label_from_node_tree(n->children);
203
- g_string_append_printf(out, "{\\*\\bkmkstart %s}{\\*\\bkmkend %s}",temp,temp);
204
- print_rtf_node_tree(out, n->children, scratch);
205
- }
206
- free(temp);
207
- g_string_append_printf(out, "\\par}\n");
208
- scratch->padded = 1;
209
- break;
210
- case TABLE:
211
- if ((n->children != NULL) && (n->children->key == TABLECAPTION)) {
212
- if (n->children->children->key == TABLELABEL) {
213
- temp = label_from_string(n->children->children->str);
214
- } else {
215
- temp = label_from_node_tree(n->children->children);
216
- }
217
- g_string_append_printf(out, "{\\*\\bkmkstart %s}{\\*\\bkmkend %s}",temp,temp);
218
- free(temp);
219
- }
220
- pad_rtf(out, 2, scratch);
221
- print_rtf_node_tree(out, n->children, scratch);
222
- if ((n->children != NULL) && (n->children->key == TABLECAPTION)) {
223
- g_string_append_printf(out, "{\\pard " kNormalStyle "\\qc ");
224
- print_rtf_node_tree(out, n->children->children, scratch);
225
- g_string_append_printf(out, "\\par}\n");
226
- }
227
- g_string_append_printf(out, "\\pard\\par\n");
228
- scratch->padded = 1;
229
- break;
230
- case TABLELABEL:
231
- case TABLECAPTION:
232
- break;
233
- case TABLESEPARATOR:
234
- scratch->table_alignment = n->str;
235
- break;
236
- case TABLEHEAD:
237
- scratch->cell_type = 'h';
238
- print_rtf_node_tree(out, n->children, scratch);
239
- scratch->cell_type = 'd';
240
- break;
241
- case TABLEROW:
242
- scratch->table_column = 0;
243
- g_string_append_printf(out, "\\trowd\\trautofit1\n");
244
- for (i=0; i < strlen(scratch->table_alignment); i++) {
245
- g_string_append_printf(out, "\\cellx%d\n",i+1);
246
- }
247
- print_rtf_node_tree(out, n->children, scratch);
248
- g_string_append_printf(out, "\\row\n");
249
- break;
250
- case TABLECELL:
251
- temp = scratch->table_alignment;
252
- if (strncmp(&temp[scratch->table_column],"h",1) == 0) {
253
- scratch->table_column++;
254
- }
255
- lev = scratch->table_column;
256
-
257
- g_string_append_printf(out, "\\intbl");
258
-
259
- if (scratch->cell_type == 'h') {
260
- g_string_append_printf(out, "\\qc{\\b ");
261
- } else {
262
- if ( strncmp(&temp[lev],"r",1) == 0) {
263
- g_string_append_printf(out, "\\qr");
264
- } else if ( strncmp(&temp[lev],"R",1) == 0) {
265
- g_string_append_printf(out, "\\qr");
266
- } else if ( strncmp(&temp[lev],"c",1) == 0) {
267
- g_string_append_printf(out, "\\qc");
268
- } else if ( strncmp(&temp[lev],"C",1) == 0) {
269
- g_string_append_printf(out, "\\qc");
270
- } else {
271
- g_string_append_printf(out, "\\ql");
272
- }
273
- }
274
- g_string_append_printf(out, " {");
275
- print_rtf_node_tree(out, n->children, scratch);
276
-
277
- if (scratch->cell_type == 'h')
278
- g_string_append_printf(out, "}");
279
-
280
- g_string_append_printf(out, "}\\cell\n");
281
- scratch->table_column++;
282
- break;
283
- case STRONG:
284
- g_string_append_printf(out, "{\\b ");
285
- print_rtf_node_tree(out,n->children,scratch);
286
- g_string_append_printf(out, "}");
287
- break;
288
- case EMPH:
289
- g_string_append_printf(out, "{\\i ");
290
- print_rtf_node_tree(out,n->children,scratch);
291
- g_string_append_printf(out, "}");
292
- break;
293
- case LINEBREAK:
294
- g_string_append_printf(out, "\\line ");
295
- break;
296
- case LINK:
297
- temp_link_data = load_link_data(n, scratch);
298
-
299
- if (temp_link_data == NULL) {
300
- /* replace original text since no definition found */
301
- g_string_append_printf(out, "[");
302
- print_rtf_node(out, n->children, scratch);
303
- g_string_append_printf(out,"]");
304
- if (n->children->next != NULL) {
305
- g_string_append_printf(out, "[");
306
- print_rtf_node_tree(out, n->children->next, scratch);
307
- g_string_append_printf(out,"]");
308
- } else if (n->str != NULL) {
309
- /* no title label, so see if we stashed str*/
310
- g_string_append_printf(out, "%s", n->str);
311
- } else {
312
- g_string_append_printf(out, "[%s]",n->link_data->label);
313
- }
314
-
315
- free_link_data(temp_link_data);
316
- break;
317
- }
318
-
319
- /* Insert link */
320
- g_string_append_printf(out, "{\\field{\\*\\fldinst{HYPERLINK \"");
321
- print_rtf_string(out, temp_link_data->source, scratch);
322
- g_string_append_printf(out, "\"}}{\\fldrslt ");
323
- if (n->children != NULL)
324
- print_rtf_node_tree(out, n->children, scratch);
325
- g_string_append_printf(out, "}}");
326
-
327
- free(temp_link_data);
328
- break;
329
- case BULLETLIST:
330
- pad(out, 2, scratch);
331
- g_string_append_printf(out, "\\ls1\\ilvl0 ");
332
- scratch->padded = 0;
333
- print_rtf_node_tree(out, n->children, scratch);
334
- break;
335
- case ORDEREDLIST:
336
- pad(out, 2, scratch);
337
- scratch->padded = 0;
338
- print_rtf_node_tree(out, n->children, scratch);
339
- break;
340
- case LISTITEM:
341
- g_string_append_printf(out, "{\\listtext \\'95 }");
342
- print_rtf_node_tree(out, n->children, scratch);
343
- break;
344
- case NOTEREFERENCE:
345
- lev = note_number_for_node(n, scratch);
346
- temp_node = node_for_count(scratch->used_notes, lev);
347
- scratch->padded = 2;
348
-
349
- g_string_append_printf(out, "{\\super\\chftn}{\\footnote\\pard\\plain\\chtfn ");
350
- print_rtf_node_tree(out, temp_node->children, scratch);
351
- g_string_append_printf(out, "}");
352
- scratch->padded = 0;
353
- break;
354
- case GLOSSARYTERM:
355
- print_rtf_string(out, n->children->str, scratch);
356
- g_string_append_printf(out, ": ");
357
- break;
358
- case GLOSSARYSORTKEY:
359
- break;
360
- case NOCITATION:
361
- case CITATION:
362
- if ((n->link_data != NULL) && (strncmp(n->link_data->label,"[#",2) == 0)) {
363
- /* external citation */
364
- g_string_append_printf(out, "%s", n->link_data->label);
365
- } else {
366
- /* MMD citation, so output as endnote */
367
- scratch->printing_notes = 1;
368
- lev = 0;
369
- if (n->link_data != NULL)
370
- lev = note_number_for_label(n->link_data->label, scratch);
371
- if (lev != 0) {
372
- temp_node = node_for_count(scratch->used_notes, lev);
373
-
374
- /* flag that this is used as a citation */
375
- temp_node->key = CITATIONSOURCE;
376
- if (lev > scratch->max_footnote_num) {
377
- /* first use of this citation */
378
- scratch->max_footnote_num = lev;
379
-
380
- old_type = scratch->odf_para_type;
381
- scratch->odf_para_type = CITATION;
382
-
383
- /* change to represent cite count only */
384
- // lev = cite_count_node_from_end(temp_node);
385
- g_string_append_printf(out, "{\\super\\chftn}{\\footnote\\ftnalt\\pard\\plain\\chtfn ");
386
- scratch->padded = 2;
387
- if (temp_node->children != NULL) {
388
- print_rtf_node(out, temp_node->children, scratch);
389
- }
390
- pad(out, 1, scratch);
391
- g_string_append_printf(out, "}");
392
- scratch->odf_para_type = old_type;
393
- } else {
394
- /* We are reusing a previous citation */
395
-
396
- /* Change lev to represent cite count only */
397
- // lev = cite_count_node_from_end(temp_node);
398
-
399
- g_string_append_printf(out, "REUSE CITATION");
400
- }
401
- } else {
402
- /* not located -- this is external cite */
403
-
404
- if ((n->link_data != NULL) && (n->key == NOCITATION)) {
405
- g_string_append_printf(out, "%s", n->link_data->label);
406
- } else if (n->link_data != NULL) {
407
- g_string_append_printf(out, "[");
408
- if (n->children != NULL) {
409
- print_rtf_node(out, n->children, scratch);
410
- g_string_append_printf(out, "][");
411
- }
412
- g_string_append_printf(out, "#%s]",n->link_data->label);
413
- }
414
- }
415
- }
416
- scratch->printing_notes = 0;
417
- if ((n->next != NULL) && (n->next->key == CITATION)) {
418
- g_string_append_printf(out, " ");
419
- }
420
- break;
421
- case APOSTROPHE:
422
- print_rtf_localized_typography(out, APOS, scratch);
423
- break;
424
- case ELLIPSIS:
425
- print_rtf_localized_typography(out, ELLIP, scratch);
426
- break;
427
- case EMDASH:
428
- print_rtf_localized_typography(out, MDASH, scratch);
429
- break;
430
- case ENDASH:
431
- print_rtf_localized_typography(out, NDASH, scratch);
432
- break;
433
- case SINGLEQUOTED:
434
- print_rtf_localized_typography(out, LSQUOTE, scratch);
435
- print_rtf_node_tree(out, n->children, scratch);
436
- print_rtf_localized_typography(out, RSQUOTE, scratch);
437
- break;
438
- case DOUBLEQUOTED:
439
- print_rtf_localized_typography(out, LDQUOTE, scratch);
440
- print_rtf_node_tree(out, n->children, scratch);
441
- print_rtf_localized_typography(out, RDQUOTE, scratch);
442
- break;
443
- case LIST:
444
- case HEADINGSECTION:
445
- print_rtf_node_tree(out,n->children,scratch);
446
- break;
447
- /* TODO: Some of the following need improvements */
448
- case TABLEBODY:
449
- case PLAIN:
450
- print_rtf_node_tree(out,n->children,scratch);
451
- g_string_append_printf(out, "\\\n");
452
- break;
453
- case NOTELABEL:
454
- case GLOSSARYLABEL:
455
- case FOOTER:
456
- case LINKREFERENCE:
457
- break;
458
- case GLOSSARYSOURCE:
459
- case CITATIONSOURCE:
460
- case NOTESOURCE:
461
- if (scratch->printing_notes)
462
- print_html_node_tree(out, n->children, scratch);
463
- break;
464
- case IMAGEBLOCK:
465
- case IMAGE:
466
- g_string_append_printf(out, "IMAGES CANNOT BE INSERTED INTO AN RTF DOCUMENT FROM MULTIMARKDOWN \\\n");
467
- break;
468
- case VARIABLE:
469
- temp = metavalue_for_key(n->str,scratch->result_tree);
470
- if (temp == NULL) {
471
- g_string_append_printf(out, "[%%%s]",n->str);
472
- } else {
473
- g_string_append_printf(out, temp);
474
- free(temp);
475
- }
476
- break;
477
- case HTMLBLOCK:
478
- /* don't print HTML block */
479
- /* but do print HTML comments for raw RTF */
480
- if (strncmp(n->str,"<!--",4) == 0) {
481
- pad(out, 2, scratch);
482
- /* trim "-->" from end */
483
- n->str[strlen(n->str)-3] = '\0';
484
- g_string_append_printf(out, "%s", &n->str[4]);
485
- scratch->padded = 0;
486
- }
487
- break;
488
- case TOC:
489
- print_rtf_node_tree(out,n->children, scratch);
490
- break;
491
- default:
492
- fprintf(stderr, "print_rtf_node encountered unknown node key = %d\n",n->key);
493
- g_string_append_printf(out, "%s",n->str);
494
- /* Will use in place of real output during development */
495
- /* exit(EXIT_FAILURE); */
496
- break;
497
- }
498
- }
499
-
500
- void begin_rtf_output(GString *out, node* list, scratch_pad *scratch) {
501
- g_string_append_printf(out, "{\\rtf1\\ansi\\deff0 {\\fonttbl\n" \
502
- "{\\f0\\froman Times New Roman;}\n" \
503
- "{\\f1\\fswiss Arial;}\n" \
504
- "{\\f2\\fmodern Courier New;}\n" \
505
- "}\n" \
506
- "{\\stylesheet\n" \
507
- "{" kNormalStyle "Normal;}\n" \
508
- "{" kH1 "Header 1;}\n" \
509
- "{" kH2 "Header 2;}\n" \
510
- "{" kH3 "Header 3;}\n" \
511
- "{" kH4 "Header 4;}\n" \
512
- "{" kH5 "Header 5;}\n" \
513
- "{" kH6 "Header 6;}\n" \
514
- "{" kQuoteStyle "Quotation;}\n" \
515
- "{" kNoteStyle "Note;}\n" \
516
- "}\n" \
517
- "\\margt1150\\margb1150\\margl1150\\margr1150\n");
518
- }
519
-
520
- void end_rtf_output(GString *out, node* list, scratch_pad *scratch) {
521
- g_string_append_printf(out, "}\n");}
522
-
523
- /* print_rtf_localized_typography -- convert to "smart" typography */
524
- void print_rtf_localized_typography(GString *out, int character, scratch_pad *scratch) {
525
- if (!extension(EXT_SMART, scratch->extensions)) {
526
- g_string_append_c(out, character);
527
- return;
528
- }
529
- switch (character) {
530
- case LSQUOTE:
531
- switch (scratch->language) {
532
- case SWEDISH:
533
- g_string_append_printf(out, "&#8217;");
534
- break;
535
- case FRENCH:
536
- g_string_append_printf(out,"&#39;");
537
- break;
538
- case GERMAN:
539
- g_string_append_printf(out,"&#8218;");
540
- break;
541
- case GERMANGUILL:
542
- g_string_append_printf(out,"&#8250;");
543
- break;
544
- default:
545
- g_string_append_printf(out,"\\'91");
546
- }
547
- break;
548
- case RSQUOTE:
549
- switch (scratch->language) {
550
- case GERMAN:
551
- g_string_append_printf(out,"&#8216;");
552
- break;
553
- case GERMANGUILL:
554
- g_string_append_printf(out,"&#8249;");
555
- break;
556
- default:
557
- g_string_append_printf(out,"\\'92");
558
- }
559
- break;
560
- case APOS:
561
- g_string_append_printf(out,"\\'27");
562
- break;
563
- case LDQUOTE:
564
- switch (scratch->language) {
565
- case DUTCH:
566
- case GERMAN:
567
- g_string_append_printf(out,"&#8222;");
568
- break;
569
- case GERMANGUILL:
570
- g_string_append_printf(out,"&#187;");
571
- break;
572
- case FRENCH:
573
- g_string_append_printf(out,"&#171;");
574
- break;
575
- case SWEDISH:
576
- g_string_append_printf(out, "&#8221;");
577
- break;
578
- default:
579
- g_string_append_printf(out,"\\'93");
580
- }
581
- break;
582
- case RDQUOTE:
583
- switch (scratch->language) {
584
- case SWEDISH:
585
- case DUTCH:
586
- g_string_append_printf(out,"&#8221;");
587
- break;
588
- case GERMAN:
589
- g_string_append_printf(out,"&#8220;");
590
- break;
591
- case GERMANGUILL:
592
- g_string_append_printf(out,"&#171;");
593
- break;
594
- case FRENCH:
595
- g_string_append_printf(out,"&#187;");
596
- break;
597
- default:
598
- g_string_append_printf(out,"\\'94");
599
- }
600
- break;
601
- case NDASH:
602
- g_string_append_printf(out,"\\'96");
603
- break;
604
- case MDASH:
605
- g_string_append_printf(out,"\\'97");
606
- break;
607
- case ELLIP:
608
- g_string_append_printf(out,"\\'85");
609
- break;
610
- default:;
611
- }
612
- }
613
-
614
- void print_rtf_string(GString *out, char *str, scratch_pad *scratch) {
615
- if (str == NULL)
616
- return;
617
- while (*str != '\0') {
618
- switch (*str) {
619
- case '\\':
620
- g_string_append_printf(out, "\\\\");
621
- break;
622
- case '{':
623
- g_string_append_printf(out, "\\{");
624
- break;
625
- case '}':
626
- g_string_append_printf(out, "\\}");
627
- break;
628
- case '\n':
629
- g_string_append_printf(out, " \n");
630
- default:
631
- g_string_append_c(out, *str);
632
- }
633
- str++;
634
- }
635
- }
636
-
637
- void print_rtf_code_string(GString *out, char *str, scratch_pad *scratch) {
638
- if (str == NULL)
639
- return;
640
- while (*str != '\0') {
641
- switch (*str) {
642
- case '\\':
643
- g_string_append_printf(out, "\\\\");
644
- break;
645
- case '{':
646
- g_string_append_printf(out, "\\{");
647
- break;
648
- case '}':
649
- g_string_append_printf(out, "\\}");
650
- break;
651
- case '\n':
652
- g_string_append_printf(out, "\\\n");
653
- break;
654
- default:
655
- g_string_append_c(out, *str);
656
- }
657
- str++;
658
- }
659
- }
660
- void pad_rtf(GString *out, int num, scratch_pad *scratch) {
661
- while (num-- > scratch->padded)
662
- g_string_append_printf(out, "\n");
663
-
664
- scratch->padded = num;
665
- }