commonmarker 0.14.14 → 0.15.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 +4 -4
- data/README.md +1 -1
- data/commonmarker.gemspec +2 -0
- data/ext/commonmarker/cmark/Makefile +13 -8
- data/ext/commonmarker/cmark/README.md +18 -11
- data/ext/commonmarker/cmark/api_test/CMakeLists.txt +1 -1
- data/ext/commonmarker/cmark/extensions/CMakeLists.txt +7 -7
- data/ext/commonmarker/cmark/extensions/ext_scanners.c +562 -3
- data/ext/commonmarker/cmark/extensions/ext_scanners.h +6 -0
- data/ext/commonmarker/cmark/extensions/ext_scanners.re +32 -0
- data/ext/commonmarker/cmark/extensions/table.c +87 -215
- data/ext/commonmarker/cmark/man/CMakeLists.txt +2 -2
- data/ext/commonmarker/cmark/man/make_man_page.py +3 -3
- data/ext/commonmarker/cmark/man/man1/{cmark.1 → cmark-gfm.1} +10 -4
- data/ext/commonmarker/cmark/man/man3/{cmark.3 → cmark-gfm.3} +2 -2
- data/ext/commonmarker/cmark/src/CMakeLists.txt +15 -15
- data/ext/commonmarker/cmark/src/buffer.c +5 -1
- data/ext/commonmarker/cmark/src/cmark.c +6 -2
- data/ext/commonmarker/cmark/src/cmark.h +1 -1
- data/ext/commonmarker/cmark/src/cmark_extension_api.h +0 -2
- data/ext/commonmarker/cmark/src/commonmark.c +1 -2
- data/ext/commonmarker/cmark/src/inlines.c +1 -1
- data/ext/commonmarker/cmark/src/libcmark-gfm.pc.in +10 -0
- data/ext/commonmarker/cmark/src/main.c +2 -2
- data/ext/commonmarker/cmark/src/render.c +15 -0
- data/ext/commonmarker/cmark/test/CMakeLists.txt +5 -5
- data/ext/commonmarker/cmark/test/cmark.py +2 -2
- data/ext/commonmarker/cmark/test/extensions.txt +24 -3
- data/ext/commonmarker/cmark/test/roundtrip_tests.py +1 -0
- data/ext/commonmarker/cmark/test/spec.txt +84 -15
- data/ext/commonmarker/cmark/test/spec_tests.py +9 -8
- data/ext/commonmarker/cmark/tools/Dockerfile +36 -0
- data/ext/commonmarker/extconf.rb +5 -5
- data/lib/commonmarker/node/inspect.rb +59 -0
- data/lib/commonmarker/node.rb +3 -0
- data/lib/commonmarker/version.rb +1 -1
- data/test/test_node.rb +8 -0
- data/test/test_spec.rb +1 -1
- metadata +10 -6
- data/ext/commonmarker/cmark/src/libcmark.pc.in +0 -10
|
@@ -24,12 +24,11 @@ typedef struct {
|
|
|
24
24
|
|
|
25
25
|
typedef struct {
|
|
26
26
|
bool is_header;
|
|
27
|
-
unsigned char *raw_content;
|
|
28
|
-
size_t raw_content_len;
|
|
29
27
|
} node_table_row;
|
|
30
28
|
|
|
31
29
|
static void free_table_cell(cmark_mem *mem, void *data) {
|
|
32
|
-
|
|
30
|
+
cmark_strbuf_free((cmark_strbuf *)data);
|
|
31
|
+
mem->free(data);
|
|
33
32
|
}
|
|
34
33
|
|
|
35
34
|
static void free_table_row(cmark_mem *mem, table_row *row) {
|
|
@@ -48,9 +47,7 @@ static void free_node_table(cmark_mem *mem, void *ptr) {
|
|
|
48
47
|
}
|
|
49
48
|
|
|
50
49
|
static void free_node_table_row(cmark_mem *mem, void *ptr) {
|
|
51
|
-
|
|
52
|
-
mem->free(ntr->raw_content);
|
|
53
|
-
mem->free(ntr);
|
|
50
|
+
mem->free(ptr);
|
|
54
51
|
}
|
|
55
52
|
|
|
56
53
|
static int get_n_table_columns(cmark_node *node) {
|
|
@@ -83,159 +80,64 @@ static int set_table_alignments(cmark_node *node, uint8_t *alignments) {
|
|
|
83
80
|
return 1;
|
|
84
81
|
}
|
|
85
82
|
|
|
86
|
-
static
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
static int find_unescaped_pipe(const cmark_chunk *chunk, int offset) {
|
|
93
|
-
bool escaping = false;
|
|
94
|
-
for (; offset < chunk->len; ++offset) {
|
|
95
|
-
if (escaping)
|
|
96
|
-
escaping = false;
|
|
97
|
-
else if (chunk->data[offset] == '\\')
|
|
98
|
-
escaping = true;
|
|
99
|
-
else if (chunk->data[offset] == '|')
|
|
100
|
-
return offset;
|
|
101
|
-
}
|
|
102
|
-
return -1;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
static cmark_node *consume_until_pipe_or_eol(cmark_syntax_extension *self,
|
|
106
|
-
cmark_parser *parser,
|
|
107
|
-
cmark_node **n, int *offset) {
|
|
108
|
-
cmark_node *result =
|
|
109
|
-
cmark_node_new_with_mem(CMARK_NODE_TABLE_CELL, parser->mem);
|
|
110
|
-
cmark_node_set_syntax_extension(result, self);
|
|
111
|
-
bool was_escape = false;
|
|
112
|
-
|
|
113
|
-
while (*n) {
|
|
114
|
-
cmark_node *node = *n;
|
|
115
|
-
|
|
116
|
-
if (node->type == CMARK_NODE_TEXT) {
|
|
117
|
-
cmark_node *child = cmark_parser_add_child(
|
|
118
|
-
parser, result, CMARK_NODE_TEXT, cmark_parser_get_offset(parser));
|
|
119
|
-
|
|
120
|
-
if (was_escape) {
|
|
121
|
-
child->as.literal = cmark_chunk_dup(&node->as.literal, *offset, 1);
|
|
122
|
-
cmark_node_own(child);
|
|
123
|
-
if (child->as.literal.data[0] == '|')
|
|
124
|
-
cmark_node_free(child->prev);
|
|
125
|
-
++*offset;
|
|
126
|
-
if (*offset >= node->as.literal.len) {
|
|
127
|
-
*offset = 0;
|
|
128
|
-
*n = node->next;
|
|
129
|
-
}
|
|
130
|
-
was_escape = false;
|
|
131
|
-
continue;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
const char *lit = (char *)node->as.literal.data + *offset;
|
|
135
|
-
const int lit_len = node->as.literal.len - *offset;
|
|
136
|
-
|
|
137
|
-
if (lit_len == 1 && lit[0] == '\\' &&
|
|
138
|
-
node->next &&
|
|
139
|
-
node->next->type == CMARK_NODE_TEXT) {
|
|
140
|
-
child->as.literal = cmark_chunk_dup(&node->as.literal, *offset, 1);
|
|
141
|
-
cmark_node_own(child);
|
|
142
|
-
was_escape = true;
|
|
143
|
-
*n = node->next;
|
|
144
|
-
continue;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
int pipe = find_unescaped_pipe(&node->as.literal, *offset);
|
|
148
|
-
if (pipe == -1) {
|
|
149
|
-
child->as.literal = cmark_chunk_dup(&node->as.literal, *offset,
|
|
150
|
-
node->as.literal.len - *offset);
|
|
151
|
-
cmark_node_own(child);
|
|
152
|
-
} else {
|
|
153
|
-
pipe -= *offset;
|
|
154
|
-
|
|
155
|
-
child->as.literal = cmark_chunk_dup(&node->as.literal, *offset, pipe);
|
|
156
|
-
cmark_node_own(child);
|
|
157
|
-
|
|
158
|
-
*offset += pipe + 1;
|
|
159
|
-
if (*offset >= node->as.literal.len) {
|
|
160
|
-
*offset = 0;
|
|
161
|
-
*n = node->next;
|
|
162
|
-
}
|
|
163
|
-
break;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
*n = node->next;
|
|
167
|
-
*offset = 0;
|
|
168
|
-
} else {
|
|
169
|
-
cmark_node *next = node->next;
|
|
170
|
-
cmark_node_append_child(result, node);
|
|
171
|
-
cmark_node_own(node);
|
|
172
|
-
*n = next;
|
|
173
|
-
*offset = 0;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
83
|
+
static cmark_strbuf *unescape_pipes(cmark_mem *mem, unsigned char *string, bufsize_t len)
|
|
84
|
+
{
|
|
85
|
+
cmark_strbuf *res = (cmark_strbuf *)mem->calloc(1, sizeof(cmark_strbuf));
|
|
86
|
+
bufsize_t r, w;
|
|
176
87
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
}
|
|
88
|
+
cmark_strbuf_init(mem, res, len + 1);
|
|
89
|
+
cmark_strbuf_put(res, string, len);
|
|
90
|
+
cmark_strbuf_putc(res, '\0');
|
|
181
91
|
|
|
182
|
-
|
|
92
|
+
for (r = 0, w = 0; r < len; ++r) {
|
|
93
|
+
if (res->ptr[r] == '\\' && res->ptr[r + 1] == '|')
|
|
94
|
+
r++;
|
|
183
95
|
|
|
184
|
-
|
|
185
|
-
cmark_chunk c = cmark_chunk_ltrim_new(parser->mem, &result->first_child->as.literal);
|
|
186
|
-
cmark_chunk_free(parser->mem, &result->first_child->as.literal);
|
|
187
|
-
result->first_child->as.literal = c;
|
|
96
|
+
res->ptr[w++] = res->ptr[r];
|
|
188
97
|
}
|
|
189
98
|
|
|
190
|
-
|
|
191
|
-
cmark_chunk c = cmark_chunk_rtrim_new(parser->mem, &result->last_child->as.literal);
|
|
192
|
-
cmark_chunk_free(parser->mem, &result->last_child->as.literal);
|
|
193
|
-
result->last_child->as.literal = c;
|
|
194
|
-
}
|
|
99
|
+
cmark_strbuf_truncate(res, w);
|
|
195
100
|
|
|
196
|
-
return
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
static int table_ispunct(char c) {
|
|
200
|
-
return cmark_ispunct(c) && c != '|';
|
|
101
|
+
return res;
|
|
201
102
|
}
|
|
202
103
|
|
|
203
104
|
static table_row *row_from_string(cmark_syntax_extension *self,
|
|
204
105
|
cmark_parser *parser, unsigned char *string,
|
|
205
106
|
int len) {
|
|
206
107
|
table_row *row = NULL;
|
|
207
|
-
|
|
208
|
-
cmark_node *temp_container =
|
|
209
|
-
cmark_node_new_with_mem(CMARK_NODE_PARAGRAPH, parser->mem);
|
|
210
|
-
cmark_strbuf_set(&temp_container->content, string, len);
|
|
211
|
-
|
|
212
|
-
cmark_manage_extensions_special_characters(parser, true);
|
|
213
|
-
cmark_parser_set_backslash_ispunct_func(parser, table_ispunct);
|
|
214
|
-
cmark_parse_inlines(parser, temp_container, parser->refmap, parser->options);
|
|
215
|
-
cmark_parser_set_backslash_ispunct_func(parser, NULL);
|
|
216
|
-
cmark_manage_extensions_special_characters(parser, false);
|
|
217
|
-
|
|
218
|
-
if (!temp_container->first_child) {
|
|
219
|
-
cmark_node_free(temp_container);
|
|
220
|
-
return NULL;
|
|
221
|
-
}
|
|
108
|
+
bufsize_t cell_matched, pipe_matched, offset = 0;
|
|
222
109
|
|
|
223
110
|
row = (table_row *)parser->mem->calloc(1, sizeof(table_row));
|
|
224
111
|
row->n_columns = 0;
|
|
225
112
|
row->cells = NULL;
|
|
226
113
|
|
|
227
|
-
|
|
228
|
-
|
|
114
|
+
if (len > 0 && string[0] == '|')
|
|
115
|
+
++offset;
|
|
229
116
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
117
|
+
do {
|
|
118
|
+
cell_matched = scan_table_cell(string, len, offset);
|
|
119
|
+
pipe_matched = scan_table_cell_end(string, len, offset + cell_matched);
|
|
120
|
+
|
|
121
|
+
if (cell_matched || pipe_matched) {
|
|
122
|
+
cmark_strbuf *cell_buf = unescape_pipes(parser->mem, string + offset,
|
|
123
|
+
cell_matched);
|
|
124
|
+
cmark_strbuf_trim(cell_buf);
|
|
125
|
+
row->n_columns += 1;
|
|
126
|
+
row->cells = cmark_llist_append(parser->mem, row->cells, cell_buf);
|
|
127
|
+
}
|
|
237
128
|
|
|
238
|
-
|
|
129
|
+
offset += cell_matched + pipe_matched;
|
|
130
|
+
|
|
131
|
+
if (!pipe_matched) {
|
|
132
|
+
pipe_matched = scan_table_row_end(string, len, offset);
|
|
133
|
+
offset += pipe_matched;
|
|
134
|
+
}
|
|
135
|
+
} while ((cell_matched || pipe_matched) && offset < len);
|
|
136
|
+
|
|
137
|
+
if (offset != len || !row->n_columns) {
|
|
138
|
+
free_table_row(parser->mem, row);
|
|
139
|
+
row = NULL;
|
|
140
|
+
}
|
|
239
141
|
|
|
240
142
|
return row;
|
|
241
143
|
}
|
|
@@ -300,25 +202,15 @@ static cmark_node *try_opening_table_header(cmark_syntax_extension *self,
|
|
|
300
202
|
|
|
301
203
|
parent_container->as.opaque = parser->mem->calloc(1, sizeof(node_table));
|
|
302
204
|
|
|
205
|
+
|
|
303
206
|
set_n_table_columns(parent_container, header_row->n_columns);
|
|
304
207
|
|
|
305
208
|
uint8_t *alignments =
|
|
306
209
|
(uint8_t *)parser->mem->calloc(header_row->n_columns, sizeof(uint8_t));
|
|
307
210
|
cmark_llist *it = marker_row->cells;
|
|
308
211
|
for (i = 0; it; it = it->next, ++i) {
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
cmark_strbuf strbuf;
|
|
313
|
-
cmark_strbuf_init(parser->mem, &strbuf, 0);
|
|
314
|
-
assert(node->first_child->type == CMARK_NODE_TEXT);
|
|
315
|
-
assert(node->first_child == node->last_child);
|
|
316
|
-
cmark_strbuf_put(&strbuf, node->first_child->as.literal.data, node->first_child->as.literal.len);
|
|
317
|
-
cmark_strbuf_trim(&strbuf);
|
|
318
|
-
char const *text = cmark_strbuf_cstr(&strbuf);
|
|
319
|
-
|
|
320
|
-
bool left = text[0] == ':', right = text[strbuf.size - 1] == ':';
|
|
321
|
-
cmark_strbuf_free(&strbuf);
|
|
212
|
+
cmark_strbuf *node = (cmark_strbuf *)it->data;
|
|
213
|
+
bool left = node->ptr[0] == ':', right = node->ptr[node->size - 1] == ':';
|
|
322
214
|
|
|
323
215
|
if (left && right)
|
|
324
216
|
alignments[i] = 'c';
|
|
@@ -336,9 +228,18 @@ static cmark_node *try_opening_table_header(cmark_syntax_extension *self,
|
|
|
336
228
|
|
|
337
229
|
table_header->as.opaque = ntr = (node_table_row *)parser->mem->calloc(1, sizeof(node_table_row));
|
|
338
230
|
ntr->is_header = true;
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
231
|
+
|
|
232
|
+
{
|
|
233
|
+
cmark_llist *tmp;
|
|
234
|
+
|
|
235
|
+
for (tmp = header_row->cells; tmp; tmp = tmp->next) {
|
|
236
|
+
cmark_strbuf *cell_buf = (cmark_strbuf *) tmp->data;
|
|
237
|
+
cmark_node *header_cell = cmark_parser_add_child(parser, table_header,
|
|
238
|
+
CMARK_NODE_TABLE_CELL, cmark_parser_get_offset(parser));
|
|
239
|
+
cmark_node_set_string_content(header_cell, (char *) cell_buf->ptr);
|
|
240
|
+
cmark_node_set_syntax_extension(header_cell, self);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
342
243
|
|
|
343
244
|
cmark_parser_advance_offset(
|
|
344
245
|
parser, (char *)input,
|
|
@@ -354,7 +255,7 @@ static cmark_node *try_opening_table_row(cmark_syntax_extension *self,
|
|
|
354
255
|
cmark_node *parent_container,
|
|
355
256
|
unsigned char *input, int len) {
|
|
356
257
|
cmark_node *table_row_block;
|
|
357
|
-
|
|
258
|
+
table_row *row;
|
|
358
259
|
|
|
359
260
|
if (cmark_parser_is_blank(parser))
|
|
360
261
|
return NULL;
|
|
@@ -364,11 +265,31 @@ static cmark_node *try_opening_table_row(cmark_syntax_extension *self,
|
|
|
364
265
|
cmark_parser_get_offset(parser));
|
|
365
266
|
|
|
366
267
|
cmark_node_set_syntax_extension(table_row_block, self);
|
|
367
|
-
table_row_block->as.opaque =
|
|
268
|
+
table_row_block->as.opaque = parser->mem->calloc(1, sizeof(node_table_row));
|
|
269
|
+
|
|
270
|
+
row = row_from_string(self, parser, input + cmark_parser_get_first_nonspace(parser),
|
|
271
|
+
len - cmark_parser_get_first_nonspace(parser));
|
|
368
272
|
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
273
|
+
{
|
|
274
|
+
cmark_llist *tmp;
|
|
275
|
+
int i, table_columns = get_n_table_columns(parent_container);
|
|
276
|
+
|
|
277
|
+
for (tmp = row->cells, i = 0; tmp && i < table_columns; tmp = tmp->next, ++i) {
|
|
278
|
+
cmark_strbuf *cell_buf = (cmark_strbuf *) tmp->data;
|
|
279
|
+
cmark_node *cell = cmark_parser_add_child(parser, table_row_block,
|
|
280
|
+
CMARK_NODE_TABLE_CELL, cmark_parser_get_offset(parser));
|
|
281
|
+
cmark_node_set_string_content(cell, (char *) cell_buf->ptr);
|
|
282
|
+
cmark_node_set_syntax_extension(cell, self);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
for (; i < table_columns; ++i) {
|
|
286
|
+
cmark_node *cell = cmark_parser_add_child(
|
|
287
|
+
parser, table_row_block, CMARK_NODE_TABLE_CELL, cmark_parser_get_offset(parser));
|
|
288
|
+
cmark_node_set_syntax_extension(cell, self);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
free_table_row(parser->mem, row);
|
|
372
293
|
|
|
373
294
|
cmark_parser_advance_offset(parser, (char *)input,
|
|
374
295
|
len - 1 - cmark_parser_get_offset(parser), false);
|
|
@@ -695,59 +616,11 @@ static void opaque_free(cmark_syntax_extension *self, cmark_mem *mem, cmark_node
|
|
|
695
616
|
}
|
|
696
617
|
|
|
697
618
|
static int escape(cmark_syntax_extension *self, cmark_node *node, int c) {
|
|
698
|
-
return
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
cmark_event_type ev;
|
|
704
|
-
cmark_node *node;
|
|
705
|
-
node_table_row *ntr;
|
|
706
|
-
table_row *row;
|
|
707
|
-
|
|
708
|
-
iter = cmark_iter_new(root);
|
|
709
|
-
|
|
710
|
-
while ((ev = cmark_iter_next(iter)) != CMARK_EVENT_DONE) {
|
|
711
|
-
node = cmark_iter_get_node(iter);
|
|
712
|
-
if (ev == CMARK_EVENT_EXIT && node->type == CMARK_NODE_TABLE_ROW) {
|
|
713
|
-
ntr = (node_table_row *)node->as.opaque;
|
|
714
|
-
if (!ntr->raw_content)
|
|
715
|
-
continue;
|
|
716
|
-
row = row_from_string(self, parser,
|
|
717
|
-
ntr->raw_content,
|
|
718
|
-
(int)ntr->raw_content_len);
|
|
719
|
-
free(ntr->raw_content);
|
|
720
|
-
ntr->raw_content = NULL;
|
|
721
|
-
ntr->raw_content_len = 0;
|
|
722
|
-
|
|
723
|
-
{
|
|
724
|
-
cmark_llist *tmp, *next;
|
|
725
|
-
int i;
|
|
726
|
-
int table_columns = get_n_table_columns(node->parent);
|
|
727
|
-
|
|
728
|
-
for (tmp = row->cells, i = 0; tmp && i < table_columns; tmp = next, ++i) {
|
|
729
|
-
cmark_node *cell = (cmark_node *)tmp->data;
|
|
730
|
-
assert(cell->type == CMARK_NODE_TABLE_CELL);
|
|
731
|
-
cmark_node_append_child(node, cell);
|
|
732
|
-
row->cells = next = tmp->next;
|
|
733
|
-
parser->mem->free(tmp);
|
|
734
|
-
}
|
|
735
|
-
|
|
736
|
-
for (; i < table_columns; ++i) {
|
|
737
|
-
cmark_node *cell =
|
|
738
|
-
cmark_parser_add_child(parser, node, CMARK_NODE_TABLE_CELL,
|
|
739
|
-
cmark_parser_get_offset(parser));
|
|
740
|
-
cmark_node_set_syntax_extension(cell, self);
|
|
741
|
-
}
|
|
742
|
-
}
|
|
743
|
-
|
|
744
|
-
free_table_row(parser->mem, row);
|
|
745
|
-
}
|
|
746
|
-
}
|
|
747
|
-
|
|
748
|
-
cmark_iter_free(iter);
|
|
749
|
-
|
|
750
|
-
return root;
|
|
619
|
+
return
|
|
620
|
+
node->type != CMARK_NODE_TABLE &&
|
|
621
|
+
node->type != CMARK_NODE_TABLE_ROW &&
|
|
622
|
+
node->type != CMARK_NODE_TABLE_CELL &&
|
|
623
|
+
c == '|';
|
|
751
624
|
}
|
|
752
625
|
|
|
753
626
|
cmark_syntax_extension *create_table_extension(void) {
|
|
@@ -764,7 +637,6 @@ cmark_syntax_extension *create_table_extension(void) {
|
|
|
764
637
|
cmark_syntax_extension_set_html_render_func(self, html_render);
|
|
765
638
|
cmark_syntax_extension_set_opaque_free_func(self, opaque_free);
|
|
766
639
|
cmark_syntax_extension_set_commonmark_escape_func(self, escape);
|
|
767
|
-
cmark_syntax_extension_set_postprocess_func(self, postprocess);
|
|
768
640
|
CMARK_NODE_TABLE = cmark_syntax_extension_add_node(0);
|
|
769
641
|
CMARK_NODE_TABLE_ROW = cmark_syntax_extension_add_node(0);
|
|
770
642
|
CMARK_NODE_TABLE_CELL = cmark_syntax_extension_add_node(0);
|
|
@@ -2,9 +2,9 @@ if (NOT MSVC)
|
|
|
2
2
|
|
|
3
3
|
include(GNUInstallDirs)
|
|
4
4
|
|
|
5
|
-
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/man1/cmark.1
|
|
5
|
+
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/man1/cmark-gfm.1
|
|
6
6
|
DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
|
|
7
7
|
|
|
8
|
-
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/man3/cmark.3
|
|
8
|
+
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/man3/cmark-gfm.3
|
|
9
9
|
DESTINATION ${CMAKE_INSTALL_MANDIR}/man3)
|
|
10
10
|
endif(NOT MSVC)
|
|
@@ -21,9 +21,9 @@ from ctypes import CDLL, c_char_p, c_long, c_void_p
|
|
|
21
21
|
sysname = platform.system()
|
|
22
22
|
|
|
23
23
|
if sysname == 'Darwin':
|
|
24
|
-
cmark = CDLL("build/src/libcmark.dylib")
|
|
24
|
+
cmark = CDLL("build/src/libcmark-gfm.dylib")
|
|
25
25
|
else:
|
|
26
|
-
cmark = CDLL("build/src/libcmark.so")
|
|
26
|
+
cmark = CDLL("build/src/libcmark-gfm.so")
|
|
27
27
|
|
|
28
28
|
parse_document = cmark.cmark_parse_document
|
|
29
29
|
parse_document.restype = c_void_p
|
|
@@ -129,5 +129,5 @@ with open(sourcefile, 'r') as cmarkh:
|
|
|
129
129
|
chunk = []
|
|
130
130
|
mdlines.append('\n')
|
|
131
131
|
|
|
132
|
-
sys.stdout.write('.TH
|
|
132
|
+
sys.stdout.write('.TH cmark-gfm 3 "' + date.today().strftime('%B %d, %Y') + '" "LOCAL" "Library Functions Manual"\n')
|
|
133
133
|
sys.stdout.write(''.join(mdlines))
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
.TH "cmark" "1" "March 24, 2016" "LOCAL" "General Commands Manual"
|
|
1
|
+
.TH "cmark-gfm" "1" "March 24, 2016" "LOCAL" "General Commands Manual"
|
|
2
2
|
.SH "NAME"
|
|
3
3
|
\fBcmark\fR
|
|
4
|
-
\- convert CommonMark formatted text to HTML
|
|
4
|
+
\- convert CommonMark formatted text with GitHub Flavored Markdown extensions to HTML
|
|
5
5
|
.SH "SYNOPSIS"
|
|
6
6
|
.HP 6n
|
|
7
|
-
\fBcmark\fR
|
|
7
|
+
\fBcmark-gfm\fR
|
|
8
8
|
[options]
|
|
9
9
|
file*
|
|
10
10
|
.SH "DESCRIPTION"
|
|
11
|
-
\fBcmark\fR
|
|
11
|
+
\fBcmark-gfm\fR
|
|
12
12
|
converts Markdown formatted plain text to either HTML, groff man,
|
|
13
13
|
CommonMark XML, LaTeX, or CommonMark, using the conventions
|
|
14
14
|
described in the CommonMark spec. It reads input from \fIstdin\fR
|
|
@@ -42,6 +42,12 @@ Include source position attribute.
|
|
|
42
42
|
.B \-\-normalize
|
|
43
43
|
Consolidate adjacent text nodes.
|
|
44
44
|
.TP 12n
|
|
45
|
+
.B \-\-extension, \-e \f[I]EXTENSION_NAME\f[]
|
|
46
|
+
Specify an extension name to use.
|
|
47
|
+
.TP 12n
|
|
48
|
+
.B \-\-list\-extensions
|
|
49
|
+
List available extensions and quit.
|
|
50
|
+
.TP 12n
|
|
45
51
|
.B \-\-validate-utf8
|
|
46
52
|
Validate UTF-8, replacing illegal sequences with U+FFFD.
|
|
47
53
|
.TP 12n
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
.TH cmark 3 "
|
|
1
|
+
.TH cmark-gfm 3 "April 03, 2017" "LOCAL" "Library Functions Manual"
|
|
2
2
|
.SH
|
|
3
3
|
NAME
|
|
4
4
|
.PP
|
|
5
|
-
\f[B]cmark\f[] \- CommonMark parsing, manipulating, and rendering
|
|
5
|
+
\f[B]cmark\-gfm\f[] \- CommonMark parsing, manipulating, and rendering
|
|
6
6
|
|
|
7
7
|
.SH
|
|
8
8
|
DESCRIPTION
|
|
@@ -2,8 +2,8 @@ if(${CMAKE_VERSION} VERSION_GREATER "3.3")
|
|
|
2
2
|
cmake_policy(SET CMP0063 NEW)
|
|
3
3
|
endif()
|
|
4
4
|
|
|
5
|
-
set(LIBRARY "libcmark")
|
|
6
|
-
set(STATICLIBRARY "
|
|
5
|
+
set(LIBRARY "libcmark-gfm")
|
|
6
|
+
set(STATICLIBRARY "libcmark-gfm_static")
|
|
7
7
|
set(HEADERS
|
|
8
8
|
cmark.h
|
|
9
9
|
cmark_extension_api.h
|
|
@@ -52,7 +52,7 @@ set(LIBRARY_SOURCES
|
|
|
52
52
|
${HEADERS}
|
|
53
53
|
)
|
|
54
54
|
|
|
55
|
-
set(PROGRAM "cmark")
|
|
55
|
+
set(PROGRAM "cmark-gfm")
|
|
56
56
|
set(PROGRAM_SOURCES
|
|
57
57
|
main.c
|
|
58
58
|
)
|
|
@@ -70,10 +70,10 @@ include (GenerateExportHeader)
|
|
|
70
70
|
add_executable(${PROGRAM} ${PROGRAM_SOURCES})
|
|
71
71
|
add_compiler_export_flags()
|
|
72
72
|
|
|
73
|
-
target_link_libraries(${PROGRAM}
|
|
73
|
+
target_link_libraries(${PROGRAM} libcmark-gfm_static)
|
|
74
74
|
|
|
75
|
-
add_dependencies(${PROGRAM}
|
|
76
|
-
target_link_libraries(${PROGRAM}
|
|
75
|
+
add_dependencies(${PROGRAM} libcmark-gfmextensions_static)
|
|
76
|
+
target_link_libraries(${PROGRAM} libcmark-gfmextensions_static)
|
|
77
77
|
|
|
78
78
|
# Disable the PUBLIC declarations when compiling the executable:
|
|
79
79
|
set_target_properties(${PROGRAM} PROPERTIES
|
|
@@ -99,7 +99,7 @@ if (CMARK_SHARED)
|
|
|
99
99
|
add_library(${LIBRARY} SHARED ${LIBRARY_SOURCES})
|
|
100
100
|
# Include minor version and patch level in soname for now.
|
|
101
101
|
set_target_properties(${LIBRARY} PROPERTIES
|
|
102
|
-
OUTPUT_NAME "cmark"
|
|
102
|
+
OUTPUT_NAME "cmark-gfm"
|
|
103
103
|
SOVERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}
|
|
104
104
|
VERSION ${PROJECT_VERSION})
|
|
105
105
|
|
|
@@ -107,7 +107,7 @@ if (CMARK_SHARED)
|
|
|
107
107
|
APPEND PROPERTY MACOSX_RPATH true)
|
|
108
108
|
|
|
109
109
|
# Avoid name clash between PROGRAM and LIBRARY pdb files.
|
|
110
|
-
set_target_properties(${LIBRARY} PROPERTIES PDB_NAME
|
|
110
|
+
set_target_properties(${LIBRARY} PROPERTIES PDB_NAME cmark-gfm_dll)
|
|
111
111
|
|
|
112
112
|
generate_export_header(${LIBRARY}
|
|
113
113
|
BASE_NAME ${PROJECT_NAME})
|
|
@@ -123,15 +123,15 @@ if (CMARK_STATIC)
|
|
|
123
123
|
|
|
124
124
|
if (MSVC)
|
|
125
125
|
set_target_properties(${STATICLIBRARY} PROPERTIES
|
|
126
|
-
OUTPUT_NAME "
|
|
126
|
+
OUTPUT_NAME "cmark-gfm_static"
|
|
127
127
|
VERSION ${PROJECT_VERSION})
|
|
128
128
|
else()
|
|
129
129
|
set_target_properties(${STATICLIBRARY} PROPERTIES
|
|
130
|
-
OUTPUT_NAME "cmark"
|
|
130
|
+
OUTPUT_NAME "cmark-gfm"
|
|
131
131
|
VERSION ${PROJECT_VERSION})
|
|
132
132
|
endif(MSVC)
|
|
133
133
|
|
|
134
|
-
target_link_libraries(cmark ${CMAKE_DL_LIBS})
|
|
134
|
+
target_link_libraries(cmark-gfm ${CMAKE_DL_LIBS})
|
|
135
135
|
|
|
136
136
|
list(APPEND CMARK_INSTALL ${STATICLIBRARY})
|
|
137
137
|
endif()
|
|
@@ -139,7 +139,7 @@ set_property(TARGET ${LIBRARY}
|
|
|
139
139
|
APPEND PROPERTY MACOSX_RPATH true)
|
|
140
140
|
|
|
141
141
|
# Avoid name clash between PROGRAM and LIBRARY pdb files.
|
|
142
|
-
set_target_properties(${LIBRARY} PROPERTIES PDB_NAME
|
|
142
|
+
set_target_properties(${LIBRARY} PROPERTIES PDB_NAME cmark-gfm_dll)
|
|
143
143
|
|
|
144
144
|
generate_export_header(${LIBRARY}
|
|
145
145
|
BASE_NAME ${PROJECT_NAME})
|
|
@@ -160,9 +160,9 @@ install(TARGETS ${PROGRAM} ${CMARK_INSTALL}
|
|
|
160
160
|
)
|
|
161
161
|
|
|
162
162
|
if(CMARK_SHARED OR CMARK_STATIC)
|
|
163
|
-
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libcmark.pc.in
|
|
164
|
-
${CMAKE_CURRENT_BINARY_DIR}/libcmark.pc @ONLY)
|
|
165
|
-
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libcmark.pc
|
|
163
|
+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libcmark-gfm.pc.in
|
|
164
|
+
${CMAKE_CURRENT_BINARY_DIR}/libcmark-gfm.pc @ONLY)
|
|
165
|
+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libcmark-gfm.pc
|
|
166
166
|
DESTINATION lib${LIB_SUFFIX}/pkgconfig)
|
|
167
167
|
|
|
168
168
|
install(FILES
|
|
@@ -42,8 +42,12 @@ void cmark_strbuf_grow(cmark_strbuf *buf, bufsize_t target_size) {
|
|
|
42
42
|
if (target_size < buf->asize)
|
|
43
43
|
return;
|
|
44
44
|
|
|
45
|
-
if (target_size > (bufsize_t)(INT32_MAX / 2))
|
|
45
|
+
if (target_size > (bufsize_t)(INT32_MAX / 2)) {
|
|
46
|
+
fprintf(stderr,
|
|
47
|
+
"[cmark] cmark_strbuf_grow requests buffer with size > %d, aborting\n",
|
|
48
|
+
(INT32_MAX / 2));
|
|
46
49
|
abort();
|
|
50
|
+
}
|
|
47
51
|
|
|
48
52
|
/* Oversize the buffer by 50% to guarantee amortized linear time
|
|
49
53
|
* complexity on append operations. */
|
|
@@ -16,15 +16,19 @@ const char *cmark_version_string() { return CMARK_VERSION_STRING; }
|
|
|
16
16
|
|
|
17
17
|
static void *xcalloc(size_t nmem, size_t size) {
|
|
18
18
|
void *ptr = calloc(nmem, size);
|
|
19
|
-
if (!ptr)
|
|
19
|
+
if (!ptr) {
|
|
20
|
+
fprintf(stderr, "[cmark] calloc returned null pointer, aborting\n");
|
|
20
21
|
abort();
|
|
22
|
+
}
|
|
21
23
|
return ptr;
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
static void *xrealloc(void *ptr, size_t size) {
|
|
25
27
|
void *new_ptr = realloc(ptr, size);
|
|
26
|
-
if (!new_ptr)
|
|
28
|
+
if (!new_ptr) {
|
|
29
|
+
fprintf(stderr, "[cmark] realloc returned null pointer, aborting\n");
|
|
27
30
|
abort();
|
|
31
|
+
}
|
|
28
32
|
return new_ptr;
|
|
29
33
|
}
|
|
30
34
|
|
|
@@ -33,8 +33,7 @@ static CMARK_INLINE void outc(cmark_renderer *renderer, cmark_node *node,
|
|
|
33
33
|
needs_escaping =
|
|
34
34
|
c < 0x80 && escape != LITERAL &&
|
|
35
35
|
((escape == NORMAL &&
|
|
36
|
-
(
|
|
37
|
-
c == '*' || c == '_' || c == '[' || c == ']' || c == '#' || c == '<' ||
|
|
36
|
+
(c == '*' || c == '_' || c == '[' || c == ']' || c == '#' || c == '<' ||
|
|
38
37
|
c == '>' || c == '\\' || c == '`' || c == '!' ||
|
|
39
38
|
(c == '&' && cmark_isalpha(nextc)) || (c == '!' && nextc == '[') ||
|
|
40
39
|
(renderer->begin_content && (c == '-' || c == '+' || c == '=') &&
|
|
@@ -1209,7 +1209,7 @@ void cmark_parse_inlines(cmark_parser *parser,
|
|
|
1209
1209
|
process_emphasis(parser, &subj, NULL);
|
|
1210
1210
|
// free bracket and delim stack
|
|
1211
1211
|
while (subj.last_delim) {
|
|
1212
|
-
|
|
1212
|
+
remove_delimiter(&subj, subj.last_delim);
|
|
1213
1213
|
}
|
|
1214
1214
|
while (subj.last_bracket) {
|
|
1215
1215
|
pop_bracket(&subj);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
prefix=@CMAKE_INSTALL_PREFIX@
|
|
2
|
+
exec_prefix=@CMAKE_INSTALL_PREFIX@
|
|
3
|
+
libdir=@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@
|
|
4
|
+
includedir=@CMAKE_INSTALL_PREFIX@/include
|
|
5
|
+
|
|
6
|
+
Name: libcmark-gfm
|
|
7
|
+
Description: CommonMark parsing, rendering, and manipulation with GitHub Flavored Markdown extensions
|
|
8
|
+
Version: @PROJECT_VERSION@
|
|
9
|
+
Libs: -L${libdir} -lcmark-gfm
|
|
10
|
+
Cflags: -I${includedir}
|
|
@@ -28,7 +28,7 @@ typedef enum {
|
|
|
28
28
|
} writer_format;
|
|
29
29
|
|
|
30
30
|
void print_usage() {
|
|
31
|
-
printf("Usage: cmark [FILE*]\n");
|
|
31
|
+
printf("Usage: cmark-gfm [FILE*]\n");
|
|
32
32
|
printf("Options:\n");
|
|
33
33
|
printf(" --to, -t FORMAT Specify output format (html, xml, man, "
|
|
34
34
|
"commonmark, latex)\n");
|
|
@@ -40,7 +40,7 @@ void print_usage() {
|
|
|
40
40
|
printf(" --smart Use smart punctuation\n");
|
|
41
41
|
printf(" --github-pre-lang Use GitHub-style <pre lang> for code blocks\n");
|
|
42
42
|
printf(" --normalize Consolidate adjacent text nodes\n");
|
|
43
|
-
printf(" -e
|
|
43
|
+
printf(" --extension, -e EXTENSION_NAME Specify an extension name to use\n");
|
|
44
44
|
printf(" --list-extensions List available extensions and quit\n");
|
|
45
45
|
printf(" --help, -h Print usage information\n");
|
|
46
46
|
printf(" --version Print version\n");
|