rmultimarkdown 6.4.0.4 → 6.7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. checksums.yaml +5 -5
  2. data/Rakefile +7 -13
  3. data/ext/Makefile +67 -55
  4. data/ext/extconf.rb +7 -5
  5. data/ext/mmd/aho-corasick.c +8 -8
  6. data/ext/mmd/aho-corasick.h +3 -3
  7. data/ext/mmd/argtable3.c +6537 -0
  8. data/ext/mmd/argtable3.h +273 -0
  9. data/ext/mmd/beamer.c +12 -1
  10. data/ext/mmd/char.c +120 -27
  11. data/ext/mmd/char.h +23 -23
  12. data/ext/mmd/critic_markup.c +7 -6
  13. data/ext/mmd/d_string.c +88 -32
  14. data/ext/mmd/{include/d_string.h → d_string.h} +50 -38
  15. data/ext/mmd/epub.c +36 -12
  16. data/ext/mmd/epub.h +2 -2
  17. data/ext/mmd/file.c +50 -40
  18. data/ext/mmd/file.h +2 -2
  19. data/ext/mmd/html.c +164 -99
  20. data/ext/mmd/html.h +3 -2
  21. data/ext/mmd/i18n.h +15 -11
  22. data/ext/mmd/itmz-lexer.c +16978 -0
  23. data/ext/mmd/itmz-lexer.h +132 -0
  24. data/ext/mmd/itmz-parser.c +1189 -0
  25. data/ext/mmd/itmz-parser.h +11 -0
  26. data/ext/mmd/itmz-reader.c +388 -0
  27. data/ext/mmd/itmz-reader.h +111 -0
  28. data/ext/mmd/itmz.c +567 -0
  29. data/ext/mmd/itmz.h +117 -0
  30. data/ext/mmd/latex.c +93 -41
  31. data/ext/mmd/lexer.c +3506 -2774
  32. data/ext/mmd/{include/libMultiMarkdown.h → libMultiMarkdown.h} +49 -2
  33. data/ext/mmd/main.c +612 -0
  34. data/ext/mmd/memoir.c +4 -1
  35. data/ext/mmd/miniz.c +6905 -6680
  36. data/ext/mmd/miniz.h +456 -476
  37. data/ext/mmd/mmd.c +399 -94
  38. data/ext/mmd/mmd.h +25 -25
  39. data/ext/mmd/object_pool.h +3 -3
  40. data/ext/mmd/opendocument-content.c +137 -69
  41. data/ext/mmd/opendocument-content.h +2 -2
  42. data/ext/mmd/opendocument.c +35 -14
  43. data/ext/mmd/opendocument.h +2 -2
  44. data/ext/mmd/opml-lexer.c +259 -637
  45. data/ext/mmd/opml-lexer.h +1 -17
  46. data/ext/mmd/opml-parser.c +194 -188
  47. data/ext/mmd/opml-reader.c +72 -142
  48. data/ext/mmd/opml-reader.h +1 -1
  49. data/ext/mmd/opml.c +13 -13
  50. data/ext/mmd/opml.h +1 -1
  51. data/ext/mmd/parser.c +1623 -1244
  52. data/ext/mmd/rng.c +8 -3
  53. data/ext/mmd/scanners.c +66625 -103198
  54. data/ext/mmd/scanners.h +1 -0
  55. data/ext/mmd/stack.c +62 -20
  56. data/ext/mmd/stack.h +10 -21
  57. data/ext/mmd/textbundle.c +23 -7
  58. data/ext/mmd/textbundle.h +2 -2
  59. data/ext/mmd/token.c +42 -16
  60. data/ext/mmd/{include/token.h → token.h} +22 -8
  61. data/ext/mmd/token_pairs.c +0 -16
  62. data/ext/mmd/transclude.c +6 -2
  63. data/ext/mmd/uthash.h +745 -745
  64. data/ext/mmd/version.h +8 -8
  65. data/ext/mmd/writer.c +225 -63
  66. data/ext/mmd/writer.h +50 -36
  67. data/ext/mmd/xml.c +855 -0
  68. data/ext/mmd/xml.h +134 -0
  69. data/ext/mmd/zip.c +71 -4
  70. data/ext/mmd/zip.h +7 -1
  71. data/ext/ruby_multi_markdown.c +9 -18
  72. data/lib/multi_markdown/version.rb +1 -1
  73. data/lib/multi_markdown.bundle +0 -0
  74. data/rmultimarkdown.gemspec +0 -2
  75. metadata +22 -28
  76. data/ext/mmd/char_lookup.c +0 -212
data/ext/mmd/file.c CHANGED
@@ -119,38 +119,48 @@
119
119
  /// Scan file into a DString
