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,17 +0,0 @@
1
- #ifndef RTF_PARSER_H
2
- #define RTF_PARSER_H
3
-
4
- #include "parser.h"
5
- #include "writer.h"
6
-
7
- void begin_rtf_output(GString *out, node* list, scratch_pad *scratch);
8
- void end_rtf_output(GString *out, node* list, scratch_pad *scratch);
9
- void print_rtf_node_tree(GString *out, node *list, scratch_pad *scratch);
10
- void print_rtf_node(GString *out, node *n, scratch_pad *scratch);
11
- void print_rtf_localized_typography(GString *out, int character, scratch_pad *scratch);
12
- void print_rtf_string(GString *out, char *str, scratch_pad *scratch);
13
- void print_rtf_code_string(GString *out, char *str, scratch_pad *scratch);
14
- void print_rtf_endnotes(GString *out, scratch_pad *scratch);
15
- void pad_rtf(GString *out, int pad, scratch_pad *scratch);
16
-
17
- #endif
@@ -1,56 +0,0 @@
1
- /*
2
- * public domain strtok_r() by Charlie Gordon
3
- *
4
- * from comp.lang.c 9/14/2007
5
- *
6
- * http://groups.google.com/group/comp.lang.c/msg/2ab1ecbb86646684
7
- *
8
- * (Declaration that it's public domain):
9
- * http://groups.google.com/group/comp.lang.c/msg/7c7b39328fefab9c
10
- */
11
-
12
- /* This file is only included since MINGW doesn't have strtok_r, so I can't
13
- compile for Windows without this */
14
-
15
- /* Also, fixed by Fletcher T. Penney --- added the "return NULL" when *nextp == NULL */
16
-
17
- /* This fix is also in the public domain */
18
-
19
- #include "strtok.h"
20
-
21
- char* strtok_r(
22
- char *str,
23
- const char *delim,
24
- char **nextp)
25
- {
26
- char *ret;
27
-
28
- if (str == NULL)
29
- {
30
- str = *nextp;
31
- }
32
-
33
- if (str == NULL) {
34
- return NULL;
35
- }
36
-
37
- str += strspn(str, delim);
38
-
39
- if (*str == '\0')
40
- {
41
- return NULL;
42
- }
43
-
44
- ret = str;
45
-
46
- str += strcspn(str, delim);
47
-
48
- if (*str)
49
- {
50
- *str++ = '\0';
51
- }
52
-
53
- *nextp = str;
54
-
55
- return ret;
56
- }
@@ -1,9 +0,0 @@
1
- /* This file is only included since MINGW doesn't have strtok_r, so I can't
2
- compile for Windows without this */
3
-
4
- #include <string.h>
5
-
6
- char* strtok_r(
7
- char *str,
8
- const char *delim,
9
- char **nextp);
@@ -1,53 +0,0 @@
1
- /*
2
-
3
- test.c -- plain text writer function as an example.
4
- Recreates the input source.
5
-
6
- (c) 2013-2015 Fletcher T. Penney (http://fletcherpenney.net/).
7
-
8
- This program is free software; you can redistribute it and/or modify
9
- it under the terms of the GNU General Public License or the MIT
10
- license. See LICENSE for details.
11
-
12
- This program is distributed in the hope that it will be useful,
13
- but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- GNU General Public License for more details.
16
-
17
- */
18
-
19
- #include "text.h"
20
-
21
-
22
- /* print_text_node_tree -- convert node tree to plain text */
23
- void print_text_node_tree(GString *out, node *list, scratch_pad *scratch) {
24
- while (list != NULL) {
25
- print_text_node(out, list, scratch);
26
- list = list->next;
27
- }
28
- }
29
-
30
- /* print_text_node -- convert given node to plain text and append */
31
- void print_text_node(GString *out, node *n, scratch_pad *scratch) {
32
- switch (n->key) {
33
- case STR:
34
- g_string_append_printf(out,"%s",n->str);
35
- break;
36
- case METADATA:
37
- print_text_node_tree(out,n->children,scratch);
38
- break;
39
- case METAKEY:
40
- g_string_append_printf(out,"%s:\t",n->str);
41
- print_text_node(out,n->children,scratch);
42
- break;
43
- case METAVALUE:
44
- g_string_append_printf(out,"%s",n->str);
45
- pad(out,1, scratch);
46
- break;
47
- case FOOTER:
48
- break;
49
- default:
50
- fprintf(stderr, "print_text_node encountered unknown node key = %d\n",n->key);
51
- exit(EXIT_FAILURE);
52
- }
53
- }
@@ -1,11 +0,0 @@
1
- #ifndef TEXT_PARSER_H
2
- #define TEXT_PARSER_H
3
-
4
- #include "parser.h"
5
- #include "writer.h"
6
-
7
- void print_text_node_tree(GString *out, node *list, scratch_pad *scratch);
8
- void print_text_node(GString *out, node *n, scratch_pad *scratch);
9
-
10
-
11
- #endif
@@ -1,142 +0,0 @@
1
- /*
2
-
3
- toc.c -- Table of contents
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 "toc.h"
19
-
20
-
21
- /* print_toc_node_tree -- convert node tree to LaTeX */
22
- void print_toc_node_tree(GString *out, node *list, scratch_pad *scratch) {
23
- #ifdef DEBUG_ON
24
- fprintf(stderr, "print_toc_node_tree\n");
25
- #endif
26
- int lev;
27
- while (list != NULL) {
28
- if (list->key == HEADINGSECTION) {
29
- lev = list->children->key;
30
-
31
- print_toc_section_and_children(out, list, scratch);
32
-
33
- while ((list->next != NULL) && (list->next->key == HEADINGSECTION)
34
- && (list->next->children->key > lev)) {
35
- list = list->next;
36
- }
37
- } else {
38
- print_toc_node(out, list, scratch);
39
- }
40
- list = list->next;
41
- }
42
- }
43
-
44
- /* print_toc_section_and_children -- we want to stay inside the outline structure */
45
- void print_toc_section_and_children(GString *out, node *list, scratch_pad *scratch) {
46
- #ifdef DEBUG_ON
47
- fprintf(stderr, "print_toc_section_and_children: %d\n",list->key);
48
- #endif
49
- int lev = list->children->key;
50
-
51
- /* print current section (parent) */
52
- print_toc_node(out, list, scratch);
53
-
54
- scratch->toc_level ++;
55
-
56
- /* check for child nodes */
57
- while ((list->next != NULL) && (list->next->key == HEADINGSECTION) && (list->next->children->key > lev)) {
58
- /* next item is also a HEADINGSECTION and is a child */
59
- if (list->next->children->key - lev == 1)
60
- print_toc_section_and_children(out, list->next, scratch);
61
- list = list->next;
62
- }
63
-
64
- scratch->toc_level --;
65
- }
66
-
67
- /* print_toc_node -- convert given node to OPML and append */
68
- void print_toc_node(GString *out, node *n, scratch_pad *scratch) {
69
- char *temp;
70
- int i;
71
-
72
- #ifdef DEBUG_ON
73
- fprintf(stderr, "print_toc_node: %d\n",n->key);
74
- #endif
75
- switch (n->key) {
76
- case HEADINGSECTION:
77
- /* Need to handle "nesting" properly */
78
- for (i = 0; i < scratch->toc_level; ++i)
79
- {
80
- g_string_append_printf(out, "\t");
81
- }
82
- g_string_append_printf(out, "* ");
83
-
84
- /* Print header */
85
- print_toc_node(out, n->children, scratch);
86
-
87
- break;
88
- case H1: case H2: case H3: case H4: case H5: case H6:
89
- if ((n->children != NULL) && (n->children->key == AUTOLABEL)) {
90
- temp = label_from_string(n->children->str);
91
- /* use label for header since one was specified (MMD)*/
92
- g_string_append_printf(out, "[");
93
- print_toc_node_tree(out, n->children, scratch);
94
- g_string_append_printf(out, "][%s]\n", temp);
95
- } else {
96
- temp = label_from_node_tree(n->children);
97
- g_string_append_printf(out, "[");
98
- print_toc_node_tree(out, n->children, scratch);
99
- g_string_append_printf(out, "][%s]\n", temp);
100
- }
101
- free(temp);
102
- break;
103
- case STR:
104
- print_toc_string(out, n->str);
105
- break;
106
- case SPACE:
107
- g_string_append_printf(out, "%s", n->str);
108
- break;
109
- case LINK:
110
- print_toc_node_tree(out, n->children, scratch);
111
- break;
112
- case LINKREFERENCE:
113
- break;
114
- case AUTOLABEL:
115
- break;
116
- case LIST:
117
- print_toc_node_tree(out, n->children, scratch);
118
- break;
119
- default: fprintf(stderr, "print_html_node encountered unknown node key = %d\n",n->key);
120
- break;
121
- }
122
- #ifdef DEBUG_ON
123
- fprintf(stderr, "finish print_toc_node: %d\n", n->key);
124
- #endif
125
- }
126
-
127
- /* print_toc_string - print string, escaping for OPML */
128
- void print_toc_string(GString *out, char *str) {
129
- while (*str != '\0') {
130
- switch (*str) {
131
- case '[':
132
- g_string_append_printf(out, "\\[");
133
- break;
134
- case ']':
135
- g_string_append_printf(out, "\\]");
136
- break;
137
- default:
138
- g_string_append_c(out, *str);
139
- }
140
- str++;
141
- }
142
- }
@@ -1,15 +0,0 @@
1
- #ifndef TOC_PARSER_H
2
- #define TOC_PARSER_H
3
-
4
- #include "parser.h"
5
- #include "writer.h"
6
-
7
- void begin_toc_output(GString *out, node* list, scratch_pad *scratch);
8
- void print_toc_node_tree(GString *out, node *list, scratch_pad *scratch);
9
- void print_toc_node(GString *out, node *n, scratch_pad *scratch);
10
- void print_toc_section_and_children(GString *out, node *list, scratch_pad *scratch);
11
- void end_toc_output(GString *out, node* list, scratch_pad *scratch);
12
- void print_toc_string(GString *out, char *str);
13
-
14
-
15
- #endif
@@ -1,307 +0,0 @@
1
- /*
2
-
3
- transclude.c -- miscellaneous support functions
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 "transclude.h"
19
- #include "parser.h"
20
- #if defined(__WIN32)
21
- #include <windows.h>
22
- #endif
23
-
24
-
25
- /* Combine directory and filename to create a full path */
26
- char * path_from_dir_base(char *dir, char *base) {
27
- #if defined(__WIN32)
28
- char sep = '\\';
29
- #else
30
- char sep = '/';
31
- #endif
32
- GString *path = NULL;
33
- char *result;
34
-
35
- if ((base != NULL) && (base[0] == sep)) {
36
- path = g_string_new(base);
37
- } else {
38
- path = g_string_new(dir);
39
-
40
- /* Ensure that folder ends in "/" */
41
- if (!(path->str[strlen(path->str)-1] == sep) ) {
42
- g_string_append_c(path, sep);
43
- }
44
-
45
- g_string_append_printf(path, "%s", base);
46
- }
47
-
48
- result = path->str;
49
- g_string_free(path, false);
50
-
51
- return result;
52
- }
53
-
54
- /* Separate filename and directory from a full path */
55
- /* See http://stackoverflow.com/questions/1575278/function-to-split-a-filepath-into-path-and-file */
56
- void split_path_file(char** dir, char** file, char *path) {
57
- char *slash = path, *next;
58
- #if defined(__WIN32)
59
- const char sep[] = "\\";
60
- #else
61
- const char sep[] = "/";
62
- #endif
63
-
64
- while ((next = strpbrk(slash + 1, sep))) slash = next;
65
- if (path != slash) slash++;
66
- *dir = my_strndup(path, slash - path);
67
- *file = strdup(slash);
68
- }
69
-
70
- /* Return pointer to beginning of text without metadata */
71
- /* NOTE: This is not a new string, and does not need to be freed separately */
72
- char * source_without_metadata(char * source, unsigned long extensions ) {
73
- char *result;
74
-
75
- if (has_metadata(source, extensions)) {
76
- /* If we have metadata, then return just the body */
77
- /* TODO: This could miss YAML Metadata that does not contain
78
- blank line afterwards */
79
- result = strstr(source, "\n\n");
80
-
81
- if (result != NULL)
82
- return result + 2;
83
- }
84
-
85
- /* No metadata, so return original pointer */
86
-
87
- /* But check for UTF-8 BOM and skip if present */
88
- if (strncmp(source, "\xef\xbb\xbf",3) == 0)
89
- return source + 3;
90
-
91
- return source;
92
- }
93
-
94
- /* Given a GString containing MMD source, and optional base directory,
95
- substitute transclusion references in the source
96
-
97
- Pass the path to the current folder if available -- should be a full path.
98
-
99
- Keep track of what we're parsing to prevent recursion using stack. */
100
- void transclude_source(GString *source, char *basedir, char *stack, int output_format, GString *manifest) {
101
- char *base = NULL;
102
- char *path = NULL;
103
- char *start;
104
- char *stop;
105
- char *temp;
106
- int curchar;
107
- size_t pos;
108
- char real[1000];
109
- FILE *input;
110
-
111
- if (basedir == NULL) {
112
- base = strdup("");
113
- } else {
114
- base = strdup(basedir);
115
- }
116
-
117
- GString *folder = NULL;
118
- GString *filename = NULL;
119
- GString *filebuffer = NULL;
120
- GString *stackstring = NULL;
121
-
122
- path = strdup(base);
123
-
124
- /* Look for override folder inside document */
125
- if (has_metadata(source->str, 0x000000)) {
126
- char *meta = extract_metadata_value(source->str, 0x000000, "transcludebase");
127
- if (meta != NULL)
128
- path = path_from_dir_base(base, meta);
129
- }
130
-
131
- if (path == NULL) {
132
- /* We have nowhere to look, so nothing to do */
133
- free(path);
134
- free(base);
135
- return;
136
- }
137
-
138
- folder = g_string_new(path);
139
-
140
- /* Ensure that folder ends in "/" */
141
- /* TODO: adjust for windows */
142
- if (!(folder->str[strlen(folder->str)-1] == '/') ) {
143
- g_string_append_c(folder, '/');
144
- }
145
-
146
- /* fprintf(stderr, "Transclude using '%s'\n", folder->str); */
147
-
148
- /* Iterate through {{foo.txt}} and substitute contents of file without metadata */
149
-
150
- start = strstr(source->str,"{{");
151
-
152
- while (start != NULL) {
153
- stop = strstr(start,"}}");
154
- if (stop == NULL)
155
- break;
156
-
157
- /* Check that we found something reasonable -- we cap at 1000 characters */
158
- if (stop - start < 1000) {
159
- strncpy(real,start+2,stop-start-2);
160
- real[stop-start-2] = '\0';
161
-
162
- filename = g_string_new(folder->str);
163
- g_string_append_printf(filename, "%s",real);
164
-
165
- /* Adjust for wildcard extensions */
166
- /* But not if output_format == 0 */
167
- if (output_format && strncmp(&filename->str[strlen(filename->str) - 2],".*",2) == 0) {
168
- g_string_erase(filename, strlen(filename->str) - 2, 2);
169
- if (output_format == TEXT_FORMAT) {
170
- g_string_append(filename,".txt");
171
- } else if (output_format == HTML_FORMAT) {
172
- g_string_append(filename,".html");
173
- } else if (output_format == LATEX_FORMAT) {
174
- g_string_append(filename,".tex");
175
- } else if (output_format == BEAMER_FORMAT) {
176
- g_string_append(filename,".tex");
177
- } else if (output_format == MEMOIR_FORMAT) {
178
- g_string_append(filename,".tex");
179
- } else if (output_format == ODF_FORMAT) {
180
- g_string_append(filename,".fodt");
181
- } else if (output_format == OPML_FORMAT) {
182
- g_string_append(filename,".opml");
183
- } else if (output_format == LYX_FORMAT) {
184
- g_string_append(filename,".lyx");
185
- } else if (output_format == RTF_FORMAT) {
186
- g_string_append(filename,".rtf");
187
- } else {
188
- /* default extension -- in this case we only have 1 */
189
- g_string_append(filename,".txt");
190
- }
191
- }
192
-
193
- pos = stop - source->str;
194
-
195
- /* Add to the manifest (if not already included) */
196
- if (manifest != NULL) {
197
- temp = strstr(manifest->str,filename->str);
198
-
199
- if ((temp != NULL) && (temp[strlen(filename->str)] == '\n')){
200
- /* Already on manifest */
201
- } else {
202
- g_string_append_printf(manifest,"%s\n",filename->str);
203
- }
204
- }
205
-
206
-
207
- /* Don't reparse ourselves */
208
- if (stack != NULL) {
209
- temp = strstr(stack,filename->str);
210
-
211
- if ((temp != NULL) && (temp[strlen(filename->str)] == '\n')){
212
- start = strstr(source->str + pos,"{{");
213
- g_string_free(filename, true);
214
- continue;
215
- }
216
- }
217
-
218
- /* Read file */
219
- #if defined(__WIN32)
220
- int wchars_num = MultiByteToWideChar(CP_UTF8, 0, filename->str, -1, NULL, 0);
221
- wchar_t wstr[wchars_num];
222
- MultiByteToWideChar(CP_UTF8, 0, filename->str, -1, wstr, wchars_num);
223
-
224
- if ((input = _wfopen(wstr, L"r")) != NULL ) {
225
- #else
226
- if ((input = fopen(filename->str, "r")) != NULL ) {
227
- #endif
228
- filebuffer = g_string_new("");
229
-
230
- while ((curchar = fgetc(input)) != EOF)
231
- g_string_append_c(filebuffer, curchar);
232
-
233
- fclose(input);
234
-
235
- pos = start - source->str;
236
-
237
- g_string_erase(source, pos, 2 + stop - start);
238
-
239
- /* Update stack list */
240
- stackstring = g_string_new(stack);
241
- g_string_append_printf(stackstring,"%s\n",filename->str);
242
-
243
-
244
- /* Recursively transclude files */
245
-
246
- /* We want to reset the base directory if we enter a subdirectory */
247
- char * new_dir;
248
- char * file_only;
249
- split_path_file(&new_dir, &file_only, filename->str);
250
-
251
- /* transclude_source(filebuffer, folder->str, stackstring->str, output_format, manifest); */
252
- transclude_source(filebuffer, new_dir, stackstring->str, output_format, manifest);
253
-
254
- free(new_dir);
255
- free(file_only);
256
-
257
- temp = source_without_metadata(filebuffer->str, 0x000000);
258
-
259
- g_string_insert(source, pos, temp);
260
-
261
- pos += strlen(temp);
262
- g_string_free(filebuffer, true);
263
- g_string_free(stackstring, true);
264
- } else {
265
- /* fprintf(stderr, "error opening file: %s\n", filename->str); */
266
- }
267
-
268
- g_string_free(filename, true);
269
- } else {
270
- /* Our "match" was > 1000 characters long */
271
- pos = stop - source->str;
272
- }
273
- start = strstr(source->str + pos,"{{");
274
- }
275
-
276
- g_string_free(folder, true);
277
- free(path);
278
- free(base);
279
- }
280
-
281
- /* Allow for a footer to specify files to be appended to the end of the text, and then transcluded.
282
- Useful for appending a list of footnotes, citations, abbreviations, etc. to each separate file,
283
- but not including multiple copies when processing the master file. */
284
- void append_mmd_footer(GString *source) {
285
- /* Look for mmd_footer metadata */
286
- if (has_metadata(source->str, 0x000000)) {
287
- char *meta = extract_metadata_value(source->str, 0x000000, "mmdfooter");
288
- if (meta != NULL)
289
- g_string_append_printf(source, "\n\n{{%s}}\n", meta);
290
- }
291
- }
292
-
293
- void prepend_mmd_header(GString *source) {
294
- /* Same thing, but to be inserted after metadata and before content */
295
- if (has_metadata(source->str, 0x000000)) {
296
- char *meta = extract_metadata_value(source->str, 0x000000, "mmdheader");
297
- if (meta != NULL) {
298
- char *content = strstr(source->str, "\n\n");
299
- if (content != NULL) {
300
- size_t pos = content - source->str;
301
- g_string_insert_printf(source, pos, "\n\n{{%s}}", meta);
302
- } else {
303
- g_string_append_printf(source, "\n\n{{%s}}\n", meta);
304
- }
305
- }
306
- }
307
- }