commonmarker 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of commonmarker might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/ext/commonmarker/cmark/CMakeLists.txt +10 -4
- data/ext/commonmarker/cmark/Makefile +5 -5
- data/ext/commonmarker/cmark/api_test/CMakeLists.txt +1 -1
- data/ext/commonmarker/cmark/api_test/main.c +16 -0
- data/ext/commonmarker/cmark/build/CMakeCache.txt +3 -4
- data/ext/commonmarker/cmark/build/CMakeFiles/2.8.10.1/CMakeSystem.cmake +4 -4
- data/ext/commonmarker/cmark/build/CMakeFiles/CMakeError.log +12 -12
- data/ext/commonmarker/cmark/build/CMakeFiles/CMakeOutput.log +97 -142
- data/ext/commonmarker/cmark/build/CMakeFiles/Makefile.cmake +0 -1
- data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/build.make +1 -1
- data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/link.txt +1 -1
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/DependInfo.cmake +1 -1
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/build.make +23 -23
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/cmake_clean.cmake +2 -2
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/link.txt +1 -1
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/blocks.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/buffer.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/cmark.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/commonmark.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/houdini_html_u.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/html.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/inlines.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/node.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/references.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/render.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/scanners.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/utf8.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/xml.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/cmake_install.cmake +3 -3
- data/ext/commonmarker/cmark/build/src/cmark_version.h +2 -2
- data/ext/commonmarker/cmark/build/src/config.h +6 -6
- data/ext/commonmarker/cmark/build/src/libcmark.a +0 -0
- data/ext/commonmarker/cmark/build/src/libcmark.pc +1 -1
- data/ext/commonmarker/cmark/build/testdir/CTestTestfile.cmake +4 -4
- data/ext/commonmarker/cmark/changelog.txt +46 -0
- data/ext/commonmarker/cmark/man/man3/cmark.3 +21 -20
- data/ext/commonmarker/cmark/src/CMakeLists.txt +4 -6
- data/ext/commonmarker/cmark/src/bench.h +8 -8
- data/ext/commonmarker/cmark/src/blocks.c +917 -947
- data/ext/commonmarker/cmark/src/buffer.c +213 -288
- data/ext/commonmarker/cmark/src/buffer.h +19 -21
- data/ext/commonmarker/cmark/src/chunk.h +78 -82
- data/ext/commonmarker/cmark/src/cmark.c +9 -17
- data/ext/commonmarker/cmark/src/cmark.h +113 -157
- data/ext/commonmarker/cmark/src/cmark_ctype.c +24 -35
- data/ext/commonmarker/cmark/src/commonmark.c +390 -425
- data/ext/commonmarker/cmark/src/config.h.in +6 -6
- data/ext/commonmarker/cmark/src/houdini.h +21 -15
- data/ext/commonmarker/cmark/src/houdini_href_e.c +50 -57
- data/ext/commonmarker/cmark/src/houdini_html_e.c +36 -51
- data/ext/commonmarker/cmark/src/houdini_html_u.c +119 -124
- data/ext/commonmarker/cmark/src/html.c +289 -307
- data/ext/commonmarker/cmark/src/inlines.c +976 -1030
- data/ext/commonmarker/cmark/src/inlines.h +4 -2
- data/ext/commonmarker/cmark/src/iterator.c +96 -126
- data/ext/commonmarker/cmark/src/iterator.h +5 -5
- data/ext/commonmarker/cmark/src/latex.c +379 -401
- data/ext/commonmarker/cmark/src/main.c +168 -175
- data/ext/commonmarker/cmark/src/man.c +212 -226
- data/ext/commonmarker/cmark/src/node.c +746 -839
- data/ext/commonmarker/cmark/src/node.h +47 -48
- data/ext/commonmarker/cmark/src/parser.h +14 -14
- data/ext/commonmarker/cmark/src/references.c +101 -111
- data/ext/commonmarker/cmark/src/references.h +10 -8
- data/ext/commonmarker/cmark/src/render.c +144 -167
- data/ext/commonmarker/cmark/src/render.h +22 -41
- data/ext/commonmarker/cmark/src/scanners.c +27695 -20903
- data/ext/commonmarker/cmark/src/scanners.h +2 -1
- data/ext/commonmarker/cmark/src/scanners.re +1 -1
- data/ext/commonmarker/cmark/src/utf8.c +276 -419
- data/ext/commonmarker/cmark/src/utf8.h +6 -6
- data/ext/commonmarker/cmark/src/xml.c +129 -144
- data/ext/commonmarker/cmark/test/CMakeLists.txt +4 -4
- data/ext/commonmarker/cmark/test/smart_punct.txt +8 -0
- data/ext/commonmarker/cmark/test/spec.txt +109 -47
- data/lib/commonmarker/version.rb +1 -1
- metadata +2 -2
@@ -12,190 +12,183 @@
|
|
12
12
|
#endif
|
13
13
|
|
14
14
|
typedef enum {
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
15
|
+
FORMAT_NONE,
|
16
|
+
FORMAT_HTML,
|
17
|
+
FORMAT_XML,
|
18
|
+
FORMAT_MAN,
|
19
|
+
FORMAT_COMMONMARK,
|
20
|
+
FORMAT_LATEX
|
21
21
|
} writer_format;
|
22
22
|
|
23
|
-
void print_usage()
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
23
|
+
void print_usage() {
|
24
|
+
printf("Usage: cmark [FILE*]\n");
|
25
|
+
printf("Options:\n");
|
26
|
+
printf(" --to, -t FORMAT Specify output format (html, xml, man, "
|
27
|
+
"commonmark, latex)\n");
|
28
|
+
printf(" --width WIDTH Specify wrap width (default 0 = nowrap)\n");
|
29
|
+
printf(" --sourcepos Include source position attribute\n");
|
30
|
+
printf(" --hardbreaks Treat newlines as hard line breaks\n");
|
31
|
+
printf(" --safe Suppress raw HTML and dangerous URLs\n");
|
32
|
+
printf(" --smart Use smart punctuation\n");
|
33
|
+
printf(" --normalize Consolidate adjacent text nodes\n");
|
34
|
+
printf(" --help, -h Print usage information\n");
|
35
|
+
printf(" --version Print version\n");
|
36
36
|
}
|
37
37
|
|
38
38
|
static void print_document(cmark_node *document, writer_format writer,
|
39
|
-
int options, int width)
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
free(result);
|
39
|
+
int options, int width) {
|
40
|
+
char *result;
|
41
|
+
|
42
|
+
switch (writer) {
|
43
|
+
case FORMAT_HTML:
|
44
|
+
result = cmark_render_html(document, options);
|
45
|
+
break;
|
46
|
+
case FORMAT_XML:
|
47
|
+
result = cmark_render_xml(document, options);
|
48
|
+
break;
|
49
|
+
case FORMAT_MAN:
|
50
|
+
result = cmark_render_man(document, options, width);
|
51
|
+
break;
|
52
|
+
case FORMAT_COMMONMARK:
|
53
|
+
result = cmark_render_commonmark(document, options, width);
|
54
|
+
break;
|
55
|
+
case FORMAT_LATEX:
|
56
|
+
result = cmark_render_latex(document, options, width);
|
57
|
+
break;
|
58
|
+
default:
|
59
|
+
fprintf(stderr, "Unknown format %d\n", writer);
|
60
|
+
exit(1);
|
61
|
+
}
|
62
|
+
printf("%s", result);
|
63
|
+
free(result);
|
65
64
|
}
|
66
65
|
|
67
|
-
int main(int argc, char *argv[])
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
int options = CMARK_OPT_DEFAULT;
|
66
|
+
int main(int argc, char *argv[]) {
|
67
|
+
int i, numfps = 0;
|
68
|
+
int *files;
|
69
|
+
char buffer[4096];
|
70
|
+
cmark_parser *parser;
|
71
|
+
size_t bytes;
|
72
|
+
cmark_node *document;
|
73
|
+
int width = 0;
|
74
|
+
char *unparsed;
|
75
|
+
writer_format writer = FORMAT_HTML;
|
76
|
+
int options = CMARK_OPT_DEFAULT;
|
79
77
|
|
80
78
|
#if defined(_WIN32) && !defined(__CYGWIN__)
|
81
|
-
|
79
|
+
_setmode(_fileno(stdout), _O_BINARY);
|
82
80
|
#endif
|
83
81
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
end_timer("free_blocks");
|
197
|
-
|
198
|
-
free(files);
|
199
|
-
|
200
|
-
return 0;
|
82
|
+
files = (int *)malloc(argc * sizeof(*files));
|
83
|
+
|
84
|
+
for (i = 1; i < argc; i++) {
|
85
|
+
if (strcmp(argv[i], "--version") == 0) {
|
86
|
+
printf("cmark %s", CMARK_VERSION_STRING);
|
87
|
+
printf(" - CommonMark converter\n(C) 2014, 2015 John MacFarlane\n");
|
88
|
+
exit(0);
|
89
|
+
} else if (strcmp(argv[i], "--sourcepos") == 0) {
|
90
|
+
options |= CMARK_OPT_SOURCEPOS;
|
91
|
+
} else if (strcmp(argv[i], "--hardbreaks") == 0) {
|
92
|
+
options |= CMARK_OPT_HARDBREAKS;
|
93
|
+
} else if (strcmp(argv[i], "--smart") == 0) {
|
94
|
+
options |= CMARK_OPT_SMART;
|
95
|
+
} else if (strcmp(argv[i], "--safe") == 0) {
|
96
|
+
options |= CMARK_OPT_SAFE;
|
97
|
+
} else if (strcmp(argv[i], "--normalize") == 0) {
|
98
|
+
options |= CMARK_OPT_NORMALIZE;
|
99
|
+
} else if (strcmp(argv[i], "--validate-utf8") == 0) {
|
100
|
+
options |= CMARK_OPT_VALIDATE_UTF8;
|
101
|
+
} else if ((strcmp(argv[i], "--help") == 0) ||
|
102
|
+
(strcmp(argv[i], "-h") == 0)) {
|
103
|
+
print_usage();
|
104
|
+
exit(0);
|
105
|
+
} else if (strcmp(argv[i], "--width") == 0) {
|
106
|
+
i += 1;
|
107
|
+
if (i < argc) {
|
108
|
+
width = (int)strtol(argv[i], &unparsed, 10);
|
109
|
+
if (unparsed && strlen(unparsed) > 0) {
|
110
|
+
fprintf(stderr, "failed parsing width '%s' at '%s'\n", argv[i],
|
111
|
+
unparsed);
|
112
|
+
exit(1);
|
113
|
+
}
|
114
|
+
} else {
|
115
|
+
fprintf(stderr, "--width requires an argument\n");
|
116
|
+
exit(1);
|
117
|
+
}
|
118
|
+
} else if ((strcmp(argv[i], "-t") == 0) || (strcmp(argv[i], "--to") == 0)) {
|
119
|
+
i += 1;
|
120
|
+
if (i < argc) {
|
121
|
+
if (strcmp(argv[i], "man") == 0) {
|
122
|
+
writer = FORMAT_MAN;
|
123
|
+
} else if (strcmp(argv[i], "html") == 0) {
|
124
|
+
writer = FORMAT_HTML;
|
125
|
+
} else if (strcmp(argv[i], "xml") == 0) {
|
126
|
+
writer = FORMAT_XML;
|
127
|
+
} else if (strcmp(argv[i], "commonmark") == 0) {
|
128
|
+
writer = FORMAT_COMMONMARK;
|
129
|
+
} else if (strcmp(argv[i], "latex") == 0) {
|
130
|
+
writer = FORMAT_LATEX;
|
131
|
+
} else {
|
132
|
+
fprintf(stderr, "Unknown format %s\n", argv[i]);
|
133
|
+
exit(1);
|
134
|
+
}
|
135
|
+
} else {
|
136
|
+
fprintf(stderr, "No argument provided for %s\n", argv[i - 1]);
|
137
|
+
exit(1);
|
138
|
+
}
|
139
|
+
} else if (*argv[i] == '-') {
|
140
|
+
print_usage();
|
141
|
+
exit(1);
|
142
|
+
} else { // treat as file argument
|
143
|
+
files[numfps++] = i;
|
144
|
+
}
|
145
|
+
}
|
146
|
+
|
147
|
+
parser = cmark_parser_new(options);
|
148
|
+
for (i = 0; i < numfps; i++) {
|
149
|
+
FILE *fp = fopen(argv[files[i]], "r");
|
150
|
+
if (fp == NULL) {
|
151
|
+
fprintf(stderr, "Error opening file %s: %s\n", argv[files[i]],
|
152
|
+
strerror(errno));
|
153
|
+
exit(1);
|
154
|
+
}
|
155
|
+
|
156
|
+
start_timer();
|
157
|
+
while ((bytes = fread(buffer, 1, sizeof(buffer), fp)) > 0) {
|
158
|
+
cmark_parser_feed(parser, buffer, bytes);
|
159
|
+
if (bytes < sizeof(buffer)) {
|
160
|
+
break;
|
161
|
+
}
|
162
|
+
}
|
163
|
+
end_timer("processing lines");
|
164
|
+
|
165
|
+
fclose(fp);
|
166
|
+
}
|
167
|
+
|
168
|
+
if (numfps == 0) {
|
169
|
+
|
170
|
+
while ((bytes = fread(buffer, 1, sizeof(buffer), stdin)) > 0) {
|
171
|
+
cmark_parser_feed(parser, buffer, bytes);
|
172
|
+
if (bytes < sizeof(buffer)) {
|
173
|
+
break;
|
174
|
+
}
|
175
|
+
}
|
176
|
+
}
|
177
|
+
|
178
|
+
start_timer();
|
179
|
+
document = cmark_parser_finish(parser);
|
180
|
+
end_timer("finishing document");
|
181
|
+
cmark_parser_free(parser);
|
182
|
+
|
183
|
+
start_timer();
|
184
|
+
print_document(document, writer, options, width);
|
185
|
+
end_timer("print_document");
|
186
|
+
|
187
|
+
start_timer();
|
188
|
+
cmark_node_free(document);
|
189
|
+
end_timer("free_blocks");
|
190
|
+
|
191
|
+
free(files);
|
192
|
+
|
193
|
+
return 0;
|
201
194
|
}
|