commonmarker 0.23.0 → 0.23.4
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/README.md +12 -7
- data/bin/commonmarker +2 -7
- data/commonmarker.gemspec +2 -0
- data/ext/commonmarker/blocks.c +13 -2
- data/ext/commonmarker/cmark-gfm_version.h +2 -2
- data/ext/commonmarker/commonmark.c +14 -4
- data/ext/commonmarker/commonmarker.c +29 -44
- data/ext/commonmarker/ext_scanners.c +360 -640
- data/ext/commonmarker/footnotes.c +23 -0
- data/ext/commonmarker/footnotes.h +2 -0
- data/ext/commonmarker/html.c +40 -19
- data/ext/commonmarker/inlines.c +69 -11
- data/ext/commonmarker/node.h +7 -0
- data/ext/commonmarker/table.c +98 -53
- data/lib/commonmarker/config.rb +10 -5
- data/lib/commonmarker/errors.rb +12 -0
- data/lib/commonmarker/version.rb +1 -1
- data/lib/commonmarker.rb +1 -3
- data/test/benchmark.rb +25 -18
- data/test/test_basics.rb +17 -0
- data/test/test_extensions.rb +3 -0
- data/test/test_footnotes.rb +24 -12
- data/test/test_maliciousness.rb +0 -5
- data/test/test_smartpunct.rb +5 -2
- metadata +24 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc6d71b6e85fb61abc438252b07369d3264982cf8fb327d96e5e8333bb23841e
|
4
|
+
data.tar.gz: 1911965561ddf20104db09c44c4e5d25f65a277a28b825bc0c03bb172779a623
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 59737cb433c3f4f3d53e06d3466f1f3dcd8a40e201e8b0f26be4d553f45667137e05d980100304e720d0e8fda178da3eaa9e421608cf4e53c6d159ff9261ae3e
|
7
|
+
data.tar.gz: c3088c3219da29bdb0356f46a5b7a7f2881410c825e101f7ced3964760bfcfcb5cef57e7f3ebf5bd9f686b974ad80887fc93899e616afb211dc0e648d6352cd2
|
data/README.md
CHANGED
@@ -130,26 +130,31 @@ CommonMarker accepts the same options that CMark does, as symbols. Note that the
|
|
130
130
|
| Name | Description
|
131
131
|
| ----------------------------- | -----------
|
132
132
|
| `:DEFAULT` | The default parsing system.
|
133
|
+
| `:SOURCEPOS` | Include source position in nodes
|
133
134
|
| `:UNSAFE` | Allow raw/custom HTML and unsafe links.
|
134
|
-
| `:
|
135
|
-
| `:LIBERAL_HTML_TAG` | Support liberal parsing of inline HTML tags.
|
135
|
+
| `:VALIDATE_UTF8` | Replace illegal sequences with the replacement character `U+FFFD`.
|
136
136
|
| `:SMART` | Use smart punctuation (curly quotes, etc.).
|
137
|
+
| `:LIBERAL_HTML_TAG` | Support liberal parsing of inline HTML tags.
|
138
|
+
| `:FOOTNOTES` | Parse footnotes.
|
137
139
|
| `:STRIKETHROUGH_DOUBLE_TILDE` | Parse strikethroughs by double tildes (compatibility with [redcarpet](https://github.com/vmg/redcarpet))
|
138
|
-
| `:VALIDATE_UTF8` | Replace illegal sequences with the replacement character `U+FFFD`.
|
139
140
|
|
140
141
|
### Render options
|
141
142
|
|
142
143
|
| Name | Description |
|
143
144
|
| ------------------ | ----------- |
|
144
145
|
| `:DEFAULT` | The default rendering system. |
|
145
|
-
| `:
|
146
|
-
| `:GITHUB_PRE_LANG` | Use GitHub-style `<pre lang>` for fenced code blocks. |
|
146
|
+
| `:SOURCEPOS` | Include source position in rendered HTML. |
|
147
147
|
| `:HARDBREAKS` | Treat `\n` as hardbreaks (by adding `<br/>`). |
|
148
|
+
| `:UNSAFE` | Allow raw/custom HTML and unsafe links. |
|
148
149
|
| `:NOBREAKS` | Translate `\n` in the source to a single whitespace. |
|
149
|
-
| `:
|
150
|
+
| `:VALIDATE_UTF8` | Replace illegal sequences with the replacement character `U+FFFD`. |
|
151
|
+
| `:SMART` | Use smart punctuation (curly quotes, etc.). |
|
152
|
+
| `:GITHUB_PRE_LANG` | Use GitHub-style `<pre lang>` for fenced code blocks. |
|
153
|
+
| `:LIBERAL_HTML_TAG` | Support liberal parsing of inline HTML tags. |
|
154
|
+
| `:FOOTNOTES` | Render footnotes. |
|
155
|
+
| `:STRIKETHROUGH_DOUBLE_TILDE` | Parse strikethroughs by double tildes (compatibility with [redcarpet](https://github.com/vmg/redcarpet)) |
|
150
156
|
| `:TABLE_PREFER_STYLE_ATTRIBUTES` | Use `style` insted of `align` for table cells. |
|
151
157
|
| `:FULL_INFO_STRING` | Include full info strings of code blocks in separate attribute. |
|
152
|
-
| `:FOOTNOTES` | Render footnotes. |
|
153
158
|
|
154
159
|
### Passing options
|
155
160
|
|
data/bin/commonmarker
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'optparse'
|
5
|
-
require 'ostruct'
|
6
5
|
|
7
6
|
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
8
7
|
require 'commonmarker'
|
@@ -11,17 +10,13 @@ root = File.expand_path('..', __dir__)
|
|
11
10
|
$LOAD_PATH.unshift File.expand_path('lib', root)
|
12
11
|
|
13
12
|
def parse_options
|
14
|
-
options =
|
13
|
+
options = Struct.new(:active_extensions, :active_parse_options, :active_render_options, :output_format, :renderer)
|
14
|
+
.new([], [:DEFAULT], [:DEFAULT], :html)
|
15
15
|
extensions = CommonMarker.extensions
|
16
16
|
parse_options = CommonMarker::Config::OPTS.fetch(:parse)
|
17
17
|
render_options = CommonMarker::Config::OPTS.fetch(:render)
|
18
18
|
format_options = CommonMarker::Config::OPTS.fetch(:format)
|
19
19
|
|
20
|
-
options.active_extensions = []
|
21
|
-
options.active_parse_options = [:DEFAULT]
|
22
|
-
options.active_render_options = [:DEFAULT]
|
23
|
-
options.output_format = :html
|
24
|
-
|
25
20
|
option_parser = OptionParser.new do |opts|
|
26
21
|
opts.banner = 'Usage: commonmarker [--html-renderer] [--extension=EXTENSION]'
|
27
22
|
opts.separator ' [--to=FORMAT]'
|
data/commonmarker.gemspec
CHANGED
@@ -23,6 +23,8 @@ Gem::Specification.new do |s|
|
|
23
23
|
s.require_paths = %w[lib ext]
|
24
24
|
s.required_ruby_version = ['>= 2.6', '< 4.0']
|
25
25
|
|
26
|
+
s.metadata['rubygems_mfa_required'] = 'true'
|
27
|
+
|
26
28
|
s.rdoc_options += ['-x', 'ext/commonmarker/cmark/.*']
|
27
29
|
|
28
30
|
s.add_development_dependency 'awesome_print'
|
data/ext/commonmarker/blocks.c
CHANGED
@@ -468,7 +468,6 @@ static void process_footnotes(cmark_parser *parser) {
|
|
468
468
|
while ((ev_type = cmark_iter_next(iter)) != CMARK_EVENT_DONE) {
|
469
469
|
cur = cmark_iter_get_node(iter);
|
470
470
|
if (ev_type == CMARK_EVENT_EXIT && cur->type == CMARK_NODE_FOOTNOTE_DEFINITION) {
|
471
|
-
cmark_node_unlink(cur);
|
472
471
|
cmark_footnote_create(map, cur);
|
473
472
|
}
|
474
473
|
}
|
@@ -485,6 +484,15 @@ static void process_footnotes(cmark_parser *parser) {
|
|
485
484
|
if (!footnote->ix)
|
486
485
|
footnote->ix = ++ix;
|
487
486
|
|
487
|
+
// store a reference to this footnote reference's footnote definition
|
488
|
+
// this is used by renderers when generating label ids
|
489
|
+
cur->parent_footnote_def = footnote->node;
|
490
|
+
|
491
|
+
// keep track of a) count of how many times this footnote def has been
|
492
|
+
// referenced, and b) which reference index this footnote ref is at.
|
493
|
+
// this is used by renderers when generating links and backreferences.
|
494
|
+
cur->footnote.ref_ix = ++footnote->node->footnote.def_count;
|
495
|
+
|
488
496
|
char n[32];
|
489
497
|
snprintf(n, sizeof(n), "%d", footnote->ix);
|
490
498
|
cmark_chunk_free(parser->mem, &cur->as.literal);
|
@@ -515,13 +523,16 @@ static void process_footnotes(cmark_parser *parser) {
|
|
515
523
|
qsort(map->sorted, map->size, sizeof(cmark_map_entry *), sort_footnote_by_ix);
|
516
524
|
for (unsigned int i = 0; i < map->size; ++i) {
|
517
525
|
cmark_footnote *footnote = (cmark_footnote *)map->sorted[i];
|
518
|
-
if (!footnote->ix)
|
526
|
+
if (!footnote->ix) {
|
527
|
+
cmark_node_unlink(footnote->node);
|
519
528
|
continue;
|
529
|
+
}
|
520
530
|
cmark_node_append_child(parser->root, footnote->node);
|
521
531
|
footnote->node = NULL;
|
522
532
|
}
|
523
533
|
}
|
524
534
|
|
535
|
+
cmark_unlink_footnotes_map(map);
|
525
536
|
cmark_map_free(map);
|
526
537
|
}
|
527
538
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
#ifndef CMARK_GFM_VERSION_H
|
2
2
|
#define CMARK_GFM_VERSION_H
|
3
3
|
|
4
|
-
#define CMARK_GFM_VERSION ((0 << 24) | (29 << 16) | (0 << 8) |
|
5
|
-
#define CMARK_GFM_VERSION_STRING "0.29.0.gfm.
|
4
|
+
#define CMARK_GFM_VERSION ((0 << 24) | (29 << 16) | (0 << 8) | 3)
|
5
|
+
#define CMARK_GFM_VERSION_STRING "0.29.0.gfm.3"
|
6
6
|
|
7
7
|
#endif
|
@@ -477,7 +477,13 @@ static int S_render_node(cmark_renderer *renderer, cmark_node *node,
|
|
477
477
|
case CMARK_NODE_FOOTNOTE_REFERENCE:
|
478
478
|
if (entering) {
|
479
479
|
LIT("[^");
|
480
|
-
|
480
|
+
|
481
|
+
char *footnote_label = renderer->mem->calloc(node->parent_footnote_def->as.literal.len + 1, sizeof(char));
|
482
|
+
memmove(footnote_label, node->parent_footnote_def->as.literal.data, node->parent_footnote_def->as.literal.len);
|
483
|
+
|
484
|
+
OUT(footnote_label, false, LITERAL);
|
485
|
+
renderer->mem->free(footnote_label);
|
486
|
+
|
481
487
|
LIT("]");
|
482
488
|
}
|
483
489
|
break;
|
@@ -486,9 +492,13 @@ static int S_render_node(cmark_renderer *renderer, cmark_node *node,
|
|
486
492
|
if (entering) {
|
487
493
|
renderer->footnote_ix += 1;
|
488
494
|
LIT("[^");
|
489
|
-
|
490
|
-
|
491
|
-
|
495
|
+
|
496
|
+
char *footnote_label = renderer->mem->calloc(node->as.literal.len + 1, sizeof(char));
|
497
|
+
memmove(footnote_label, node->as.literal.data, node->as.literal.len);
|
498
|
+
|
499
|
+
OUT(footnote_label, false, LITERAL);
|
500
|
+
renderer->mem->free(footnote_label);
|
501
|
+
|
492
502
|
LIT("]:\n");
|
493
503
|
|
494
504
|
cmark_strbuf_puts(renderer->prefix, " ");
|
@@ -115,25 +115,23 @@ static void rb_parent_removed(VALUE val) {
|
|
115
115
|
RDATA(val)->dfree = rb_free_c_struct;
|
116
116
|
}
|
117
117
|
|
118
|
-
static cmark_parser *prepare_parser(VALUE rb_options, VALUE rb_extensions
|
118
|
+
static cmark_parser *prepare_parser(VALUE rb_options, VALUE rb_extensions) {
|
119
119
|
int options;
|
120
|
-
int extensions_len;
|
121
120
|
VALUE rb_ext_name;
|
122
121
|
int i;
|
123
122
|
|
124
|
-
|
123
|
+
FIXNUM_P(rb_options);
|
124
|
+
options = FIX2INT(rb_options);
|
125
|
+
|
125
126
|
Check_Type(rb_extensions, T_ARRAY);
|
126
127
|
|
127
|
-
|
128
|
-
extensions_len = RARRAY_LEN(rb_extensions);
|
128
|
+
cmark_parser *parser = cmark_parser_new(options);
|
129
129
|
|
130
|
-
|
131
|
-
|
132
|
-
rb_ext_name = RARRAY_PTR(rb_extensions)[i];
|
130
|
+
for (i = 0; i < RARRAY_LEN(rb_extensions); ++i) {
|
131
|
+
rb_ext_name = rb_ary_entry(rb_extensions, i);
|
133
132
|
|
134
133
|
if (!SYMBOL_P(rb_ext_name)) {
|
135
134
|
cmark_parser_free(parser);
|
136
|
-
cmark_arena_reset();
|
137
135
|
rb_raise(rb_eTypeError, "extension names should be Symbols; got a %"PRIsVALUE"", rb_obj_class(rb_ext_name));
|
138
136
|
}
|
139
137
|
|
@@ -142,7 +140,6 @@ static cmark_parser *prepare_parser(VALUE rb_options, VALUE rb_extensions, cmark
|
|
142
140
|
|
143
141
|
if (!syntax_extension) {
|
144
142
|
cmark_parser_free(parser);
|
145
|
-
cmark_arena_reset();
|
146
143
|
rb_raise(rb_eArgError, "extension %s not found", rb_id2name(SYM2ID(rb_ext_name)));
|
147
144
|
}
|
148
145
|
|
@@ -157,33 +154,28 @@ static cmark_parser *prepare_parser(VALUE rb_options, VALUE rb_extensions, cmark
|
|
157
154
|
*
|
158
155
|
*/
|
159
156
|
static VALUE rb_markdown_to_html(VALUE self, VALUE rb_text, VALUE rb_options, VALUE rb_extensions) {
|
160
|
-
char *
|
161
|
-
int len;
|
157
|
+
char *html;
|
162
158
|
cmark_parser *parser;
|
163
159
|
cmark_node *doc;
|
164
|
-
Check_Type(rb_text, T_STRING);
|
165
|
-
Check_Type(rb_options, T_FIXNUM);
|
166
160
|
|
167
|
-
|
161
|
+
Check_Type(rb_text, T_STRING);
|
168
162
|
|
169
|
-
|
170
|
-
len = RSTRING_LEN(rb_text);
|
163
|
+
parser = prepare_parser(rb_options, rb_extensions);
|
171
164
|
|
172
|
-
cmark_parser_feed(parser,
|
165
|
+
cmark_parser_feed(parser, StringValuePtr(rb_text), RSTRING_LEN(rb_text));
|
173
166
|
doc = cmark_parser_finish(parser);
|
167
|
+
|
174
168
|
if (doc == NULL) {
|
175
|
-
|
169
|
+
cmark_parser_free(parser);
|
176
170
|
rb_raise(rb_eNodeError, "error parsing document");
|
177
171
|
}
|
178
172
|
|
179
|
-
|
180
|
-
html = cmark_render_html_with_mem(doc, FIX2INT(rb_options), parser->syntax_extensions, default_mem);
|
181
|
-
cmark_arena_reset();
|
173
|
+
html = cmark_render_html(doc, parser->options, parser->syntax_extensions);
|
182
174
|
|
183
|
-
|
184
|
-
|
175
|
+
cmark_parser_free(parser);
|
176
|
+
cmark_node_free(doc);
|
185
177
|
|
186
|
-
return
|
178
|
+
return rb_utf8_str_new_cstr(html);
|
187
179
|
}
|
188
180
|
|
189
181
|
/*
|
@@ -191,33 +183,28 @@ static VALUE rb_markdown_to_html(VALUE self, VALUE rb_text, VALUE rb_options, VA
|
|
191
183
|
*
|
192
184
|
*/
|
193
185
|
static VALUE rb_markdown_to_xml(VALUE self, VALUE rb_text, VALUE rb_options, VALUE rb_extensions) {
|
194
|
-
char *
|
195
|
-
int len;
|
186
|
+
char *xml;
|
196
187
|
cmark_parser *parser;
|
197
188
|
cmark_node *doc;
|
198
|
-
Check_Type(rb_text, T_STRING);
|
199
|
-
Check_Type(rb_options, T_FIXNUM);
|
200
189
|
|
201
|
-
|
190
|
+
Check_Type(rb_text, T_STRING);
|
202
191
|
|
203
|
-
|
204
|
-
len = RSTRING_LEN(rb_text);
|
192
|
+
parser = prepare_parser(rb_options, rb_extensions);
|
205
193
|
|
206
|
-
cmark_parser_feed(parser,
|
194
|
+
cmark_parser_feed(parser, StringValuePtr(rb_text), RSTRING_LEN(rb_text));
|
207
195
|
doc = cmark_parser_finish(parser);
|
196
|
+
|
208
197
|
if (doc == NULL) {
|
209
|
-
|
198
|
+
cmark_parser_free(parser);
|
210
199
|
rb_raise(rb_eNodeError, "error parsing document");
|
211
200
|
}
|
212
201
|
|
213
|
-
|
214
|
-
xml = cmark_render_xml_with_mem(doc, FIX2INT(rb_options), default_mem);
|
215
|
-
cmark_arena_reset();
|
202
|
+
xml = cmark_render_xml(doc, parser->options);
|
216
203
|
|
217
|
-
|
218
|
-
|
204
|
+
cmark_parser_free(parser);
|
205
|
+
cmark_node_free(doc);
|
219
206
|
|
220
|
-
return
|
207
|
+
return rb_utf8_str_new_cstr(xml);
|
221
208
|
}
|
222
209
|
|
223
210
|
/*
|
@@ -308,18 +295,17 @@ static VALUE rb_node_new(VALUE self, VALUE type) {
|
|
308
295
|
static VALUE rb_parse_document(VALUE self, VALUE rb_text, VALUE rb_len,
|
309
296
|
VALUE rb_options, VALUE rb_extensions) {
|
310
297
|
char *text;
|
311
|
-
int len
|
298
|
+
int len;
|
312
299
|
cmark_parser *parser;
|
313
300
|
cmark_node *doc;
|
314
301
|
Check_Type(rb_text, T_STRING);
|
315
302
|
Check_Type(rb_len, T_FIXNUM);
|
316
303
|
Check_Type(rb_options, T_FIXNUM);
|
317
304
|
|
318
|
-
parser = prepare_parser(rb_options, rb_extensions
|
305
|
+
parser = prepare_parser(rb_options, rb_extensions);
|
319
306
|
|
320
307
|
text = (char *)RSTRING_PTR(rb_text);
|
321
308
|
len = FIX2INT(rb_len);
|
322
|
-
options = FIX2INT(rb_options);
|
323
309
|
|
324
310
|
cmark_parser_feed(parser, text, len);
|
325
311
|
doc = cmark_parser_finish(parser);
|
@@ -614,7 +600,6 @@ static VALUE rb_render_html(VALUE self, VALUE rb_options, VALUE rb_extensions) {
|
|
614
600
|
*/
|
615
601
|
static VALUE rb_render_xml(VALUE self, VALUE rb_options) {
|
616
602
|
int options;
|
617
|
-
int i;
|
618
603
|
cmark_node *node;
|
619
604
|
Check_Type(rb_options, T_FIXNUM);
|
620
605
|
|