120
120
  DString * scan_file(const char * fname) {
121
121
  /* Read from stdin and return a DString *
122
- `buffer` will need to be freed elsewhere */
122
+ `buffer` will need to be freed elsewhere */
123
123
 
124
124
  char chunk[kBUFFERSIZE];
125
125
  size_t bytes;
126
126
 
127
127
  FILE * file;
128
128
 
129
- #if defined(__WIN32)
129
+ #if defined(__WIN32)
130
130
  int wchars_num = MultiByteToWideChar(CP_UTF8, 0, fname, -1, NULL, 0);
131
131
  wchar_t wstr[wchars_num];
132
132
  MultiByteToWideChar(CP_UTF8, 0, fname, -1, wstr, wchars_num);
133
133
 
134
134
  if ((file = _wfopen(wstr, L"rb")) == NULL) {
135
- #else
135
+ return NULL;
136
+ }
136
137
 
137
- if ((file = fopen(fname, "r")) == NULL ) {
138
- #endif
138
+ #else
139
139
 
140
+ if ((file = fopen(fname, "r")) == NULL ) {
140
141
  return NULL;
141
142
  }
142
143
 
144
+ #endif
145
+
143
146
  DString * buffer = d_string_new("");
144
147
 
145
148
  while ((bytes = fread(chunk, 1, kBUFFERSIZE, file)) > 0) {
146
149
  d_string_append_c_array(buffer, chunk, bytes);
150
+ }
147
151
 
148
- if (buffer->currentStringLength <= kBUFFERSIZE) {
149
- // Strip BOM
150
- if (strncmp(buffer->str, "\xef\xbb\xbf", 3) == 0) {
151
- d_string_erase(buffer, 0, 3);
152
- }
153
- }
152
+ // Strip UTF-8 BOM
153
+ if (strncmp(buffer->str, "\xef\xbb\xbf", 3) == 0) {
154
+ d_string_erase(buffer, 0, 3);
155
+ }
156
+
157
+ // Strip UTF-16 BOMs
158
+ if (strncmp(buffer->str, "\xef\xff", 2) == 0) {
159
+ d_string_erase(buffer, 0, 2);
160
+ }
161
+
162
+ if (strncmp(buffer->str, "\xff\xfe", 2) == 0) {
163
+ d_string_erase(buffer, 0, 2);
154
164
  }
155
165
 
156
166
  fclose(file);
@@ -160,7 +170,7 @@ DString * scan_file(const char * fname) {
160
170
 
161
171
 
162
172
  /// Scan from stdin into a DString
163
- DString * stdin_buffer() {
173
+ DString * stdin_buffer(void) {
164
174
  /* Read from stdin and return a GString *
165
175
  `buffer` will need to be freed elsewhere */
166
176
 
@@ -182,38 +192,38 @@ DString * stdin_buffer() {
182
192
  /// Windows can use either `\` or `/` as a separator -- thanks to t-beckmann on github
183
193
  /// for suggesting a fix for this.
184
194
  bool is_separator(char c) {
185
- #if defined(__WIN32)
195
+ #if defined(__WIN32)
186
196
  return c == '\\' || c == '/';
187
- #else
197
+ #else
188
198
  return c == '/';
189
- #endif
199
+ #endif
190
200
  }
191
201
 
192
202
 
193
203
  #ifdef TEST
194
- void Test_is_separator(CuTest* tc) {
204
+ void Test_is_separator(CuTest * tc) {
195
205
  char * test = "a/\\";
196
206
 
197
- #if defined(__WIN32)
207
+ #if defined(__WIN32)
198
208
  CuAssertIntEquals(tc, false, is_separator(test[0]));
199
209
  CuAssertIntEquals(tc, true, is_separator(test[1]));
200
210
  CuAssertIntEquals(tc, true, is_separator(test[2]));
201
- #else
211
+ #else
202
212
  CuAssertIntEquals(tc, false, is_separator(test[0]));
203
213
  CuAssertIntEquals(tc, true, is_separator(test[1]));
204
214
  CuAssertIntEquals(tc, false, is_separator(test[2]));
205
- #endif
215
+ #endif
206
216
  }
207
217
  #endif
208
218
 
209
219
 
210
220
  /// Ensure that path ends in separator
211
221
  void add_trailing_sep(DString * path) {
212
- #if defined(__WIN32)
222
+ #if defined(__WIN32)
213
223
  char sep = '\\';
214
- #else
224
+ #else
215
225
  char sep = '/';
216
- #endif
226
+ #endif
217
227
 
218
228
  // Ensure that folder ends in separator
219
229
  if ((path->currentStringLength == 0) || (!is_separator(path->str[path->currentStringLength - 1]))) {
@@ -234,7 +244,7 @@ static char * my_strndup(const char * source, size_t n) {
234
244
 
235
245
  // strlen is too slow if strlen(source) >> n
236
246
  for (len = 0; len < n; ++len) {
237
- if (test == '\0') {
247
+ if (*test == '\0') {
238
248
  break;
239
249
  }
240
250
 
@@ -301,17 +311,17 @@ char * path_from_dir_base(const char * dir, const char * base) {
301
311
 
302
312
 
303
313
  #ifdef TEST
304
- void Test_path_from_dir_base(CuTest* tc) {
314
+ void Test_path_from_dir_base(CuTest * tc) {
305
315
  char dir[10] = "/foo";
306
316
  char base[10] = "bar";
307
317
 
308
318
  char * path = path_from_dir_base(dir, base);
309
319
 
310
- #if defined(__WIN32)
320
+ #if defined(__WIN32)
311
321
  CuAssertStrEquals(tc, "/foo\\bar", path);
312
- #else
322
+ #else
313
323
  CuAssertStrEquals(tc, "/foo/bar", path);
314
- #endif
324
+ #endif
315
325
 
316
326
  free(path);
317
327
  strcpy(base, "/bar");
@@ -334,11 +344,11 @@ void Test_path_from_dir_base(CuTest* tc) {
334
344
  void split_path_file(char ** dir, char ** file, const char * path) {
335
345
  const char * slash = path, * next;
336
346
 
337
- #if defined(__WIN32)
347
+ #if defined(__WIN32)
338
348
  const char sep[] = "\\/"; // Windows allows either variant
339
- #else
349
+ #else
340
350
  const char sep[] = "/";
341
- #endif
351
+ #endif
342
352
 
343
353
  while ((next = strpbrk(slash + 1, sep))) {
344
354
  slash = next;
@@ -359,7 +369,7 @@ void split_path_file(char ** dir, char ** file, const char * path) {
359
369
 
360
370
 
361
371
  #ifdef TEST
362
- void Test_split_path_file(CuTest* tc) {
372
+ void Test_split_path_file(CuTest * tc) {
363
373
  char * dir, * file;
364
374
 
365
375
  char * path = "/foo/bar.txt";
@@ -371,13 +381,13 @@ void Test_split_path_file(CuTest* tc) {
371
381
  path = "\\foo\\bar.txt";
372
382
  split_path_file(&dir, &file, path);
373
383
 
374
- #if defined(__WIN32)
384
+ #if defined(__WIN32)
375
385
  CuAssertStrEquals(tc, "\\foo\\", dir);
376
386
  CuAssertStrEquals(tc, "bar.txt", file);
377
- #else
387
+ #else
378
388
  CuAssertStrEquals(tc, "", dir);
379
389
  CuAssertStrEquals(tc, "\\foo\\bar.txt", file);
380
- #endif
390
+ #endif
381
391
  }
382
392
  #endif
383
393
 
@@ -388,15 +398,15 @@ void Test_split_path_file(CuTest* tc) {
388
398
  // Let compiler know where to find GetFullPathName()
389
399
  #include <windows.h>
390
400
 
391
- char *realpath(const char *path, char *resolved_path) {
401
+ char * realpath(const char * path, char * resolved_path) {
392
402
  DWORD retval = 0;
393
403
  DWORD dwBufSize = 0; // Just in case MAX_PATH differs from PATH_MAX
394
- TCHAR *buffer = NULL;
404
+ TCHAR * buffer = NULL;
395
405
 
396
406
  if (resolved_path == NULL) {
397
407
  // realpath allocates appropiate bytes if resolved_path is null. This is to mimic realpath behavior
398
408
  dwBufSize = PATH_MAX; // Use windows PATH_MAX constant, because we are in Windows context now.
399
- buffer = (char*)malloc(dwBufSize);
409
+ buffer = (char *)malloc(dwBufSize);
400
410
 
401
411
  if (buffer == NULL) {
402
412
  return NULL; // some really weird is going on...
@@ -421,15 +431,15 @@ char *realpath(const char *path, char *resolved_path) {
421
431
  // Convert argument to absolute path
422
432
  char * absolute_path_for_argument(const char * arg) {
423
433
  char * result = NULL;
424
- #ifdef PATH_MAX
434
+ #ifdef PATH_MAX
425
435
  // If PATH_MAX defined, use it
426
436
  char absolute[PATH_MAX + 1];
427
437
  realpath(arg, absolute);
428
438
  result = my_strdup(absolute);
429
- #else
439
+ #else
430
440
  // If undefined, then we *should* be able to use a NULL pointer to allocate
431
441
  result = realpath(arg, NULL);
432
- #endif
442
+ #endif
433
443
 
434
444
  return result;
435
445
  }
data/ext/mmd/file.h CHANGED
@@ -121,7 +121,7 @@ DString * scan_file(const char * fname);
121
121
 
122
122
 
123
123
  /// Scan from stdin into a DString
124
- DString * stdin_buffer();
124
+ DString * stdin_buffer(void);
125
125
 
126
126
 
127
127
  /// Windows can use either `\` or `/` as a separator -- thanks to t-beckmann on github
@@ -147,7 +147,7 @@ char * absolute_path_for_argument(const char * arg);
147
147
 
148
148
  #if (defined(_WIN32) || defined(__WIN32__))
149
149
  // Windows does not know realpath(), so we need a "windows port"
150
- char *realpath(const char *path, char *resolved_path);
150
+ char * realpath(const char * path, char * resolved_path);
151
151
  #endif
152
152
 
153
153
  #endif