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
data/ext/mmd/writer.h ADDED
@@ -0,0 +1,260 @@
1
+ /**
2
+
3
+ MultiMarkdown 6 -- Lightweight markup processor to produce HTML, LaTeX, and more.
4
+
5
+ @file writer.h
6
+
7
+ @brief Coordinate conversion of token tree to output formats.
8
+
9
+
10
+ @author Fletcher T. Penney
11
+ @bug
12
+
13
+ **/
14
+
15
+ /*
16
+
17
+ Copyright © 2016 - 2017 Fletcher T. Penney.
18
+
19
+
20
+ The `MultiMarkdown 6` project is released under the MIT License..
21
+
22
+ GLibFacade.c and GLibFacade.h are from the MultiMarkdown v4 project:
23
+
24
+ https://github.com/fletcher/MultiMarkdown-4/
25
+
26
+ MMD 4 is released under both the MIT License and GPL.
27
+
28
+
29
+ CuTest is released under the zlib/libpng license. See CuTest.c for the text
30
+ of the license.
31
+
32
+
33
+ ## The MIT License ##
34
+
35
+ Permission is hereby granted, free of charge, to any person obtaining a copy
36
+ of this software and associated documentation files (the "Software"), to deal
37
+ in the Software without restriction, including without limitation the rights
38
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
39
+ copies of the Software, and to permit persons to whom the Software is
40
+ furnished to do so, subject to the following conditions:
41
+
42
+ The above copyright notice and this permission notice shall be included in
43
+ all copies or substantial portions of the Software.
44
+
45
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
46
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
47
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
48
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
49
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
50
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
51
+ THE SOFTWARE.
52
+
53
+ */
54
+
55
+
56
+ #ifndef WRITER_MULTIMARKDOWN_H
57
+ #define WRITER_MULTIMARKDOWN_H
58
+
59
+ #ifdef TEST
60
+ #include "CuTest.h"
61
+ #endif
62
+
63
+ #include "d_string.h"
64
+ #include "mmd.h"
65
+ #include "stack.h"
66
+ #include "token.h"
67
+ #include "uthash.h"
68
+
69
+
70
+ #define kMaxExportRecursiveDepth 1000 //!< Maximum recursion depth when exporting token tree -- to prevent stack overflow with "pathologic" input
71
+
72
+ #define kMaxTableColumns 48 //!< Maximum number of table columns for specifying alignment
73
+
74
+ typedef struct {
75
+ struct link * link_hash;
76
+ struct meta * meta_hash;
77
+
78
+ unsigned long extensions;
79
+ short output_format;
80
+ short padded; //!< How many empty lines at end output buffer
81
+ short list_is_tight;
82
+ short close_para;
83
+ short skip_token;
84
+
85
+ short footnote_para_counter;
86
+ stack * used_footnotes;
87
+ stack * inline_footnotes_to_free;
88
+ struct fn_holder * footnote_hash;
89
+ short footnote_being_printed;
90
+
91
+ int random_seed_base;
92
+
93
+ stack * used_citations;
94
+ stack * inline_citations_to_free;
95
+ struct fn_holder * citation_hash;
96
+ short citation_being_printed;
97
+ char * bibtex_file;
98
+
99
+ stack * used_glossaries;
100
+ stack * inline_glossaries_to_free;
101
+ struct fn_holder * glossary_hash;
102
+ short glossary_being_printed;
103
+
104
+ stack * used_abbreviations;
105
+ stack * inline_abbreviations_to_free;
106
+ struct fn_holder * abbreviation_hash;
107
+
108
+ short language;
109
+ short quotes_lang;
110
+
111
+ short base_header_level;
112
+
113
+ stack * header_stack;
114
+
115
+ stack * outline_stack;
116
+
117
+ short recurse_depth;
118
+
119
+ short in_table_header;
120
+ short table_column_count;
121
+ short table_cell_count;
122
+ char table_alignment[kMaxTableColumns];
123
+
124
+ short odf_para_type;
125
+
126
+ struct asset * asset_hash;
127
+ short store_assets;
128
+ short remember_assets;
129
+ } scratch_pad;
130
+
131
+
132
+ struct attr {
133
+ char * key;
134
+ char * value;
135
+ struct attr * next;
136
+ };
137
+
138
+ typedef struct attr attr;
139
+
140
+ struct link {
141
+ token * label;
142
+ char * label_text;
143
+ char * clean_text;
144
+ char * url;
145
+ char * title;
146
+ attr * attributes;
147
+ UT_hash_handle hh;
148
+ };
149
+
150
+ typedef struct link link;
151
+
152
+ struct footnote {
153
+ token * label;
154
+ char * label_text;
155
+ char * clean_text;
156
+ token * content;
157
+ size_t count;
158
+ bool free_para;
159
+
160
+ char _PADDING[7]; //!< pad struct for alignment
161
+ };
162
+
163
+ typedef struct footnote footnote;
164
+
165
+ struct fn_holder {
166
+ footnote * note;
167
+ UT_hash_handle hh;
168
+ };
169
+
170
+ typedef struct fn_holder fn_holder;
171
+
172
+ struct meta {
173
+ char * key;
174
+ char * value;
175
+ size_t start;
176
+ UT_hash_handle hh;
177
+ };
178
+
179
+ typedef struct meta meta;
180
+
181
+ struct abbr {
182
+ char * abbr;
183
+ size_t abbr_len;
184
+ char * expansion;
185
+ size_t expansion_len;
186
+ UT_hash_handle hh;
187
+ };
188
+
189
+ typedef struct abbr abbr;
190
+
191
+
192
+ /// Temporary storage while exporting parse tree to output format
193
+ scratch_pad * scratch_pad_new(mmd_engine * e, short format);
194
+
195
+ void scratch_pad_free(scratch_pad * scratch);
196
+
197
+
198
+ /// Ensure at least num newlines at end of output buffer
199
+ void pad(DString * d, short num, scratch_pad * scratch);
200
+
201
+ link * explicit_link(scratch_pad * scratch, token * label, token * url, const char * source);
202
+
203
+ /// Find link based on label
204
+ link * extract_link_from_stack(scratch_pad * scratch, const char * target);
205
+
206
+ char * text_inside_pair(const char * source, token * pair);
207
+ char * clean_inside_pair(const char * source, token * t, bool lowercase);
208
+
209
+ void link_free(link * l);
210
+ void footnote_free(footnote * f);
211
+
212
+ char * label_from_token(const char * source, token * t);
213
+ char * label_from_header(const char * source, token * t);
214
+
215
+ void parse_brackets(const char * source, scratch_pad * scratch, token * bracket, link ** link, short * skip_token, bool * free_link);
216
+
217
+
218
+ void print_token_raw(DString * out, const char * source, token * t);
219
+
220
+ void print_token_tree_raw(DString * out, const char * source, token * t);
221
+
222
+ char * url_accept(const char * source, size_t start, size_t max_len, size_t * end_pos, bool validate);
223
+
224
+ void abbreviation_from_bracket(const char * source, scratch_pad * scratch, token * t, short * num);
225
+ void citation_from_bracket(const char * source, scratch_pad * scratch, token * t, short * num);
226
+ void footnote_from_bracket(const char * source, scratch_pad * scratch, token * t, short * num);
227
+ void glossary_from_bracket(const char * source, scratch_pad * scratch, token * t, short * num);
228
+
229
+ meta * meta_new(const char * source, size_t start, size_t len);
230
+ void meta_set_value(meta * m, const char * value);
231
+ void meta_free(meta * m);
232
+ char * extract_metadata(scratch_pad * scratch, const char * target);
233
+ meta * extract_meta_from_stack(scratch_pad * scratch, const char * target);
234
+
235
+ void read_table_column_alignments(const char * source, token * table, scratch_pad * scratch);
236
+
237
+ void strip_leading_whitespace(token * chain, const char * source);
238
+
239
+ bool table_has_caption(token * table);
240
+
241
+ char * get_fence_language_specifier(token * fence, const char * source);
242
+
243
+ token * manual_label_from_header(token * h, const char * source);
244
+
245
+ char * label_from_string(const char * str);
246
+
247
+ char * clean_string(const char * str, bool lowercase);
248
+
249
+ short raw_level_for_header(token * header);
250
+
251
+ void store_asset(scratch_pad * scratch_pad, char * url);
252
+ asset * extract_asset(scratch_pad * scratch, char * url);
253
+ void asset_free(asset * a);
254
+
255
+ bool raw_filter_text_matches(char * pattern, short format);
256
+ bool raw_filter_matches(token * filter, const char * source, short format);
257
+
258
+
259
+ #endif
260
+
data/ext/mmd/zip.c ADDED
@@ -0,0 +1,210 @@
1
+ /**
2
+
3
+ MultiMarkdown -- Lightweight markup processor to produce HTML, LaTeX, and more.
4
+
5
+ @file zip.c
6
+
7
+ @brief Common routines for zip-based file formats
8
+
9
+
10
+ @author Fletcher T. Penney
11
+ @bug
12
+
13
+ **/
14
+
15
+ /*
16
+
17
+ Copyright © 2016 - 2017 Fletcher T. Penney.
18
+
19
+
20
+ The `MultiMarkdown 6` project is released under the MIT License..
21
+
22
+ GLibFacade.c and GLibFacade.h are from the MultiMarkdown v4 project:
23
+
24
+ https://github.com/fletcher/MultiMarkdown-4/
25
+
26
+ MMD 4 is released under both the MIT License and GPL.
27
+
28
+
29
+ CuTest is released under the zlib/libpng license. See CuTest.c for the
30
+ text of the license.
31
+
32
+ uthash library:
33
+ Copyright (c) 2005-2016, Troy D. Hanson
34
+
35
+ Licensed under Revised BSD license
36
+
37
+ miniz library:
38
+ Copyright 2013-2014 RAD Game Tools and Valve Software
39
+ Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC
40
+
41
+ Licensed under the MIT license
42
+
43
+ argtable3 library:
44
+ Copyright (C) 1998-2001,2003-2011,2013 Stewart Heitmann
45
+ <sheitmann@users.sourceforge.net>
46
+ All rights reserved.
47
+
48
+ Licensed under the Revised BSD License
49
+
50
+
51
+ ## The MIT License ##
52
+
53
+ Permission is hereby granted, free of charge, to any person obtaining
54
+ a copy of this software and associated documentation files (the
55
+ "Software"), to deal in the Software without restriction, including
56
+ without limitation the rights to use, copy, modify, merge, publish,
57
+ distribute, sublicense, and/or sell copies of the Software, and to
58
+ permit persons to whom the Software is furnished to do so, subject to
59
+ the following conditions:
60
+
61
+ The above copyright notice and this permission notice shall be
62
+ included in all copies or substantial portions of the Software.
63
+
64
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
65
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
66
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
67
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
68
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
69
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
70
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
71
+
72
+
73
+ ## Revised BSD License ##
74
+
75
+ Redistribution and use in source and binary forms, with or without
76
+ modification, are permitted provided that the following conditions are
77
+ met:
78
+ * Redistributions of source code must retain the above copyright
79
+ notice, this list of conditions and the following disclaimer.
80
+ * Redistributions in binary form must reproduce the above
81
+ copyright notice, this list of conditions and the following
82
+ disclaimer in the documentation and/or other materials provided
83
+ with the distribution.
84
+ * Neither the name of the <organization> nor the
85
+ names of its contributors may be used to endorse or promote
86
+ products derived from this software without specific prior
87
+ written permission.
88
+
89
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
90
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
91
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
92
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT
93
+ HOLDER> BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
94
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
95
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES LOSS OF USE, DATA, OR
96
+ PROFITS OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
97
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
98
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
99
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
100
+
101
+
102
+ */
103
+
104
+ #include "zip.h"
105
+
106
+ #include <dirent.h>
107
+ #include <sys/stat.h>
108
+ #include <unistd.h>
109
+
110
+
111
+ // Windows deprecated mkdir()
112
+ // Fix per internet searches and modified by @f8ttyc8t (<https://github.com/f8ttyc8t>)
113
+ #if (defined(_WIN32) || defined(__WIN32__))
114
+ // Let compiler know where to find _mkdir()
115
+ #include <direct.h>
116
+ #define mkdir(A, B) _mkdir(A)
117
+ #endif
118
+
119
+
120
+ // Create new zip archive
121
+ void zip_new_archive(mz_zip_archive * pZip) {
122
+ memset(pZip, 0, sizeof(mz_zip_archive));
123
+
124
+ mz_bool status;
125
+
126
+ status = mz_zip_writer_init_heap(pZip, 0, 0);
127
+
128
+ if (!status) {
129
+ fprintf(stderr, "mz_zip_writer_init_heap() failed.\n");
130
+ }
131
+ }
132
+
133
+
134
+ // Unzip archive to specified file path
135
+ mz_bool unzip_archive_to_path(mz_zip_archive * pZip, const char * path) {
136
+ // Ensure folder 'path' exists
137
+
138
+ DIR * dir = opendir(path);
139
+ mz_bool status;
140
+
141
+ if (!dir) {
142
+ // path is not an existing directory
143
+
144
+ if (access(path, F_OK) == 0) {
145
+ // path is an existing file
146
+ fprintf(stderr, "'%s' is an existing file.\n", path);
147
+ return -1;
148
+ } else {
149
+ // path doesn't exist - create directory
150
+ mkdir(path, 0755);
151
+ }
152
+ }
153
+
154
+ dir = opendir(path);
155
+
156
+ if (dir) {
157
+ // Directory 'path' exists
158
+
159
+ // Remember current working directory
160
+ // Apparently PATH_MAX doesn't actually mean anything, so pick a big number
161
+ char cwd[4096 + 1];
162
+ getcwd(cwd, sizeof(cwd));
163
+
164
+ // Move into the desired directory
165
+ chdir(path);
166
+
167
+ int file_count = mz_zip_reader_get_num_files(pZip);
168
+
169
+ mz_zip_archive_file_stat pStat;
170
+
171
+ for (int i = 0; i < file_count; ++i) {
172
+ mz_zip_reader_file_stat(pZip, i, &pStat);
173
+
174
+ if (pStat.m_is_directory) {
175
+ // Create the directory
176
+ mkdir(pStat.m_filename, 0755);
177
+ } else {
178
+ status = mz_zip_reader_extract_to_file(pZip, i, pStat.m_filename, 0);
179
+
180
+ if (!status) {
181
+ fprintf(stderr, "Error extracting file from zip archive.\n");
182
+ return status;
183
+ }
184
+ }
185
+ }
186
+
187
+ // Return to prior working directory
188
+ chdir(cwd);
189
+ }
190
+
191
+
192
+ return 0;
193
+ }
194
+
195
+
196
+ // Unzip archive (as plain binary data) to specified file path
197
+ mz_bool unzip_data_to_path(const void * data, size_t size, const char * path) {
198
+ mz_zip_archive pZip;
199
+ memset(&pZip, 0, sizeof(mz_zip_archive));
200
+
201
+ mz_bool status = mz_zip_reader_init_mem(&pZip, data, size, 0);
202
+
203
+ if (!status) {
204
+ fprintf(stderr, "mz_zip_reader_init_mem() failed.\n");
205
+ return status;
206
+ }
207
+
208
+ return unzip_archive_to_path(&pZip, path);
209
+ }
210
+