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,37 +0,0 @@
1
- #ifndef LYX_PARSER_H
2
- #define LYX_PARSER_H
3
-
4
- #include "parser.h"
5
- #include "writer.h"
6
-
7
- /* allow the user to change the heading levels */
8
-
9
- extern GString *heading_name[7];
10
-
11
- /* Lyx likes to wrap strings in "environments" */
12
- enum lyx_environment{
13
- LYX_NONE,
14
- LYX_STANDARD,
15
- LYX_CODE,
16
- LYX_PLAIN
17
- };
18
-
19
-
20
- void perform_lyx_output(GString *out, node* list, scratch_pad *scratch);
21
- bool begin_lyx_output(GString *out, node* list, scratch_pad *scratch);
22
- void print_lyx_node_tree(GString *out, node *list, scratch_pad *scratch, bool no_newline);
23
- void end_lyx_output(GString *out, node* list, scratch_pad *scratch);
24
- void print_lyx_node(GString *out, node *n, scratch_pad *scratch, bool no_newline);
25
- void print_lyx_localized_typography(GString *out, unsigned char character, scratch_pad *scratch);
26
- void print_lyx_string(GString *out,char *str, scratch_pad *scratch,short environment);
27
- void print_lyx_url(GString *out, char *str, scratch_pad *scratch);
28
- void print_lyx_endnotes(GString *out, scratch_pad *scratch);
29
- void lyx_get_table_dimensions(node* list, int *rows, int *cols, scratch_pad *scratch);
30
- void add_prefixes(node *list, node *root, scratch_pad *scratch);
31
- void update_links(char *label,char *prefix, scratch_pad *scratch);
32
- char *prefix_label(char *prefix, char *label, bool pound);
33
- void update_link_source(char *source, char *prefix,node *n);
34
- void print_escaped_node_tree(GString *out, node *n);
35
- void print_escaped_node(GString *out, node *n);
36
- char * escape_string(char *str);
37
- #endif
@@ -1,265 +0,0 @@
1
- /*
2
-
3
- lyxbeamer.c -- Beamer add-on to LyX writer
4
-
5
- (c) 2013 Charles R. Cowan
6
- (c) 2013 Fletcher T. Penney (http://fletcherpenney.net/).
7
-
8
- Derrived from MultiMarkdown by Fletcher T. Penney - added code to support the LYY format directly
9
-
10
- This program is free software; you can redistribute it and/or modify
11
- it under the terms of the GNU General Public License or the MIT
12
- license. See LICENSE for details.
13
-
14
- This program is distributed in the hope that it will be useful,
15
- but WITHOUT ANY WARRANTY; without even the implied warranty of
16
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
- GNU General Public License for more details.
18
-
19
- */
20
-
21
- #include "lyxbeamer.h"
22
- #include "lyx.h"
23
-
24
- bool need_fragile; // if the frame needs to be fragile
25
-
26
- /* print_beamer_node_tree -- convert node tree to LyX */
27
- void print_lyxbeamer_node_tree(GString *out, node *list, scratch_pad *scratch, bool no_newline) {
28
- while (list != NULL) {
29
- print_lyxbeamer_node(out, list, scratch, no_newline);
30
- list = list->next;
31
- }
32
- }
33
-
34
- /* print_beamer_node -- convert given node to LyX and append */
35
- void print_lyxbeamer_node(GString *out, node *n, scratch_pad *scratch, bool no_newline) {
36
- int lev;
37
- int i;
38
- char *temp;
39
- char *prefixed_label;
40
- node *temp_node;
41
- int old_type;
42
-
43
- /* If we are forcing a complete document, and METADATA isn't the first thing,
44
- we need to close <head> */
45
- if ((scratch->extensions & EXT_COMPLETE)
46
- && !(scratch->extensions & EXT_HEAD_CLOSED) &&
47
- !((n->key == FOOTER) || (n->key == METADATA))) {
48
- scratch->extensions = scratch->extensions | EXT_HEAD_CLOSED;
49
- }
50
- switch (n->key) {
51
- case FOOTER:
52
- if (scratch->lyx_in_frame){ // have an open frame
53
- g_string_append(out,"\n\\end_deeper");
54
- // g_string_append(out,"\n\\end_layout");
55
- g_string_append(out, "\n\\begin_layout Separator");
56
- g_string_append(out, "\n\\end_layout");
57
- }
58
- scratch->lyx_in_frame = FALSE;
59
- print_lyxbeamer_endnotes(out, scratch);
60
- break;
61
- case BULLETLIST:
62
- case ORDEREDLIST:
63
- scratch -> lyx_beamerbullet = TRUE;
64
- case DEFLIST:
65
- old_type = scratch->lyx_para_type;
66
- scratch->lyx_para_type = n->key;
67
- scratch->lyx_level++;
68
- if (scratch->lyx_level > 1){
69
- g_string_append(out,"\n\\begin_deeper\n");
70
- }
71
- print_lyxbeamer_node_tree(out, n->children, scratch, FALSE);
72
- scratch->lyx_level--;
73
- if (scratch->lyx_level > 0){
74
- g_string_append(out,"\n\\end_deeper\n");
75
- }
76
- scratch->lyx_para_type = old_type;
77
- if (scratch->lyx_definition_open){
78
- g_string_append(out,"\n\\end_deeper\n");
79
- scratch->lyx_definition_open = FALSE;
80
- }
81
- break;
82
- case LISTITEM:
83
- temp_node = n-> children; // should be a list node
84
- if (temp_node->key != LIST){
85
- fprintf(stderr,"\nUnanticipated List Item Format");
86
- exit(EXIT_FAILURE);
87
- } else {
88
- temp_node = temp_node-> children; // process the list
89
- i = 0;
90
- while (temp_node != NULL){
91
- i++;
92
- if (i == 2){
93
- g_string_append(out,"\n\\begin_deeper\n");
94
- old_type = scratch->lyx_para_type;
95
- scratch->lyx_para_type = PARA; // and make it a paragraph, not a list item
96
- }
97
- print_lyx_node(out, temp_node, scratch, no_newline);
98
- temp_node = temp_node->next;
99
-
100
- }
101
- if (i>1){
102
- scratch->lyx_para_type = old_type; // reset the paragraph type
103
- g_string_append(out,"\n\\end_deeper\n");
104
- }
105
- }
106
- break;
107
- case HEADINGSECTION:
108
- if (scratch->lyx_in_frame){ // have an open frame
109
- g_string_append(out,"\n\\end_deeper");
110
- // g_string_append(out,"\n\\end_layout");
111
- g_string_append(out, "\n\\begin_layout Separator");
112
- g_string_append(out, "\n\\end_layout");
113
- }
114
- scratch->lyx_in_frame = FALSE;
115
- need_fragile = FALSE;
116
- if (tree_contains_key(n->children,VERBATIM)) {
117
- need_fragile = TRUE;
118
- }
119
- print_lyxbeamer_node_tree(out,n->children,scratch , FALSE);
120
- break;
121
- case H1: case H2: case H3: case H4: case H5: case H6:
122
- lev = n->key - H1 + scratch->baseheaderlevel; /* assumes H1 ... H6 are in order */
123
- switch (lev) {
124
- case 1:
125
- g_string_append(out, "\n\\begin_layout Part\n");
126
- break;
127
- case 2:
128
- g_string_append(out, "\n\\begin_layout Section\n");
129
- break;
130
- case 3:
131
- if (need_fragile) {
132
- g_string_append(out, "\n\\begin_layout FragileFrame");
133
- } else {
134
- g_string_append(out, "\n\\begin_layout Frame");
135
- };
136
- g_string_append(out,"\n\\begin_inset Argument 4");
137
- g_string_append(out,"\nstatus open\n");
138
- g_string_append(out,"\n\\begin_layout Plain Layout\n");
139
- scratch->lyx_in_frame = TRUE;
140
- break;
141
- case 4:
142
- g_string_append(out,"\n\\begin_layout Standard");
143
- g_string_append(out, "\n\\begin_inset Flex ArticleMode");
144
- g_string_append(out, "\nstatus open\n\n");
145
- g_string_append(out,"\n\\begin_layout Plain Layout\n");
146
- break;
147
- default:
148
- g_string_append(out,"\n\\begin_layout Standard");
149
- g_string_append(out, "\n\\emph on\n");
150
- break;
151
- }
152
- /* Don't allow footnotes */
153
- scratch->no_lyx_footnote = TRUE;
154
- if (n->children->key == AUTOLABEL) {
155
- /* use label for header since one was specified (MMD)*/
156
- temp = label_from_string(n->children->str);
157
- prefixed_label = prefix_label(heading_name[lev-1]->str,temp,FALSE);
158
- print_lyx_node_tree(out, n->children->next, scratch , FALSE);
159
- g_string_append(out,"\n\\begin_inset CommandInset label\n");
160
- g_string_append(out,"LatexCommand label\n");
161
- g_string_append_printf(out, "name \"%s\"",prefixed_label);
162
- g_string_append(out,"\n\\end_inset\n");
163
- free(prefixed_label);
164
- free(temp);
165
- } else {
166
- /* generate a label by default for MMD */
167
- temp = label_from_node_tree(n->children);
168
- prefixed_label = prefix_label(heading_name[lev-1]->str,temp,FALSE);
169
- print_lyx_node_tree(out, n->children, scratch, FALSE);
170
- g_string_append(out,"\n\\begin_inset CommandInset label\n");
171
- g_string_append(out,"LatexCommand label\n");
172
- g_string_append_printf(out, "name \"%s\"",prefixed_label);
173
- g_string_append(out,"\n\\end_inset\n");
174
- free(prefixed_label);
175
- free(temp);
176
- }
177
- scratch->no_lyx_footnote = FALSE;
178
- switch(lev){
179
- case 1: case 2:
180
- g_string_append(out,"\n\\end_layout\n");
181
- break;
182
- case 3:
183
- g_string_append(out,"\n\\end_layout\n");
184
- g_string_append(out,"\n\\end_inset\n");
185
- g_string_append(out,"\n\\end_layout\n");
186
- g_string_append(out,"\n\\begin_deeper\n");
187
- break;
188
- case 4:
189
- g_string_append(out,"\n\\end_layout");
190
- g_string_append(out,"\n\\end_inset");
191
- g_string_append(out,"\n\\end_layout");
192
- break;
193
- default:
194
- g_string_append(out, "\n\\emph default\n");
195
- g_string_append(out,"\n\\end_layout");
196
- break;
197
- }
198
-
199
- break;
200
- default:
201
- /* most things are not changed for beamer output */
202
- print_lyx_node(out, n, scratch,no_newline);
203
- }
204
- }
205
-
206
- /* print_beamer_endnotes */
207
- void print_lyxbeamer_endnotes(GString *out, scratch_pad *scratch) {
208
- node *temp_node;
209
- scratch->used_notes = reverse_list(scratch->used_notes);
210
- node *note = scratch->used_notes;
211
-
212
- // Handle Glossary
213
- temp_node = note;
214
- while (temp_node != NULL){
215
- if(temp_node->key == GLOSSARYSOURCE){
216
- g_string_append(out, "\n\\begin_layout BeginFrame\nGlossary\n");
217
- g_string_append(out,"\n\\begin_layout Standard");
218
- g_string_append(out,"\n\\begin_inset CommandInset nomencl_print");
219
- g_string_append(out,"\nLatexCommand printnomenclature");
220
- g_string_append(out,"\nset_width \"auto\"\n");
221
- g_string_append(out,"\n\\end_inset\n");
222
- g_string_append(out,"\n\\end_layout\n");
223
- g_string_append(out, "\n\\end_layout\n");
224
- g_string_append(out, "\n\\begin_layout EndFrame");
225
- g_string_append(out, "\n\\end_layout");
226
- break;
227
- }
228
- temp_node = temp_node->next;
229
- }
230
-
231
- if (note == NULL)
232
- return;
233
-
234
- note = scratch->used_notes;
235
-
236
- if (tree_contains_key(note,CITATIONSOURCE)){
237
- g_string_append(out, "\n\\begin_layout BeginFrame\nReferences\n");
238
- g_string_append(out, "\n\\end_layout");
239
- }
240
- while ( note != NULL) {
241
- if (note->key == KEY_COUNTER) {
242
- note = note->next;
243
- continue;
244
- }
245
-
246
-
247
- if (note->key == CITATIONSOURCE) {
248
- g_string_append(out, "\n\\begin_layout Bibliography\n");
249
- g_string_append(out,"\\begin_inset CommandInset bibitem\n");
250
- g_string_append(out,"LatexCommand bibitem\n");
251
- g_string_append_printf(out, "key \"%s\"\n", note->str);
252
- g_string_append_printf(out, "label \"%s\"\n", note->str);
253
- g_string_append(out,"\n\\end_inset\n");
254
- print_lyx_node(out, note, scratch, FALSE);
255
- g_string_append(out,"\n\\end_layout\n");
256
- } else {
257
- /* footnotes handled elsewhere */
258
- }
259
-
260
- note = note->next;
261
- }
262
- g_string_append(out, "\n\\begin_layout EndFrame"); // close last frame
263
- g_string_append(out, "\n\\end_layout");
264
-
265
- }
@@ -1,11 +0,0 @@
1
- #ifndef LYX_BEAMER_PARSER_H
2
- #define LYX_BEAMER_PARSER_H
3
-
4
- #include "parser.h"
5
- #include "lyx.h"
6
-
7
- void print_lyxbeamer_node_tree(GString *out, node *list, scratch_pad *scratch,bool no_newline);
8
- void print_lyxbeamer_node(GString *out, node *n, scratch_pad *scratch,bool no_newline);
9
- void print_lyxbeamer_endnotes(GString *out, scratch_pad *scratch);
10
-
11
- #endif
@@ -1,80 +0,0 @@
1
- /*
2
-
3
- memoir.c -- Memoir add-on to LaTeX writer
4
-
5
- (c) 2013-2015 Fletcher T. Penney (http://fletcherpenney.net/).
6
-
7
- This program is free software; you can redistribute it and/or modify
8
- it under the terms of the GNU General Public License or the MIT
9
- license. See LICENSE for details.
10
-
11
- This program is distributed in the hope that it will be useful,
12
- but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- GNU General Public License for more details.
15
-
16
- */
17
-
18
- #include "memoir.h"
19
-
20
- /* print_memoir_node_tree -- convert node tree to LaTeX */
21
- void print_memoir_node_tree(GString *out, node *list, scratch_pad *scratch) {
22
- while (list != NULL) {
23
- print_memoir_node(out, list, scratch);
24
- list = list->next;
25
- }
26
- }
27
-
28
- /* print_memoir_node -- convert given node to LaTeX and append */
29
- void print_memoir_node(GString *out, node *n, scratch_pad *scratch) {
30
-
31
- /* If we are forcing a complete document, and METADATA isn't the first thing,
32
- we need to close <head> */
33
- if ((scratch->extensions & EXT_COMPLETE)
34
- && !(scratch->extensions & EXT_HEAD_CLOSED) &&
35
- !((n->key == FOOTER) || (n->key == METADATA))) {
36
- pad(out, 2, scratch);
37
- scratch->extensions = scratch->extensions | EXT_HEAD_CLOSED;
38
- }
39
- switch (n->key) {
40
- case VERBATIM:
41
- case VERBATIMFENCE:
42
- pad(out, 2, scratch);
43
- if ((n->children != NULL) && (n->children->key == VERBATIMTYPE)) {
44
- trim_trailing_whitespace(n->children->str);
45
- if (strlen(n->children->str) > 0) {
46
- g_string_append_printf(out, "\\begin{adjustwidth}{2.5em}{2.5em}\n\\begin{lstlisting}[language=%s]\n", n->children->str);
47
- print_raw_node(out, n);
48
- g_string_append_printf(out, "\n\\end{lstlisting}\n\\end{adjustwidth}");
49
- scratch->padded = 0;
50
- break;
51
- }
52
- }
53
- g_string_append_printf(out, "\\begin{adjustwidth}{2.5em}{2.5em}\n\\begin{verbatim}\n\n");
54
- print_raw_node(out, n);
55
- g_string_append_printf(out, "\n\\end{verbatim}\n\\end{adjustwidth}");
56
- scratch->padded = 0;
57
- break;
58
- case HEADINGSECTION:
59
- print_memoir_node_tree(out, n->children, scratch);
60
- break;
61
- case DEFLIST:
62
- pad(out, 2, scratch);
63
- g_string_append_printf(out, "\\begin{description}");
64
- scratch->padded = 0;
65
- print_memoir_node_tree(out, n->children, scratch);
66
- pad(out, 1, scratch);
67
- g_string_append_printf(out, "\\end{description}");
68
- scratch->padded = 0;
69
- break;
70
- case DEFINITION:
71
- pad(out, 2, scratch);
72
- scratch->padded = 2;
73
- print_memoir_node_tree(out, n->children, scratch);
74
- scratch->padded = 0;
75
- break;
76
- default:
77
- /* most things are not changed for memoir output */
78
- print_latex_node(out, n, scratch);
79
- }
80
- }
@@ -1,10 +0,0 @@
1
- #ifndef MEMOIR_PARSER_H
2
- #define MEMOIR_PARSER_H
3
-
4
- #include "parser.h"
5
- #include "latex.h"
6
-
7
- void print_memoir_node_tree(GString *out, node *list, scratch_pad *scratch);
8
- void print_memoir_node(GString *out, node *n, scratch_pad *scratch);
9
-
10
- #endif
@@ -1,518 +0,0 @@
1
- /*
2
-
3
- parser.leg -> parser.c -- Parse (Multi)Markdown plain text for
4
- conversion into other formats
5
-
6
- (c) 2013-2015 Fletcher T. Penney (http://fletcherpenney.net/).
7
-
8
- Derived from peg-multimarkdown, which was forked from peg-markdown,
9
- which is (c) 2008 John MacFarlane (jgm at berkeley dot edu), and
10
- licensed under GNU GPL or MIT.
11
-
12
- This program is free software; you can redistribute it and/or modify
13
- it under the terms of the GNU General Public License or the MIT
14
- license. See LICENSE for details.
15
-
16
- This program is distributed in the hope that it will be useful,
17
- but WITHOUT ANY WARRANTY; without even the implied warranty of
18
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
- GNU General Public License for more details.
20
- */
21
-
22
- #include <getopt.h>
23
- #include <libgen.h>
24
- #include "parser.h"
25
- #include "transclude.h"
26
-
27
- int main(int argc, char **argv)
28
- {
29
- int numargs;
30
- int c;
31
- int i;
32
- static int batch_flag = 0;
33
- static int complete_flag = 0;
34
- static int snippet_flag = 0;
35
- static int compatibility_flag = 0;
36
- static int notes_flag = 0;
37
- static int no_notes_flag = 0;
38
- static int typography_flag = 0;
39
- static int no_typography_flag = 0;
40
- static int label_flag = 0;
41
- static int no_label_flag = 0;
42
- static int escaped_line_breaks_flag = 0;
43
- static int obfuscate_flag = 0;
44
- static int no_obfuscate_flag = 0;
45
- static int process_html_flag = 0;
46
- static int random_footnotes_flag = 0;
47
- bool list_meta_keys = 0;
48
- bool list_transclude_manifest = 0;
49
- char *target_meta_key = FALSE;
50
-
51
- static struct option long_options[] = {
52
- {"batch", no_argument, &batch_flag, 1}, /* process each file separately */
53
- {"to", required_argument, 0, 't'}, /* which output format to use */
54
- {"full", no_argument, &complete_flag, 1}, /* complete document */
55
- {"snippet", no_argument, &snippet_flag, 1}, /* snippet only */
56
- {"output", required_argument, 0, 'o'}, /* which output format to use */
57
- {"notes", no_argument, &notes_flag, 1}, /* use footnotes */
58
- {"nonotes", no_argument, &no_notes_flag, 1}, /* don't use footnotes */
59
- {"smart", no_argument, &typography_flag, 1}, /* use smart typography */
60
- {"nosmart", no_argument, &no_typography_flag, 1}, /* don't use smart typography */
61
- {"mask", no_argument, &obfuscate_flag, 1}, /* mask email addresses */
62
- {"nomask", no_argument, &no_obfuscate_flag, 1}, /* don't mask email addresses */
63
- {"labels", no_argument, &label_flag, 1}, /* generate labels */
64
- {"nolabels", no_argument, &no_label_flag, 1}, /* don't generate labels */
65
- {"escaped-line-breaks", no_argument, &escaped_line_breaks_flag, 1}, /* enable escaped line breaks */
66
- {"compatibility", no_argument, &compatibility_flag, 1}, /* compatibility mode */
67
- {"process-html", no_argument, &process_html_flag, 1}, /* process Markdown inside HTML */
68
- {"random", no_argument, &random_footnotes_flag, 1}, /* Use random numbers for footnote links */
69
- {"accept", no_argument, 0, 'a'}, /* Accept all proposed CriticMarkup changes */
70
- {"reject", no_argument, 0, 'r'}, /* Reject all proposed CriticMarkup changes */
71
- {"metadata-keys", no_argument, 0, 'm'}, /* List all metadata keys */
72
- {"extract", required_argument, 0, 'e'}, /* show value of specified metadata */
73
- {"version", no_argument, 0, 'v'}, /* display version information */
74
- {"help", no_argument, 0, 'h'}, /* display usage information */
75
- {"manifest", no_argument, 0, 'x'}, /* List all transcluded files */
76
- {NULL, 0, NULL, 0}
77
- };
78
-
79
- GString *inputbuf;
80
- GString *manifest;
81
- FILE *input;
82
- FILE *output;
83
- int curchar;
84
- GString *filename = NULL;
85
-
86
- char *out;
87
-
88
- /* set up my data for the parser */
89
- int output_format = 0;
90
- unsigned long extensions = 0;
91
- extensions = extensions | EXT_SMART | EXT_NOTES | EXT_OBFUSCATE;
92
-
93
- /* process options */
94
- while (1) {
95
- int option_index = 0;
96
-
97
- c = getopt_long (argc, argv, "vhco:bfst:me:arx", long_options, &option_index);
98
-
99
- if (c == -1)
100
- break;
101
-
102
- switch (c) {
103
- case 0: /* handle long_options */
104
- /* printf ("option %s", long_options[option_index].name);
105
- if (optarg)
106
- printf (" with arg %s", optarg);
107
- printf("\n"); */
108
- break;
109
-
110
- case 'b': /* batch */
111
- batch_flag = 1;
112
- break;
113
-
114
- case 'c': /* compatibility */
115
- compatibility_flag = 1;
116
- break;
117
-
118
- case 'o': /* output filename */
119
- if (optarg)
120
- filename = g_string_new(optarg);
121
- break;
122
-
123
- case 'v': /* show version */
124
- printf("\nMultiMarkdown version %s\n%s\n",MMD_VERSION, MMD_COPYRIGHT);
125
- return(EXIT_SUCCESS);
126
-
127
- case 'h': /* show usage */
128
- printf("\nMultiMarkdown version %s\n\n",MMD_VERSION);
129
- printf(" %s [OPTION...] [FILE...]\n",argv[0]);
130
- printf("\n"
131
- " Options:\n"
132
- " -h, --help Show help\n"
133
- " -v, --version Show version information\n"
134
- " -o, --output=FILE Send output to FILE\n"
135
- " -t, --to=FORMAT Convert to FORMAT\n"
136
- " -b, --batch Process each file separately\n"
137
- " -c, --compatibility Markdown compatibility mode\n"
138
- " -f, --full Force a complete document\n"
139
- " -s, --snippet Force a snippet\n"
140
- " --process-html Process Markdown inside of raw HTML\n"
141
- " -m, --metadata-keys List all metadata keys\n"
142
- " -e, --extract Extract specified metadata\n"
143
- " -x, --manifest Show manifest of all transcluded files\n"
144
- " --random Use random numbers for footnote anchors\n"
145
- "\n"
146
- " -a, --accept Accept all CriticMarkup changes\n"
147
- " -r, --reject Reject all CriticMarkup changes\n"
148
- "\n"
149
- " --smart, --nosmart Toggle smart typography\n"
150
- " --notes, --nonotes Toggle footnotes\n"
151
- " --labels, --nolabels Disable id attributes for headers\n"
152
- " --mask, --nomask Mask email addresses in HTML\n"
153
- " --escaped-line-breaks Enable escaped line breaks\n"
154
-
155
- "\nAvailable FORMATs: html(default), latex, beamer, memoir, odf, opml, lyx, mmd\n\n"
156
- "NOTE: The lyx output format was created by Charles R. Cowan, and \n\tis provided as is.\n\n\n"
157
- );
158
- return(EXIT_SUCCESS);
159
-
160
- case 't': /* output format */
161
- if (strcmp(optarg, "text") == 0)
162
- output_format = TEXT_FORMAT;
163
- else if (strcmp(optarg, "html") == 0)
164
- output_format = HTML_FORMAT;
165
- else if (strcmp(optarg, "latex") == 0)
166
- output_format = LATEX_FORMAT;
167
- else if (strcmp(optarg, "memoir") == 0)
168
- output_format = MEMOIR_FORMAT;
169
- else if (strcmp(optarg, "beamer") == 0)
170
- output_format = BEAMER_FORMAT;
171
- else if (strcmp(optarg, "opml") == 0)
172
- output_format = OPML_FORMAT;
173
- else if (strcmp(optarg, "odf") == 0)
174
- output_format = ODF_FORMAT;
175
- else if (strcmp(optarg, "rtf") == 0)
176
- output_format = RTF_FORMAT;
177
- else if (strcmp(optarg, "lyx") == 0)
178
- output_format = LYX_FORMAT;
179
- else if (strcmp(optarg, "mmd") == 0)
180
- output_format = ORIGINAL_FORMAT;
181
- else {
182
- /* no valid format specified */
183
- fprintf(stderr, "%s: Unknown output format '%s'\n",argv[0], optarg);
184
- exit(EXIT_FAILURE);
185
- }
186
- break;
187
-
188
- case 'f': /* full doc */
189
- extensions = extensions | EXT_COMPLETE;
190
- break;
191
-
192
- case 's': /* snippet only */
193
- extensions = extensions | EXT_SNIPPET;
194
- break;
195
-
196
- case 'm': /* list metadata */
197
- list_meta_keys = 1;
198
- break;
199
-
200
- case 'e': /* extract metadata */
201
- target_meta_key = strdup(optarg);
202
- break;
203
-
204
- case '?': /* long handles */
205
- break;
206
-
207
- case 'a': /* Accept CriticMarkup changes */
208
- extensions = extensions | EXT_CRITIC_ACCEPT;
209
- break;
210
-
211
- case 'r': /* Reject CriticMarkup changes */
212
- extensions = extensions | EXT_CRITIC_REJECT;
213
- break;
214
-
215
- case 'x': /* List transcluded files */
216
- list_transclude_manifest = 1;
217
- break;
218
-
219
- default:
220
- fprintf(stderr,"Error parsing options.\n");
221
- abort();
222
- }
223
- }
224
-
225
- /* Compatibility mode emulates the behavior of Markdown.pl */
226
- if (compatibility_flag) {
227
- extensions = 0x000000;
228
- extensions = extensions | EXT_COMPATIBILITY | EXT_NO_LABELS | EXT_OBFUSCATE;
229
- }
230
-
231
- /* apply extensions from long options*/
232
- if (complete_flag)
233
- extensions = extensions | EXT_COMPLETE;
234
-
235
- if (snippet_flag)
236
- extensions = extensions | EXT_SNIPPET;
237
-
238
- if (notes_flag)
239
- extensions = extensions | EXT_NOTES;
240
-
241
- if (no_notes_flag)
242
- extensions &= ~EXT_NOTES;
243
-
244
- if (typography_flag)
245
- extensions = extensions | EXT_SMART;
246
-
247
- if (no_typography_flag)
248
- extensions &= ~EXT_SMART;
249
-
250
- if (label_flag)
251
- extensions &= ~EXT_NO_LABELS;
252
-
253
- if (no_label_flag)
254
- extensions = extensions | EXT_NO_LABELS;
255
-
256
- if (obfuscate_flag)
257
- extensions = extensions | EXT_OBFUSCATE;
258
-
259
- if (no_obfuscate_flag)
260
- extensions &= ~EXT_OBFUSCATE;
261
-
262
- if (process_html_flag)
263
- extensions = extensions | EXT_PROCESS_HTML;
264
-
265
- if (random_footnotes_flag)
266
- extensions = extensions | EXT_RANDOM_FOOT;
267
-
268
- if (escaped_line_breaks_flag)
269
- extensions = extensions | EXT_ESCAPED_LINE_BREAKS;
270
-
271
- /* Enable HEADINGSECTION for certain formats */
272
- if ((output_format == OPML_FORMAT) || (output_format == BEAMER_FORMAT) || (output_format == LYX_FORMAT))
273
- extensions = extensions | EXT_HEADINGSECTION;
274
-
275
- /* fix numbering to account for options */
276
- argc -= optind;
277
- argv += optind;
278
-
279
- /* We expect argc and argv to still point just one below the start of remaining args */
280
- argc++;
281
- argv--;
282
-
283
- /* any filenames */
284
- numargs = argc -1;
285
-
286
- if (batch_flag && (numargs != 0)) {
287
- /* we have multiple file names -- handle individually */
288
-
289
- for (i = 0; i < numargs; i++) {
290
- inputbuf = g_string_new("");
291
- manifest = g_string_new("");
292
- char *temp = NULL;
293
- char *folder = NULL;
294
-
295
- /* Read file */
296
- if ((input = fopen(argv[i+1], "r")) == NULL ) {
297
- perror(argv[i+1]);
298
- g_string_free(inputbuf, true);
299
- g_string_free(filename, true);
300
- exit(EXIT_FAILURE);
301
- }
302
-
303
- while ((curchar = fgetc(input)) != EOF)
304
- g_string_append_c(inputbuf, curchar);
305
- fclose(input);
306
-
307
- /* list metadata keys */
308
- if (list_meta_keys) {
309
- out = extract_metadata_keys(inputbuf->str, extensions);
310
- if (out != NULL) {
311
- fprintf(stdout, "%s", out);
312
- free(out);
313
- g_string_free(inputbuf, true);
314
- free(target_meta_key);
315
- return(EXIT_SUCCESS);
316
- }
317
- }
318
-
319
- /* extract metadata */
320
- if (target_meta_key) {
321
- out = extract_metadata_value(inputbuf->str, extensions, target_meta_key);
322
- if (out != NULL)
323
- fprintf(stdout, "%s\n", out);
324
- free(out);
325
- g_string_free(inputbuf, true);
326
- free(target_meta_key);
327
- return(EXIT_SUCCESS);
328
- }
329
-
330
- if (!(extensions & EXT_COMPATIBILITY)) {
331
- temp = strdup(argv[i+1]);
332
- folder = dirname(temp);
333
- prepend_mmd_header(inputbuf);
334
- append_mmd_footer(inputbuf);
335
- transclude_source(inputbuf, folder, NULL, output_format, manifest);
336
- free(temp);
337
- // free(folder);
338
- }
339
-
340
- /* list transclude manifest */
341
- if (list_transclude_manifest) {
342
- fprintf(stdout, "%s\n", manifest->str);
343
- g_string_free(inputbuf, true);
344
- g_string_free(manifest, true);
345
- return(EXIT_SUCCESS);
346
- } else {
347
- g_string_free(manifest, true);
348
- }
349
-
350
- if (output_format == ORIGINAL_FORMAT) {
351
- /* We want the source, don't parse */
352
- out = (inputbuf->str);
353
- g_string_free(inputbuf, FALSE);
354
- } else {
355
- out = markdown_to_string(inputbuf->str, extensions, output_format);
356
- g_string_free(inputbuf, true);
357
- }
358
-
359
- /* set up for output */
360
- temp = argv[i+1]; /* get current filename */
361
- if (strrchr(temp,'.') != NULL) {
362
- long count = strrchr(temp,'.') - temp;
363
- if (count != 0) {
364
- /* truncate string at "." */
365
- temp[count] = '\0';
366
- }
367
- }
368
-
369
- filename = g_string_new(temp);
370
-
371
- if (output_format == TEXT_FORMAT) {
372
- g_string_append(filename,".txt");
373
- } else if (output_format == HTML_FORMAT) {
374
- g_string_append(filename,".html");
375
- } else if (output_format == LATEX_FORMAT) {
376
- g_string_append(filename,".tex");
377
- } else if (output_format == BEAMER_FORMAT) {
378
- g_string_append(filename,".tex");
379
- } else if (output_format == MEMOIR_FORMAT) {
380
- g_string_append(filename,".tex");
381
- } else if (output_format == ODF_FORMAT) {
382
- g_string_append(filename,".fodt");
383
- } else if (output_format == OPML_FORMAT) {
384
- g_string_append(filename,".opml");
385
- } else if (output_format == LYX_FORMAT) {
386
- g_string_append(filename,".lyx");
387
- } else if (output_format == RTF_FORMAT) {
388
- g_string_append(filename,".rtf");
389
- } else if (output_format == ORIGINAL_FORMAT) {
390
- g_string_append(filename,".mmd_out");
391
- } else {
392
- /* default extension -- in this case we only have 1 */
393
- g_string_append(filename,".txt");
394
- }
395
-
396
- if (!(output = fopen(filename->str, "w"))) {
397
- perror(filename->str);
398
- } else {
399
- fprintf(output, "%s\n",out);
400
- fclose(output);
401
- }
402
-
403
- g_string_free(filename,true);
404
-
405
- if (out != NULL)
406
- free(out);
407
- }
408
- } else {
409
- /* get input from stdin or concat all files */
410
- inputbuf = g_string_new("");
411
- char *folder = NULL;
412
- char *temp = NULL;
413
- GString *manifest = g_string_new("");
414
-
415
- folder = getcwd(0,0);
416
-
417
- if (numargs == 0) {
418
- /* get stdin */
419
- while ((curchar = fgetc(stdin)) != EOF)
420
- g_string_append_c(inputbuf, curchar);
421
- fclose(stdin);
422
- } else {
423
- /* get files */
424
- free(folder);
425
- temp = strdup(argv[1]);
426
- folder = dirname(temp);
427
-
428
- for (i = 0; i < numargs; i++) {
429
- if ((input = fopen(argv[i+1], "r")) == NULL ) {
430
- perror(argv[i+1]);
431
- g_string_free(inputbuf, true);
432
- g_string_free(filename, true);
433
- // free(folder);
434
- free(temp);
435
- exit(EXIT_FAILURE);
436
- }
437
-
438
- while ((curchar = fgetc(input)) != EOF)
439
- g_string_append_c(inputbuf, curchar);
440
- fclose(input);
441
- }
442
- }
443
-
444
- if (!(extensions & EXT_COMPATIBILITY)) {
445
- prepend_mmd_header(inputbuf);
446
- append_mmd_footer(inputbuf);
447
- transclude_source(inputbuf, folder, NULL, output_format, manifest);
448
- }
449
-
450
- free(temp);
451
-
452
- //if (folder != NULL)
453
- // free(folder);
454
-
455
- /* list metadata keys */
456
- if (list_meta_keys) {
457
- out = extract_metadata_keys(inputbuf->str, extensions);
458
- if (out != NULL) {
459
- fprintf(stdout, "%s", out);
460
- free(out);
461
- g_string_free(inputbuf, true);
462
- free(target_meta_key);
463
- return(EXIT_SUCCESS);
464
- }
465
- }
466
-
467
- /* extract metadata */
468
- if (target_meta_key) {
469
- out = extract_metadata_value(inputbuf->str, extensions, target_meta_key);
470
- if (out != NULL)
471
- fprintf(stdout, "%s\n", out);
472
- free(out);
473
- g_string_free(inputbuf, true);
474
- free(target_meta_key);
475
- return(EXIT_SUCCESS);
476
- }
477
-
478
- /* list transclude manifest */
479
- if (list_transclude_manifest) {
480
- fprintf(stdout, "%s\n", manifest->str);
481
- g_string_free(inputbuf, true);
482
- g_string_free(manifest, true);
483
- return(EXIT_SUCCESS);
484
- } else {
485
- g_string_free(manifest, true);
486
- }
487
-
488
- if (output_format == ORIGINAL_FORMAT) {
489
- /* We want the source, don't parse */
490
- out = (inputbuf->str);
491
- g_string_free(inputbuf, FALSE);
492
- } else {
493
- out = markdown_to_string(inputbuf->str, extensions, output_format);
494
- g_string_free(inputbuf, true);
495
- }
496
-
497
- /* did we specify an output filename; "-" equals stdout */
498
- if ((filename == NULL) || (strcmp(filename->str, "-") == 0)) {
499
- output = stdout;
500
- } else if (!(output = fopen(filename->str, "w"))) {
501
- perror(filename->str);
502
- if (out != NULL)
503
- free(out);
504
- g_string_free(filename, true);
505
- return 1;
506
- }
507
-
508
- fprintf(output, "%s\n",out);
509
- fclose(output);
510
-
511
- g_string_free(filename, true);
512
-
513
- if (out != NULL)
514
- free(out);
515
- }
516
-
517
- return(EXIT_SUCCESS);
518
- }