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.
- checksums.yaml +5 -5
- data/Rakefile +7 -13
- data/ext/Makefile +67 -55
- data/ext/extconf.rb +7 -5
- data/ext/mmd/aho-corasick.c +8 -8
- data/ext/mmd/aho-corasick.h +3 -3
- data/ext/mmd/argtable3.c +6537 -0
- data/ext/mmd/argtable3.h +273 -0
- data/ext/mmd/beamer.c +12 -1
- data/ext/mmd/char.c +120 -27
- data/ext/mmd/char.h +23 -23
- data/ext/mmd/critic_markup.c +7 -6
- data/ext/mmd/d_string.c +88 -32
- data/ext/mmd/{include/d_string.h → d_string.h} +50 -38
- data/ext/mmd/epub.c +36 -12
- data/ext/mmd/epub.h +2 -2
- data/ext/mmd/file.c +50 -40
- data/ext/mmd/file.h +2 -2
- data/ext/mmd/html.c +164 -99
- data/ext/mmd/html.h +3 -2
- data/ext/mmd/i18n.h +15 -11
- data/ext/mmd/itmz-lexer.c +16978 -0
- data/ext/mmd/itmz-lexer.h +132 -0
- data/ext/mmd/itmz-parser.c +1189 -0
- data/ext/mmd/itmz-parser.h +11 -0
- data/ext/mmd/itmz-reader.c +388 -0
- data/ext/mmd/itmz-reader.h +111 -0
- data/ext/mmd/itmz.c +567 -0
- data/ext/mmd/itmz.h +117 -0
- data/ext/mmd/latex.c +93 -41
- data/ext/mmd/lexer.c +3506 -2774
- data/ext/mmd/{include/libMultiMarkdown.h → libMultiMarkdown.h} +49 -2
- data/ext/mmd/main.c +612 -0
- data/ext/mmd/memoir.c +4 -1
- data/ext/mmd/miniz.c +6905 -6680
- data/ext/mmd/miniz.h +456 -476
- data/ext/mmd/mmd.c +399 -94
- data/ext/mmd/mmd.h +25 -25
- data/ext/mmd/object_pool.h +3 -3
- data/ext/mmd/opendocument-content.c +137 -69
- data/ext/mmd/opendocument-content.h +2 -2
- data/ext/mmd/opendocument.c +35 -14
- data/ext/mmd/opendocument.h +2 -2
- data/ext/mmd/opml-lexer.c +259 -637
- data/ext/mmd/opml-lexer.h +1 -17
- data/ext/mmd/opml-parser.c +194 -188
- data/ext/mmd/opml-reader.c +72 -142
- data/ext/mmd/opml-reader.h +1 -1
- data/ext/mmd/opml.c +13 -13
- data/ext/mmd/opml.h +1 -1
- data/ext/mmd/parser.c +1623 -1244
- data/ext/mmd/rng.c +8 -3
- data/ext/mmd/scanners.c +66625 -103198
- data/ext/mmd/scanners.h +1 -0
- data/ext/mmd/stack.c +62 -20
- data/ext/mmd/stack.h +10 -21
- data/ext/mmd/textbundle.c +23 -7
- data/ext/mmd/textbundle.h +2 -2
- data/ext/mmd/token.c +42 -16
- data/ext/mmd/{include/token.h → token.h} +22 -8
- data/ext/mmd/token_pairs.c +0 -16
- data/ext/mmd/transclude.c +6 -2
- data/ext/mmd/uthash.h +745 -745
- data/ext/mmd/version.h +8 -8
- data/ext/mmd/writer.c +225 -63
- data/ext/mmd/writer.h +50 -36
- data/ext/mmd/xml.c +855 -0
- data/ext/mmd/xml.h +134 -0
- data/ext/mmd/zip.c +71 -4
- data/ext/mmd/zip.h +7 -1
- data/ext/ruby_multi_markdown.c +9 -18
- data/lib/multi_markdown/version.rb +1 -1
- data/lib/multi_markdown.bundle +0 -0
- data/rmultimarkdown.gemspec +0 -2
- metadata +22 -28
- data/ext/mmd/char_lookup.c +0 -212
data/ext/mmd/d_string.c
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Dynamic string -- Lightweight dynamic string implementation.
|
|
4
4
|
|
|
5
5
|
@file d_string.c
|
|
6
6
|
|
|
7
|
-
@brief Dynamic string -- refactoring of old GLibFacade
|
|
8
|
-
"object" that can grow to accomodate any size content
|
|
7
|
+
@brief Dynamic string -- refactoring of old GLibFacade from MultiMarkdown.
|
|
8
|
+
Provides a string "object" that can grow to accomodate any size content
|
|
9
|
+
that is appended.
|
|
9
10
|
|
|
10
11
|
|
|
11
12
|
@author Daniel Jalkut, modified by Fletcher T. Penney and Dan Lowe
|
|
@@ -17,7 +18,7 @@
|
|
|
17
18
|
/*
|
|
18
19
|
|
|
19
20
|
Copyright © 2011 Daniel Jalkut.
|
|
20
|
-
Modifications by Fletcher T. Penney, Copyright © 2011-
|
|
21
|
+
Modifications by Fletcher T. Penney, Copyright © 2011-2020 Fletcher T. Penney.
|
|
21
22
|
Modifications by Dan Lowe, Copyright © 2011 Dan Lowe.
|
|
22
23
|
|
|
23
24
|
|
|
@@ -84,17 +85,17 @@
|
|
|
84
85
|
// Some operating systems do not supply vasprintf() -- standardize on this
|
|
85
86
|
// replacement from:
|
|
86
87
|
// https://github.com/esp8266/Arduino/issues/1954
|
|
87
|
-
int vasprintf(char** strp, const char* fmt, va_list ap) {
|
|
88
|
+
int vasprintf(char ** strp, const char * fmt, va_list ap) {
|
|
88
89
|
va_list ap2;
|
|
89
90
|
va_copy(ap2, ap);
|
|
90
91
|
|
|
91
|
-
|
|
92
|
-
char *tmp = NULL;
|
|
92
|
+
#if (defined(_WIN32) || defined(__WIN32__))
|
|
93
|
+
char * tmp = NULL;
|
|
93
94
|
int size = vsnprintf(tmp, 0, fmt, ap2);
|
|
94
|
-
|
|
95
|
+
#else
|
|
95
96
|
char tmp[1];
|
|
96
97
|
int size = vsnprintf(tmp, 1, fmt, ap2);
|
|
97
|
-
|
|
98
|
+
#endif
|
|
98
99
|
|
|
99
100
|
if (size <= 0) {
|
|
100
101
|
return size;
|
|
@@ -102,7 +103,7 @@ int vasprintf(char** strp, const char* fmt, va_list ap) {
|
|
|
102
103
|
|
|
103
104
|
va_end(ap2);
|
|
104
105
|
size += 1;
|
|
105
|
-
*strp = (char*)malloc(size * sizeof(char));
|
|
106
|
+
*strp = (char *)malloc(size * sizeof(char));
|
|
106
107
|
return vsnprintf(*strp, size, fmt, ap);
|
|
107
108
|
}
|
|
108
109
|
|
|
@@ -115,8 +116,8 @@ int vasprintf(char** strp, const char* fmt, va_list ap) {
|
|
|
115
116
|
|
|
116
117
|
|
|
117
118
|
/// Create a new dynamic string
|
|
118
|
-
DString* d_string_new(const char * startingString) {
|
|
119
|
-
DString* newString = malloc(sizeof(DString));
|
|
119
|
+
DString * d_string_new(const char * startingString) {
|
|
120
|
+
DString * newString = malloc(sizeof(DString));
|
|
120
121
|
|
|
121
122
|
if (!newString) {
|
|
122
123
|
return NULL;
|
|
@@ -150,7 +151,7 @@ DString* d_string_new(const char * startingString) {
|
|
|
150
151
|
|
|
151
152
|
|
|
152
153
|
#ifdef TEST
|
|
153
|
-
void Test_d_string_new(CuTest* tc) {
|
|
154
|
+
void Test_d_string_new(CuTest * tc) {
|
|
154
155
|
char * test = "foo";
|
|
155
156
|
|
|
156
157
|
DString * result = d_string_new(test);
|
|
@@ -175,12 +176,12 @@ void Test_d_string_new(CuTest* tc) {
|
|
|
175
176
|
|
|
176
177
|
|
|
177
178
|
/// Free dynamic string
|
|
178
|
-
char* d_string_free(DString * ripString, bool freeCharacterData) {
|
|
179
|
+
char * d_string_free(DString * ripString, bool freeCharacterData) {
|
|
179
180
|
if (ripString == NULL) {
|
|
180
181
|
return NULL;
|
|
181
182
|
}
|
|
182
183
|
|
|
183
|
-
char* returnedString = ripString->str;
|
|
184
|
+
char * returnedString = ripString->str;
|
|
184
185
|
|
|
185
186
|
if (freeCharacterData) {
|
|
186
187
|
if (ripString->str != NULL) {
|
|
@@ -212,7 +213,7 @@ static void ensureStringBufferCanHold(DString * baseString, size_t newStringSize
|
|
|
212
213
|
}
|
|
213
214
|
}
|
|
214
215
|
|
|
215
|
-
char *temp;
|
|
216
|
+
char * temp;
|
|
216
217
|
temp = realloc(baseString->str, newBufferSize);
|
|
217
218
|
|
|
218
219
|
if (temp == NULL) {
|
|
@@ -230,7 +231,7 @@ static void ensureStringBufferCanHold(DString * baseString, size_t newStringSize
|
|
|
230
231
|
|
|
231
232
|
|
|
232
233
|
#ifdef TEST
|
|
233
|
-
void Test_ensureStringBufferCanHold(CuTest* tc) {
|
|
234
|
+
void Test_ensureStringBufferCanHold(CuTest * tc) {
|
|
234
235
|
char * test = "foo";
|
|
235
236
|
|
|
236
237
|
DString * result = d_string_new(test);
|
|
@@ -276,7 +277,7 @@ void d_string_append(DString * baseString, const char * appendedString) {
|
|
|
276
277
|
|
|
277
278
|
|
|
278
279
|
#ifdef TEST
|
|
279
|
-
void Test_d_string_append(CuTest* tc) {
|
|
280
|
+
void Test_d_string_append(CuTest * tc) {
|
|
280
281
|
char * test = "foo";
|
|
281
282
|
|
|
282
283
|
DString * result = d_string_new(test);
|
|
@@ -311,7 +312,7 @@ void d_string_append_c(DString * baseString, char appendedCharacter) {
|
|
|
311
312
|
|
|
312
313
|
|
|
313
314
|
#ifdef TEST
|
|
314
|
-
void Test_d_string_append_c(CuTest* tc) {
|
|
315
|
+
void Test_d_string_append_c(CuTest * tc) {
|
|
315
316
|
char * test = "foo";
|
|
316
317
|
|
|
317
318
|
DString * result = d_string_new(test);
|
|
@@ -342,10 +343,10 @@ void d_string_append_c_array(DString * baseString, const char * appendedChars, s
|
|
|
342
343
|
size_t newSizeNeeded = baseString->currentStringLength + bytes;
|
|
343
344
|
ensureStringBufferCanHold(baseString, newSizeNeeded);
|
|
344
345
|
|
|
345
|
-
memcpy(baseString->str + baseString->currentStringLength, appendedChars, bytes);
|
|
346
|
+
memcpy((void *)baseString->str + baseString->currentStringLength, appendedChars, bytes);
|
|
346
347
|
|
|
347
348
|
baseString->currentStringLength = newSizeNeeded;
|
|
348
|
-
baseString->str[
|
|
349
|
+
baseString->str[newSizeNeeded] = '\0';
|
|
349
350
|
}
|
|
350
351
|
}
|
|
351
352
|
}
|
|
@@ -353,7 +354,7 @@ void d_string_append_c_array(DString * baseString, const char * appendedChars, s
|
|
|
353
354
|
|
|
354
355
|
|
|
355
356
|
#ifdef TEST
|
|
356
|
-
void Test_d_string_append_c_array(CuTest* tc) {
|
|
357
|
+
void Test_d_string_append_c_array(CuTest * tc) {
|
|
357
358
|
char * test = "foo";
|
|
358
359
|
|
|
359
360
|
DString * result = d_string_new(test);
|
|
@@ -387,7 +388,7 @@ void d_string_append_printf(DString * baseString, const char * format, ...) {
|
|
|
387
388
|
va_list args;
|
|
388
389
|
va_start(args, format);
|
|
389
390
|
|
|
390
|
-
char* formattedString = NULL;
|
|
391
|
+
char * formattedString = NULL;
|
|
391
392
|
vasprintf(&formattedString, format, args);
|
|
392
393
|
|
|
393
394
|
if (formattedString != NULL) {
|
|
@@ -401,7 +402,7 @@ void d_string_append_printf(DString * baseString, const char * format, ...) {
|
|
|
401
402
|
|
|
402
403
|
|
|
403
404
|
#ifdef TEST
|
|
404
|
-
void Test_d_string_append_printf(CuTest* tc) {
|
|
405
|
+
void Test_d_string_append_printf(CuTest * tc) {
|
|
405
406
|
char * test = "foo";
|
|
406
407
|
|
|
407
408
|
DString * result = d_string_new(test);
|
|
@@ -444,7 +445,7 @@ void d_string_prepend(DString * baseString, const char * prependedString) {
|
|
|
444
445
|
|
|
445
446
|
|
|
446
447
|
#ifdef TEST
|
|
447
|
-
void Test_d_string_prepend(CuTest* tc) {
|
|
448
|
+
void Test_d_string_prepend(CuTest * tc) {
|
|
448
449
|
char * test = "foo";
|
|
449
450
|
|
|
450
451
|
DString * result = d_string_new(test);
|
|
@@ -488,7 +489,7 @@ void d_string_insert(DString * baseString, size_t pos, const char * insertedStri
|
|
|
488
489
|
|
|
489
490
|
|
|
490
491
|
#ifdef TEST
|
|
491
|
-
void Test_d_string_insert(CuTest* tc) {
|
|
492
|
+
void Test_d_string_insert(CuTest * tc) {
|
|
492
493
|
char * test = "foo";
|
|
493
494
|
|
|
494
495
|
DString * result = d_string_new(test);
|
|
@@ -533,7 +534,7 @@ void d_string_insert_c(DString * baseString, size_t pos, char insertedCharacter)
|
|
|
533
534
|
|
|
534
535
|
|
|
535
536
|
#ifdef TEST
|
|
536
|
-
void Test_d_string_insert_c(CuTest* tc) {
|
|
537
|
+
void Test_d_string_insert_c(CuTest * tc) {
|
|
537
538
|
char * test = "foo";
|
|
538
539
|
|
|
539
540
|
DString * result = d_string_new(test);
|
|
@@ -557,13 +558,62 @@ void Test_d_string_insert_c(CuTest* tc) {
|
|
|
557
558
|
#endif
|
|
558
559
|
|
|
559
560
|
|
|
561
|
+
/// Insert array of characters inside dynamic string
|
|
562
|
+
void d_string_insert_c_array(DString * baseString, size_t pos, const char * insertedString, size_t bytes) {
|
|
563
|
+
if (baseString && insertedString) {
|
|
564
|
+
if (bytes == -1) {
|
|
565
|
+
// Same as regular insertion
|
|
566
|
+
d_string_insert(baseString, pos, insertedString);
|
|
567
|
+
} else {
|
|
568
|
+
if (pos > baseString->currentStringLength) {
|
|
569
|
+
pos = baseString->currentStringLength;
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
size_t newSizeNeeded = baseString->currentStringLength + bytes;
|
|
573
|
+
ensureStringBufferCanHold(baseString, newSizeNeeded);
|
|
574
|
+
|
|
575
|
+
/* Shift following string to 'right' */
|
|
576
|
+
memmove(baseString->str + pos + bytes, baseString->str + pos, baseString->currentStringLength - pos);
|
|
577
|
+
strncpy(baseString->str + pos, insertedString, bytes);
|
|
578
|
+
baseString->currentStringLength = newSizeNeeded;
|
|
579
|
+
baseString->str[baseString->currentStringLength] = '\0';
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
|
|
585
|
+
#ifdef TEST
|
|
586
|
+
void Test_d_string_insert_c_array(CuTest * tc) {
|
|
587
|
+
char * test = "foo";
|
|
588
|
+
|
|
589
|
+
DString * result = d_string_new(test);
|
|
590
|
+
|
|
591
|
+
d_string_insert_c_array(result, 2, "bar", 2);
|
|
592
|
+
CuAssertStrEquals(tc, "fobao", result->str);
|
|
593
|
+
CuAssertIntEquals(tc, 5, result->currentStringLength);
|
|
594
|
+
|
|
595
|
+
d_string_insert_c_array(result, -1, "bar", 3);
|
|
596
|
+
CuAssertStrEquals(tc, "fobaobar", result->str);
|
|
597
|
+
CuAssertIntEquals(tc, 8, result->currentStringLength);
|
|
598
|
+
|
|
599
|
+
d_string_insert_c_array(result, -1, NULL, -1);
|
|
600
|
+
CuAssertStrEquals(tc, "fobaobar", result->str);
|
|
601
|
+
CuAssertIntEquals(tc, 8, result->currentStringLength);
|
|
602
|
+
|
|
603
|
+
d_string_insert_c_array(NULL, 0, NULL, -1);
|
|
604
|
+
|
|
605
|
+
d_string_free(result, true);
|
|
606
|
+
}
|
|
607
|
+
#endif
|
|
608
|
+
|
|
609
|
+
|
|
560
610
|
/// Insert inside dynamic string using format specifier
|
|
561
611
|
void d_string_insert_printf(DString * baseString, size_t pos, const char * format, ...) {
|
|
562
612
|
if (baseString && format) {
|
|
563
613
|
va_list args;
|
|
564
614
|
va_start(args, format);
|
|
565
615
|
|
|
566
|
-
char* formattedString = NULL;
|
|
616
|
+
char * formattedString = NULL;
|
|
567
617
|
vasprintf(&formattedString, format, args);
|
|
568
618
|
|
|
569
619
|
if (formattedString != NULL) {
|
|
@@ -577,7 +627,7 @@ void d_string_insert_printf(DString * baseString, size_t pos, const char * forma
|
|
|
577
627
|
|
|
578
628
|
|
|
579
629
|
#ifdef TEST
|
|
580
|
-
void Test_d_string_insert_printf(CuTest* tc) {
|
|
630
|
+
void Test_d_string_insert_printf(CuTest * tc) {
|
|
581
631
|
char * test = "foo";
|
|
582
632
|
|
|
583
633
|
DString * result = d_string_new(test);
|
|
@@ -621,7 +671,7 @@ void d_string_erase(DString * baseString, size_t pos, size_t len) {
|
|
|
621
671
|
|
|
622
672
|
|
|
623
673
|
#ifdef TEST
|
|
624
|
-
void Test_d_string_erase(CuTest* tc) {
|
|
674
|
+
void Test_d_string_erase(CuTest * tc) {
|
|
625
675
|
char * test = "foobar";
|
|
626
676
|
|
|
627
677
|
DString * result = d_string_new(test);
|
|
@@ -677,7 +727,7 @@ char * d_string_copy_substring(DString * d, size_t start, size_t len) {
|
|
|
677
727
|
|
|
678
728
|
|
|
679
729
|
#ifdef TEST
|
|
680
|
-
void Test_d_string_copy_substring(CuTest* tc) {
|
|
730
|
+
void Test_d_string_copy_substring(CuTest * tc) {
|
|
681
731
|
char * test = "foobar";
|
|
682
732
|
|
|
683
733
|
DString * result = d_string_new(test);
|
|
@@ -712,6 +762,11 @@ long d_string_replace_text_in_range(DString * d, size_t pos, size_t len, const c
|
|
|
712
762
|
if (d && original && replace) {
|
|
713
763
|
long delta = 0; // Overall change in length
|
|
714
764
|
|
|
765
|
+
if (pos > d->currentStringLength) {
|
|
766
|
+
// Out of range
|
|
767
|
+
return 0;
|
|
768
|
+
}
|
|
769
|
+
|
|
715
770
|
long len_o = strlen(original);
|
|
716
771
|
long len_r = strlen(replace);
|
|
717
772
|
long change = len_r - len_o; // Change in length for each replacement
|
|
@@ -748,7 +803,7 @@ long d_string_replace_text_in_range(DString * d, size_t pos, size_t len, const c
|
|
|
748
803
|
|
|
749
804
|
|
|
750
805
|
#ifdef TEST
|
|
751
|
-
void Test_d_string_replace_text_in_range(CuTest* tc) {
|
|
806
|
+
void Test_d_string_replace_text_in_range(CuTest * tc) {
|
|
752
807
|
char * test = "foobarfoobarfoo";
|
|
753
808
|
long delta = 0;
|
|
754
809
|
|
|
@@ -783,3 +838,4 @@ void Test_d_string_replace_text_in_range(CuTest* tc) {
|
|
|
783
838
|
d_string_free(result, true);
|
|
784
839
|
}
|
|
785
840
|
#endif
|
|
841
|
+
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Dynamic string -- Lightweight dynamic string implementation.
|
|
4
4
|
|
|
5
5
|
@file d_string.h
|
|
6
6
|
|
|
7
|
-
@brief Dynamic string -- refactoring of old GLibFacade
|
|
8
|
-
"object" that can grow to accomodate any size content
|
|
7
|
+
@brief Dynamic string -- refactoring of old GLibFacade from MultiMarkdown.
|
|
8
|
+
Provides a string "object" that can grow to accomodate any size content
|
|
9
|
+
that is appended.
|
|
9
10
|
|
|
10
11
|
|
|
11
12
|
@author Daniel Jalkut, modified by Fletcher T. Penney and Dan Lowe
|
|
@@ -17,7 +18,7 @@
|
|
|
17
18
|
/*
|
|
18
19
|
|
|
19
20
|
Copyright © 2011 Daniel Jalkut.
|
|
20
|
-
Modifications by Fletcher T. Penney, Copyright © 2011-
|
|
21
|
+
Modifications by Fletcher T. Penney, Copyright © 2011-2020 Fletcher T. Penney.
|
|
21
22
|
Modifications by Dan Lowe, Copyright © 2011 Dan Lowe.
|
|
22
23
|
|
|
23
24
|
|
|
@@ -73,9 +74,9 @@
|
|
|
73
74
|
|
|
74
75
|
/// Structure for dynamic string
|
|
75
76
|
struct DString {
|
|
76
|
-
char * str;
|
|
77
|
-
unsigned long currentStringBufferSize;
|
|
78
|
-
unsigned long currentStringLength;
|
|
77
|
+
char * str; //!< Pointer to UTF-8 byte stream for string
|
|
78
|
+
unsigned long currentStringBufferSize; //!< Size of buffer currently allocated
|
|
79
|
+
unsigned long currentStringLength; //!< Size of current string
|
|
79
80
|
};
|
|
80
81
|
|
|
81
82
|
typedef struct DString DString;
|
|
@@ -83,93 +84,104 @@ typedef struct DString DString;
|
|
|
83
84
|
|
|
84
85
|
/// Create a new dynamic string
|
|
85
86
|
DString * d_string_new(
|
|
86
|
-
const char * startingString
|
|
87
|
+
const char * startingString //!< Initial contents for string
|
|
87
88
|
);
|
|
88
89
|
|
|
89
90
|
|
|
90
91
|
/// Free dynamic string
|
|
91
92
|
char * d_string_free(
|
|
92
|
-
DString * ripString,
|
|
93
|
-
bool freeCharacterData
|
|
93
|
+
DString * ripString, //!< DString to be freed
|
|
94
|
+
bool freeCharacterData //!< Should the underlying str be freed as well?
|
|
94
95
|
);
|
|
95
96
|
|
|
96
97
|
|
|
97
98
|
/// Append null-terminated string to end of dynamic string
|
|
98
99
|
void d_string_append(
|
|
99
|
-
DString * baseString,
|
|
100
|
-
const char * appendedString
|
|
100
|
+
DString * baseString, //!< DString to be appended
|
|
101
|
+
const char * appendedString //!< String to be appended
|
|
101
102
|
);
|
|
102
103
|
|
|
103
104
|
|
|
104
105
|
/// Append single character to end of dynamic string
|
|
105
106
|
void d_string_append_c(
|
|
106
|
-
DString * baseString,
|
|
107
|
-
char appendedCharacter
|
|
107
|
+
DString * baseString, //!< DString to be appended
|
|
108
|
+
char appendedCharacter //!< Character to append
|
|
108
109
|
);
|
|
109
110
|
|
|
110
111
|
|
|
111
112
|
/// Append array of characters to end of dynamic string
|
|
112
113
|
void d_string_append_c_array(
|
|
113
|
-
DString * baseString,
|
|
114
|
-
const char * appendedChars,
|
|
115
|
-
size_t bytes
|
|
114
|
+
DString * baseString, //!< DString to be appended
|
|
115
|
+
const char * appendedChars, //!< String to be appended
|
|
116
|
+
size_t bytes //!< Number of bytes to append
|
|
116
117
|
);
|
|
117
118
|
|
|
118
119
|
|
|
119
120
|
/// Append to end of dynamic string using format specifier
|
|
120
121
|
void d_string_append_printf(
|
|
121
|
-
DString * baseString,
|
|
122
|
-
const char * format,
|
|
123
|
-
...
|
|
122
|
+
DString * baseString, //!< DString to be appended
|
|
123
|
+
const char * format, //!< Format specifier for appending
|
|
124
|
+
... //!< Arguments for format specifier
|
|
124
125
|
);
|
|
125
126
|
|
|
126
127
|
|
|
127
128
|
/// Prepend null-terminated string to end of dynamic string
|
|
128
129
|
void d_string_prepend(
|
|
129
|
-
DString * baseString,
|
|
130
|
-
const char * prependedString
|
|
130
|
+
DString * baseString, //!< DString to be appended
|
|
131
|
+
const char * prependedString //!< String to be prepended
|
|
131
132
|
);
|
|
132
133
|
|
|
133
134
|
|
|
134
135
|
/// Insert null-terminated string inside dynamic string
|
|
135
136
|
void d_string_insert(
|
|
136
|
-
DString * baseString,
|
|
137
|
-
size_t pos,
|
|
138
|
-
const char * insertedString
|
|
137
|
+
DString * baseString, //!< DString to be appended
|
|
138
|
+
size_t pos, //!< Offset at which to insert string
|
|
139
|
+
const char * insertedString //!< String to be inserted
|
|
139
140
|
);
|
|
140
141
|
|
|
141
142
|
|
|
142
143
|
/// Insert single character inside dynamic string
|
|
143
144
|
void d_string_insert_c(
|
|
144
|
-
DString * baseString,
|
|
145
|
-
size_t pos,
|
|
146
|
-
char insertedCharacter
|
|
145
|
+
DString * baseString, //!< DString to be appended
|
|
146
|
+
size_t pos, //!< Offset at which to insert string
|
|
147
|
+
char insertedCharacter //!< Character to insert
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
/// Insert array of characters inside dynamic string
|
|
152
|
+
void d_string_insert_c_array(
|
|
153
|
+
DString * baseString, //!< DString to be appended
|
|
154
|
+
size_t pos, //!< Offset at which to insert string
|
|
155
|
+
const char * insertedString, //!< String to be inserted
|
|
156
|
+
size_t bytes //!< Number of bytes to insert
|
|
147
157
|
);
|
|
148
158
|
|
|
149
159
|
|
|
150
160
|
/// Insert inside dynamic string using format specifier
|
|
151
161
|
void d_string_insert_printf(
|
|
152
|
-
DString * baseString,
|
|
153
|
-
size_t pos,
|
|
154
|
-
const char * format,
|
|
155
|
-
...
|
|
162
|
+
DString * baseString, //!< DString to be appended
|
|
163
|
+
size_t pos, //!< Offset at which to insert string
|
|
164
|
+
const char * format, //!< Format specifier for appending
|
|
165
|
+
... //!< Arguments for format specifier
|
|
156
166
|
);
|
|
157
167
|
|
|
158
168
|
|
|
159
169
|
/// Erase portion of dynamic string
|
|
160
170
|
void d_string_erase(
|
|
161
|
-
DString * baseString,
|
|
162
|
-
size_t pos,
|
|
163
|
-
size_t len
|
|
171
|
+
DString * baseString, //!< DString to be appended
|
|
172
|
+
size_t pos, //!< Offset at which to erase portion of string
|
|
173
|
+
size_t len //!< Character to append
|
|
164
174
|
);
|
|
165
175
|
|
|
176
|
+
|
|
166
177
|
/// Copy a portion of dynamic string
|
|
167
178
|
char * d_string_copy_substring(
|
|
168
|
-
DString * d,
|
|
169
|
-
size_t start,
|
|
170
|
-
size_t len
|
|
179
|
+
DString * d, //!< DString to copy
|
|
180
|
+
size_t start, //!< Start position for copy
|
|
181
|
+
size_t len //!< How many characters(bytes) to copy
|
|
171
182
|
);
|
|
172
183
|
|
|
184
|
+
|
|
173
185
|
/// Replace occurences of "original" with "replace" inside the specified range
|
|
174
186
|
/// Returns the change in overall length
|
|
175
187
|
long d_string_replace_text_in_range(
|
data/ext/mmd/epub.c
CHANGED
|
@@ -58,6 +58,21 @@
|
|
|
58
58
|
#include <stdlib.h>
|
|
59
59
|
#include <sys/stat.h>
|
|
60
60
|
|
|
61
|
+
#ifdef __APPLE__
|
|
62
|
+
#include "TargetConditionals.h"
|
|
63
|
+
#if TARGET_IPHONE_SIMULATOR
|
|
64
|
+
// iOS Simulator
|
|
65
|
+
#undef USE_CURL
|
|
66
|
+
#elif TARGET_OS_IPHONE
|
|
67
|
+
// iOS device
|
|
68
|
+
#undef USE_CURL
|
|
69
|
+
#elif TARGET_OS_MAC
|
|
70
|
+
// Other kinds of Mac OS
|
|
71
|
+
#else
|
|
72
|
+
# error "Unknown Apple platform"
|
|
73
|
+
#endif
|
|
74
|
+
#endif
|
|
75
|
+
|
|
61
76
|
#ifdef USE_CURL
|
|
62
77
|
#include <curl/curl.h>
|
|
63
78
|
#endif
|
|
@@ -67,6 +82,7 @@
|
|
|
67
82
|
#include "html.h"
|
|
68
83
|
#include "i18n.h"
|
|
69
84
|
#include "miniz.h"
|
|
85
|
+
#include "stack.h"
|
|
70
86
|
#include "uuid.h"
|
|
71
87
|
#include "writer.h"
|
|
72
88
|
#include "zip.h"
|
|
@@ -133,7 +149,7 @@ char * epub_package_document(scratch_pad * scratch) {
|
|
|
133
149
|
|
|
134
150
|
if (m) {
|
|
135
151
|
print_const("<dc:identifier id=\"pub-id\">urn:uuid:");
|
|
136
|
-
mmd_print_string_html(out, m->value, false);
|
|
152
|
+
mmd_print_string_html(out, m->value, false, false);
|
|
137
153
|
print_const("</dc:identifier>\n");
|
|
138
154
|
} else {
|
|
139
155
|
print_const("<dc:identifier id=\"pub-id\">urn:uuid:");
|
|
@@ -149,7 +165,7 @@ char * epub_package_document(scratch_pad * scratch) {
|
|
|
149
165
|
|
|
150
166
|
if (m) {
|
|
151
167
|
print_const("<dc:title>");
|
|
152
|
-
mmd_print_string_html(out, m->value, false);
|
|
168
|
+
mmd_print_string_html(out, m->value, false, false);
|
|
153
169
|
print_const("</dc:title>\n");
|
|
154
170
|
} else {
|
|
155
171
|
print_const("<dc:title>Untitled</dc:title>\n");
|
|
@@ -160,7 +176,7 @@ char * epub_package_document(scratch_pad * scratch) {
|
|
|
160
176
|
|
|
161
177
|
if (m) {
|
|
162
178
|
print_const("<dc:creator>");
|
|
163
|
-
mmd_print_string_html(out, m->value, false);
|
|
179
|
+
mmd_print_string_html(out, m->value, false, false);
|
|
164
180
|
print_const("</dc:creator>\n");
|
|
165
181
|
}
|
|
166
182
|
|
|
@@ -170,7 +186,7 @@ char * epub_package_document(scratch_pad * scratch) {
|
|
|
170
186
|
|
|
171
187
|
if (m) {
|
|
172
188
|
print_const("<dc:language>");
|
|
173
|
-
mmd_print_string_html(out, m->value, false);
|
|
189
|
+
mmd_print_string_html(out, m->value, false, false);
|
|
174
190
|
print_const("</dc:language>\n");
|
|
175
191
|
} else {
|
|
176
192
|
switch (scratch->language) {
|
|
@@ -194,6 +210,10 @@ char * epub_package_document(scratch_pad * scratch) {
|
|
|
194
210
|
print_const("<dc:language>sv</dc:language>\n");
|
|
195
211
|
break;
|
|
196
212
|
|
|
213
|
+
case LC_HE:
|
|
214
|
+
print_const("<dc:language>he</dc:language>\n");
|
|
215
|
+
break;
|
|
216
|
+
|
|
197
217
|
default:
|
|
198
218
|
print_const("<dc:language>en</dc:language>\n");
|
|
199
219
|
}
|
|
@@ -204,7 +224,7 @@ char * epub_package_document(scratch_pad * scratch) {
|
|
|
204
224
|
|
|
205
225
|
if (m) {
|
|
206
226
|
print_const("<meta property=\"dcterms:modified\">");
|
|
207
|
-
mmd_print_string_html(out, m->value, false);
|
|
227
|
+
mmd_print_string_html(out, m->value, false, false);
|
|
208
228
|
print_const("</meta>\n");
|
|
209
229
|
} else {
|
|
210
230
|
time_t t = time(NULL);
|
|
@@ -251,7 +271,8 @@ void epub_export_nav_entry(DString * out, const char * source, scratch_pad * scr
|
|
|
251
271
|
|
|
252
272
|
if (entry_level >= level) {
|
|
253
273
|
// This entry is a direct descendant of the parent
|
|
254
|
-
|
|
274
|
+
scratch->label_counter = (int) * counter;
|
|
275
|
+
temp_char = label_from_header(source, entry, scratch);
|
|
255
276
|
printf("<li><a href=\"main.xhtml#%s\">", temp_char);
|
|
256
277
|
mmd_export_token_tree_html(out, source, entry->child, scratch);
|
|
257
278
|
print_const("</a>");
|
|
@@ -287,8 +308,11 @@ void epub_export_nav_entry(DString * out, const char * source, scratch_pad * scr
|
|
|
287
308
|
void epub_export_nav(DString * out, mmd_engine * e, scratch_pad * scratch) {
|
|
288
309
|
size_t counter = 0;
|
|
289
310
|
|
|
311
|
+
int old_label_counter = scratch->label_counter;
|
|
290
312
|
|
|
291
313
|
epub_export_nav_entry(out, e->dstr->str, scratch, &counter, 0);
|
|
314
|
+
|
|
315
|
+
scratch->label_counter = old_label_counter;
|
|
292
316
|
}
|
|
293
317
|
|
|
294
318
|
|
|
@@ -303,7 +327,7 @@ char * epub_nav(mmd_engine * e, scratch_pad * scratch) {
|
|
|
303
327
|
HASH_FIND_STR(scratch->meta_hash, "title", temp);
|
|
304
328
|
|
|
305
329
|
if (temp) {
|
|
306
|
-
mmd_print_string_html(out, temp->value, false);
|
|
330
|
+
mmd_print_string_html(out, temp->value, false, false);
|
|
307
331
|
} else {
|
|
308
332
|
print_const("Untitled");
|
|
309
333
|
}
|
|
@@ -452,7 +476,7 @@ static void add_assets(mz_zip_archive * pZip, mmd_engine * e, const char * direc
|
|
|
452
476
|
|
|
453
477
|
|
|
454
478
|
// Use the miniz library to create a zip archive for the EPUB document
|
|
455
|
-
void epub_write_wrapper(const char * filepath,
|
|
479
|
+
void epub_write_wrapper(const char * filepath, DString * body, mmd_engine * e, const char * directory) {
|
|
456
480
|
FILE * output_stream;
|
|
457
481
|
|
|
458
482
|
DString * result = epub_create(body, e, directory);
|
|
@@ -469,9 +493,10 @@ void epub_write_wrapper(const char * filepath, const char * body, mmd_engine * e
|
|
|
469
493
|
}
|
|
470
494
|
|
|
471
495
|
|
|
472
|
-
DString * epub_create(
|
|
496
|
+
DString * epub_create(DString * body, mmd_engine * e, const char * directory) {
|
|
473
497
|
DString * result = d_string_new("");
|
|
474
498
|
scratch_pad * scratch = scratch_pad_new(e, FORMAT_EPUB);
|
|
499
|
+
scratch->random_seed_base_labels = e->random_seed_base_labels;
|
|
475
500
|
|
|
476
501
|
mz_bool status;
|
|
477
502
|
char * data;
|
|
@@ -534,8 +559,7 @@ DString * epub_create(const char * body, mmd_engine * e, const char * directory)
|
|
|
534
559
|
}
|
|
535
560
|
|
|
536
561
|
// Add main document
|
|
537
|
-
|
|
538
|
-
status = mz_zip_writer_add_mem(&zip, "OEBPS/main.xhtml", body, len, MZ_BEST_COMPRESSION);
|
|
562
|
+
status = mz_zip_writer_add_mem(&zip, "OEBPS/main.xhtml", body->str, body->currentStringLength, MZ_BEST_COMPRESSION);
|
|
539
563
|
|
|
540
564
|
if (!status) {
|
|
541
565
|
fprintf(stderr, "Error adding asset to zip.\n");
|
|
@@ -552,7 +576,7 @@ DString * epub_create(const char * body, mmd_engine * e, const char * directory)
|
|
|
552
576
|
status = mz_zip_writer_finalize_heap_archive(&zip, (void **) & (result->str), (size_t *) & (result->currentStringLength));
|
|
553
577
|
|
|
554
578
|
if (!status) {
|
|
555
|
-
fprintf(stderr, "Error
|
|
579
|
+
fprintf(stderr, "Error finalizing zip archive.\n");
|
|
556
580
|
}
|
|
557
581
|
|
|
558
582
|
return result;
|
data/ext/mmd/epub.h
CHANGED
|
@@ -61,9 +61,9 @@
|
|
|
61
61
|
#include "d_string.h"
|
|
62
62
|
#include "mmd.h"
|
|
63
63
|
|
|
64
|
-
void epub_write_wrapper(const char * root_path,
|
|
64
|
+
void epub_write_wrapper(const char * root_path, DString * body, mmd_engine * e, const char * directory);
|
|
65
65
|
|
|
66
|
-
DString * epub_create(
|
|
66
|
+
DString * epub_create(DString * body, mmd_engine * e, const char * directory);
|
|
67
67
|
|
|
68
68
|
|
|
69
69
|
#endif
|