markly 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/conduct.md +133 -0
- data/ext/markly/arena.c +9 -8
- data/ext/markly/autolink.c +217 -134
- data/ext/markly/blocks.c +27 -2
- data/ext/markly/cmark-gfm-core-extensions.h +11 -11
- data/ext/markly/cmark-gfm-extension_api.h +1 -0
- data/ext/markly/cmark-gfm.h +18 -2
- data/ext/markly/cmark.c +3 -3
- data/ext/markly/commonmark.c +19 -34
- data/ext/markly/extconf.rb +8 -1
- data/ext/markly/html.c +22 -6
- data/ext/markly/inlines.c +148 -51
- data/ext/markly/latex.c +6 -4
- data/ext/markly/man.c +7 -11
- data/ext/markly/map.c +11 -4
- data/ext/markly/map.h +5 -2
- data/ext/markly/markly.c +582 -586
- data/ext/markly/markly.h +1 -1
- data/ext/markly/node.c +76 -10
- data/ext/markly/node.h +42 -1
- data/ext/markly/parser.h +1 -0
- data/ext/markly/plaintext.c +12 -29
- data/ext/markly/references.c +1 -0
- data/ext/markly/render.c +15 -7
- data/ext/markly/scanners.c +13916 -10380
- data/ext/markly/scanners.h +8 -0
- data/ext/markly/scanners.re +47 -8
- data/ext/markly/strikethrough.c +1 -1
- data/ext/markly/table.c +81 -31
- data/ext/markly/xml.c +2 -1
- data/lib/markly/flags.rb +16 -0
- data/lib/markly/node/inspect.rb +59 -53
- data/lib/markly/node.rb +125 -58
- data/lib/markly/renderer/generic.rb +129 -124
- data/lib/markly/renderer/html.rb +294 -275
- data/lib/markly/version.rb +7 -1
- data/lib/markly.rb +36 -30
- data/license.md +39 -0
- data/readme.md +36 -0
- data.tar.gz.sig +0 -0
- metadata +61 -29
- metadata.gz.sig +0 -0
- data/bin/markly +0 -94
- data/lib/markly/markly.bundle +0 -0
data/ext/markly/markly.c
CHANGED
@@ -207,60 +207,60 @@ static VALUE rb_Markly_Parser_parse(VALUE self, VALUE text) {
|
|
207
207
|
* - `:image`
|
208
208
|
*/
|
209
209
|
static VALUE rb_node_new(VALUE self, VALUE type) {
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
210
|
+
cmark_node_type node_type = 0;
|
211
|
+
cmark_node *node;
|
212
|
+
|
213
|
+
Check_Type(type, T_SYMBOL);
|
214
|
+
|
215
|
+
if (type == sym_document)
|
216
|
+
node_type = CMARK_NODE_DOCUMENT;
|
217
|
+
else if (type == sym_blockquote)
|
218
|
+
node_type = CMARK_NODE_BLOCK_QUOTE;
|
219
|
+
else if (type == sym_list)
|
220
|
+
node_type = CMARK_NODE_LIST;
|
221
|
+
else if (type == sym_list_item)
|
222
|
+
node_type = CMARK_NODE_ITEM;
|
223
|
+
else if (type == sym_code_block)
|
224
|
+
node_type = CMARK_NODE_CODE_BLOCK;
|
225
|
+
else if (type == sym_html)
|
226
|
+
node_type = CMARK_NODE_HTML;
|
227
|
+
else if (type == sym_paragraph)
|
228
|
+
node_type = CMARK_NODE_PARAGRAPH;
|
229
|
+
else if (type == sym_header)
|
230
|
+
node_type = CMARK_NODE_HEADER;
|
231
|
+
else if (type == sym_hrule)
|
232
|
+
node_type = CMARK_NODE_HRULE;
|
233
|
+
else if (type == sym_text)
|
234
|
+
node_type = CMARK_NODE_TEXT;
|
235
|
+
else if (type == sym_softbreak)
|
236
|
+
node_type = CMARK_NODE_SOFTBREAK;
|
237
|
+
else if (type == sym_linebreak)
|
238
|
+
node_type = CMARK_NODE_LINEBREAK;
|
239
|
+
else if (type == sym_code)
|
240
|
+
node_type = CMARK_NODE_CODE;
|
241
|
+
else if (type == sym_inline_html)
|
242
|
+
node_type = CMARK_NODE_INLINE_HTML;
|
243
|
+
else if (type == sym_emph)
|
244
|
+
node_type = CMARK_NODE_EMPH;
|
245
|
+
else if (type == sym_strong)
|
246
|
+
node_type = CMARK_NODE_STRONG;
|
247
|
+
else if (type == sym_link)
|
248
|
+
node_type = CMARK_NODE_LINK;
|
249
|
+
else if (type == sym_image)
|
250
|
+
node_type = CMARK_NODE_IMAGE;
|
251
|
+
else if (type == sym_footnote_reference)
|
252
|
+
node_type = CMARK_NODE_FOOTNOTE_REFERENCE;
|
253
|
+
else if (type == sym_footnote_definition)
|
254
|
+
node_type = CMARK_NODE_FOOTNOTE_DEFINITION;
|
255
|
+
else
|
256
|
+
rb_raise(rb_Markly_Error, "invalid node of type %d", node_type);
|
257
|
+
|
258
|
+
node = cmark_node_new(node_type);
|
259
|
+
if (node == NULL) {
|
260
|
+
rb_raise(rb_Markly_Error, "could not create node of type %d", node_type);
|
261
|
+
}
|
262
|
+
|
263
|
+
return rb_Markly_Node_wrap(node);
|
264
264
|
}
|
265
265
|
|
266
266
|
static VALUE rb_node_replace(VALUE self, VALUE other) {
|
@@ -279,10 +279,10 @@ static VALUE rb_node_replace(VALUE self, VALUE other) {
|
|
279
279
|
}
|
280
280
|
|
281
281
|
static VALUE encode_utf8_string(const char *c_string) {
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
282
|
+
VALUE string = rb_str_new2(c_string);
|
283
|
+
int enc = rb_enc_find_index("UTF-8");
|
284
|
+
rb_enc_associate_index(string, enc);
|
285
|
+
return string;
|
286
286
|
}
|
287
287
|
|
288
288
|
/*
|
@@ -291,16 +291,16 @@ static VALUE encode_utf8_string(const char *c_string) {
|
|
291
291
|
* Returns a {String}.
|
292
292
|
*/
|
293
293
|
static VALUE rb_node_get_string_content(VALUE self) {
|
294
|
-
|
295
|
-
|
296
|
-
|
294
|
+
const char *text;
|
295
|
+
cmark_node *node;
|
296
|
+
TypedData_Get_Struct(self, cmark_node, &rb_Markly_Node_Type, node);
|
297
297
|
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
298
|
+
text = cmark_node_get_literal(node);
|
299
|
+
if (text == NULL) {
|
300
|
+
rb_raise(rb_Markly_Error, "could not get string content");
|
301
|
+
}
|
302
302
|
|
303
|
-
|
303
|
+
return encode_utf8_string(text);
|
304
304
|
}
|
305
305
|
|
306
306
|
/*
|
@@ -311,18 +311,18 @@ static VALUE rb_node_get_string_content(VALUE self) {
|
|
311
311
|
* Raises Error if the string content can't be set.
|
312
312
|
*/
|
313
313
|
static VALUE rb_node_set_string_content(VALUE self, VALUE s) {
|
314
|
-
|
315
|
-
|
316
|
-
|
314
|
+
char *text;
|
315
|
+
cmark_node *node;
|
316
|
+
Check_Type(s, T_STRING);
|
317
317
|
|
318
|
-
|
319
|
-
|
318
|
+
TypedData_Get_Struct(self, cmark_node, &rb_Markly_Node_Type, node);
|
319
|
+
text = StringValueCStr(s);
|
320
320
|
|
321
|
-
|
322
|
-
|
323
|
-
|
321
|
+
if (!cmark_node_set_literal(node, text)) {
|
322
|
+
rb_raise(rb_Markly_Error, "could not set string content");
|
323
|
+
}
|
324
324
|
|
325
|
-
|
325
|
+
return Qnil;
|
326
326
|
}
|
327
327
|
|
328
328
|
/*
|
@@ -331,86 +331,86 @@ static VALUE rb_node_set_string_content(VALUE self, VALUE s) {
|
|
331
331
|
* Returns a {Symbol} representing the node's type.
|
332
332
|
*/
|
333
333
|
static VALUE rb_node_get_type(VALUE self) {
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
334
|
+
int node_type = 0;
|
335
|
+
cmark_node *node = NULL;
|
336
|
+
VALUE symbol = Qnil;
|
337
|
+
const char *s = NULL;
|
338
|
+
|
339
|
+
TypedData_Get_Struct(self, cmark_node, &rb_Markly_Node_Type, node);
|
340
|
+
|
341
|
+
node_type = cmark_node_get_type(node);
|
342
|
+
symbol = Qnil;
|
343
|
+
|
344
|
+
switch (node_type) {
|
345
|
+
case CMARK_NODE_DOCUMENT:
|
346
|
+
symbol = sym_document;
|
347
|
+
break;
|
348
|
+
case CMARK_NODE_BLOCK_QUOTE:
|
349
|
+
symbol = sym_blockquote;
|
350
|
+
break;
|
351
|
+
case CMARK_NODE_LIST:
|
352
|
+
symbol = sym_list;
|
353
|
+
break;
|
354
|
+
case CMARK_NODE_ITEM:
|
355
|
+
symbol = sym_list_item;
|
356
|
+
break;
|
357
|
+
case CMARK_NODE_CODE_BLOCK:
|
358
|
+
symbol = sym_code_block;
|
359
|
+
break;
|
360
|
+
case CMARK_NODE_HTML:
|
361
|
+
symbol = sym_html;
|
362
|
+
break;
|
363
|
+
case CMARK_NODE_PARAGRAPH:
|
364
|
+
symbol = sym_paragraph;
|
365
|
+
break;
|
366
|
+
case CMARK_NODE_HEADER:
|
367
|
+
symbol = sym_header;
|
368
|
+
break;
|
369
|
+
case CMARK_NODE_HRULE:
|
370
|
+
symbol = sym_hrule;
|
371
|
+
break;
|
372
|
+
case CMARK_NODE_TEXT:
|
373
|
+
symbol = sym_text;
|
374
|
+
break;
|
375
|
+
case CMARK_NODE_SOFTBREAK:
|
376
|
+
symbol = sym_softbreak;
|
377
|
+
break;
|
378
|
+
case CMARK_NODE_LINEBREAK:
|
379
|
+
symbol = sym_linebreak;
|
380
|
+
break;
|
381
|
+
case CMARK_NODE_CODE:
|
382
|
+
symbol = sym_code;
|
383
|
+
break;
|
384
|
+
case CMARK_NODE_INLINE_HTML:
|
385
|
+
symbol = sym_inline_html;
|
386
|
+
break;
|
387
|
+
case CMARK_NODE_EMPH:
|
388
|
+
symbol = sym_emph;
|
389
|
+
break;
|
390
|
+
case CMARK_NODE_STRONG:
|
391
|
+
symbol = sym_strong;
|
392
|
+
break;
|
393
|
+
case CMARK_NODE_LINK:
|
394
|
+
symbol = sym_link;
|
395
|
+
break;
|
396
|
+
case CMARK_NODE_IMAGE:
|
397
|
+
symbol = sym_image;
|
398
|
+
break;
|
399
|
+
case CMARK_NODE_FOOTNOTE_REFERENCE:
|
400
|
+
symbol = sym_footnote_reference;
|
401
|
+
break;
|
402
|
+
case CMARK_NODE_FOOTNOTE_DEFINITION:
|
403
|
+
symbol = sym_footnote_definition;
|
404
|
+
break;
|
405
|
+
default:
|
406
|
+
if (node->extension) {
|
407
|
+
s = node->extension->get_type_string_func(node->extension, node);
|
408
|
+
return ID2SYM(rb_intern(s));
|
409
|
+
}
|
410
|
+
rb_raise(rb_Markly_Error, "invalid node type %d", node_type);
|
411
|
+
}
|
412
|
+
|
413
|
+
return symbol;
|
414
414
|
}
|
415
415
|
|
416
416
|
/*
|
@@ -419,24 +419,24 @@ static VALUE rb_node_get_type(VALUE self) {
|
|
419
419
|
* Returns a {Hash} containing {Symbol} keys of the positions.
|
420
420
|
*/
|
421
421
|
static VALUE rb_node_get_source_position(VALUE self) {
|
422
|
-
|
423
|
-
|
422
|
+
int start_line, start_column, end_line, end_column;
|
423
|
+
VALUE result;
|
424
424
|
|
425
|
-
|
426
|
-
|
425
|
+
cmark_node *node;
|
426
|
+
TypedData_Get_Struct(self, cmark_node, &rb_Markly_Node_Type, node);
|
427
427
|
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
428
|
+
start_line = cmark_node_get_start_line(node);
|
429
|
+
start_column = cmark_node_get_start_column(node);
|
430
|
+
end_line = cmark_node_get_end_line(node);
|
431
|
+
end_column = cmark_node_get_end_column(node);
|
432
432
|
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
433
|
+
result = rb_hash_new();
|
434
|
+
rb_hash_aset(result, CSTR2SYM("start_line"), INT2NUM(start_line));
|
435
|
+
rb_hash_aset(result, CSTR2SYM("start_column"), INT2NUM(start_column));
|
436
|
+
rb_hash_aset(result, CSTR2SYM("end_line"), INT2NUM(end_line));
|
437
|
+
rb_hash_aset(result, CSTR2SYM("end_column"), INT2NUM(end_column));
|
438
438
|
|
439
|
-
|
439
|
+
return result;
|
440
440
|
}
|
441
441
|
|
442
442
|
/*
|
@@ -445,10 +445,10 @@ static VALUE rb_node_get_source_position(VALUE self) {
|
|
445
445
|
* Returns a {String}.
|
446
446
|
*/
|
447
447
|
static VALUE rb_node_get_type_string(VALUE self) {
|
448
|
-
|
449
|
-
|
448
|
+
cmark_node *node;
|
449
|
+
TypedData_Get_Struct(self, cmark_node, &rb_Markly_Node_Type, node);
|
450
450
|
|
451
|
-
|
451
|
+
return rb_str_new2(cmark_node_get_type_string(node));
|
452
452
|
}
|
453
453
|
|
454
454
|
/*
|
@@ -456,12 +456,12 @@ static VALUE rb_node_get_type_string(VALUE self) {
|
|
456
456
|
* parents and siblings appropriately).
|
457
457
|
*/
|
458
458
|
static VALUE rb_node_unlink(VALUE self) {
|
459
|
-
|
460
|
-
|
459
|
+
cmark_node *node;
|
460
|
+
TypedData_Get_Struct(self, cmark_node, &rb_Markly_Node_Type, node);
|
461
461
|
|
462
|
-
|
462
|
+
cmark_node_unlink(node);
|
463
463
|
|
464
|
-
|
464
|
+
return Qnil;
|
465
465
|
}
|
466
466
|
|
467
467
|
/* Public: Fetches the first child of the node.
|
@@ -469,12 +469,12 @@ static VALUE rb_node_unlink(VALUE self) {
|
|
469
469
|
* Returns a {Node} if a child exists, `nil` otherise.
|
470
470
|
*/
|
471
471
|
static VALUE rb_node_first_child(VALUE self) {
|
472
|
-
|
473
|
-
|
472
|
+
cmark_node *node, *child;
|
473
|
+
TypedData_Get_Struct(self, cmark_node, &rb_Markly_Node_Type, node);
|
474
474
|
|
475
|
-
|
475
|
+
child = cmark_node_first_child(node);
|
476
476
|
|
477
|
-
|
477
|
+
return rb_Markly_Node_wrap(child);
|
478
478
|
}
|
479
479
|
|
480
480
|
/* Public: Fetches the next sibling of the node.
|
@@ -482,12 +482,12 @@ static VALUE rb_node_first_child(VALUE self) {
|
|
482
482
|
* Returns a {Node} if a sibling exists, `nil` otherwise.
|
483
483
|
*/
|
484
484
|
static VALUE rb_node_next(VALUE self) {
|
485
|
-
|
486
|
-
|
485
|
+
cmark_node *node, *next;
|
486
|
+
TypedData_Get_Struct(self, cmark_node, &rb_Markly_Node_Type, node);
|
487
487
|
|
488
|
-
|
488
|
+
next = cmark_node_next(node);
|
489
489
|
|
490
|
-
|
490
|
+
return rb_Markly_Node_wrap(next);
|
491
491
|
}
|
492
492
|
|
493
493
|
/*
|
@@ -499,15 +499,15 @@ static VALUE rb_node_next(VALUE self) {
|
|
499
499
|
* Raises Error if the node can't be inserted.
|
500
500
|
*/
|
501
501
|
static VALUE rb_node_insert_before(VALUE self, VALUE sibling) {
|
502
|
-
|
502
|
+
cmark_node *node1, *node2;
|
503
503
|
TypedData_Get_Struct(self, cmark_node, &rb_Markly_Node_Type, node1);
|
504
504
|
TypedData_Get_Struct(sibling, cmark_node, &rb_Markly_Node_Type, node2);
|
505
505
|
|
506
|
-
|
507
|
-
|
508
|
-
|
506
|
+
if (!cmark_node_insert_before(node1, node2)) {
|
507
|
+
rb_raise(rb_Markly_Error, "could not insert before");
|
508
|
+
}
|
509
509
|
|
510
|
-
|
510
|
+
return Qtrue;
|
511
511
|
}
|
512
512
|
|
513
513
|
/* Internal: Convert the node to an HTML string.
|
@@ -515,46 +515,45 @@ static VALUE rb_node_insert_before(VALUE self, VALUE sibling) {
|
|
515
515
|
* Returns a {String}.
|
516
516
|
*/
|
517
517
|
static VALUE rb_render_html(VALUE self, VALUE rb_options, VALUE rb_extensions) {
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
Check_Type(rb_extensions, T_ARRAY);
|
518
|
+
VALUE rb_ext_name;
|
519
|
+
int i;
|
520
|
+
cmark_node *node;
|
521
|
+
cmark_llist *extensions = NULL;
|
522
|
+
cmark_mem *mem = cmark_get_default_mem_allocator();
|
523
|
+
Check_Type(rb_options, T_FIXNUM);
|
524
|
+
Check_Type(rb_extensions, T_ARRAY);
|
526
525
|
|
527
|
-
|
528
|
-
|
526
|
+
int options = FIX2INT(rb_options);
|
527
|
+
long extensions_len = RARRAY_LEN(rb_extensions);
|
529
528
|
|
530
|
-
|
529
|
+
TypedData_Get_Struct(self, cmark_node, &rb_Markly_Node_Type, node);
|
531
530
|
|
532
|
-
|
533
|
-
|
531
|
+
for (i = 0; i < extensions_len; ++i) {
|
532
|
+
rb_ext_name = RARRAY_PTR(rb_extensions)[i];
|
534
533
|
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
534
|
+
if (!SYMBOL_P(rb_ext_name)) {
|
535
|
+
cmark_llist_free(mem, extensions);
|
536
|
+
rb_raise(rb_eTypeError, "extension names should be Symbols; got a %"PRIsVALUE"", rb_obj_class(rb_ext_name));
|
537
|
+
}
|
539
538
|
|
540
|
-
|
541
|
-
|
539
|
+
cmark_syntax_extension *syntax_extension =
|
540
|
+
cmark_find_syntax_extension(rb_id2name(SYM2ID(rb_ext_name)));
|
542
541
|
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
542
|
+
if (!syntax_extension) {
|
543
|
+
cmark_llist_free(mem, extensions);
|
544
|
+
rb_raise(rb_eArgError, "extension %s not found\n", rb_id2name(SYM2ID(rb_ext_name)));
|
545
|
+
}
|
547
546
|
|
548
|
-
|
549
|
-
|
547
|
+
extensions = cmark_llist_append(mem, extensions, syntax_extension);
|
548
|
+
}
|
550
549
|
|
551
|
-
|
552
|
-
|
550
|
+
char *html = cmark_render_html(node, options, extensions);
|
551
|
+
VALUE ruby_html = rb_str_new2(html);
|
553
552
|
|
554
|
-
|
555
|
-
|
553
|
+
cmark_llist_free(mem, extensions);
|
554
|
+
free(html);
|
556
555
|
|
557
|
-
|
556
|
+
return ruby_html;
|
558
557
|
}
|
559
558
|
|
560
559
|
/* Internal: Convert the node to a CommonMark string.
|
@@ -562,27 +561,27 @@ static VALUE rb_render_html(VALUE self, VALUE rb_options, VALUE rb_extensions) {
|
|
562
561
|
* Returns a {String}.
|
563
562
|
*/
|
564
563
|
static VALUE rb_render_commonmark(int argc, VALUE *argv, VALUE self) {
|
565
|
-
|
566
|
-
|
564
|
+
VALUE rb_options, rb_width;
|
565
|
+
rb_scan_args(argc, argv, "11", &rb_options, &rb_width);
|
567
566
|
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
567
|
+
int width = 120;
|
568
|
+
if (!NIL_P(rb_width)) {
|
569
|
+
Check_Type(rb_width, T_FIXNUM);
|
570
|
+
width = FIX2INT(rb_width);
|
571
|
+
}
|
573
572
|
|
574
|
-
|
575
|
-
|
576
|
-
|
573
|
+
int options;
|
574
|
+
cmark_node *node;
|
575
|
+
Check_Type(rb_options, T_FIXNUM);
|
577
576
|
|
578
|
-
|
579
|
-
|
577
|
+
options = FIX2INT(rb_options);
|
578
|
+
TypedData_Get_Struct(self, cmark_node, &rb_Markly_Node_Type, node);
|
580
579
|
|
581
|
-
|
582
|
-
|
583
|
-
|
580
|
+
char *cmark = cmark_render_commonmark(node, options, width);
|
581
|
+
VALUE ruby_cmark = rb_str_new2(cmark);
|
582
|
+
free(cmark);
|
584
583
|
|
585
|
-
|
584
|
+
return ruby_cmark;
|
586
585
|
}
|
587
586
|
|
588
587
|
/* Internal: Convert the node to a plain textstring.
|
@@ -590,27 +589,27 @@ static VALUE rb_render_commonmark(int argc, VALUE *argv, VALUE self) {
|
|
590
589
|
* Returns a {String}.
|
591
590
|
*/
|
592
591
|
static VALUE rb_render_plaintext(int argc, VALUE *argv, VALUE self) {
|
593
|
-
|
594
|
-
|
592
|
+
VALUE rb_options, rb_width;
|
593
|
+
rb_scan_args(argc, argv, "11", &rb_options, &rb_width);
|
595
594
|
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
595
|
+
int width = 120;
|
596
|
+
if (!NIL_P(rb_width)) {
|
597
|
+
Check_Type(rb_width, T_FIXNUM);
|
598
|
+
width = FIX2INT(rb_width);
|
599
|
+
}
|
601
600
|
|
602
|
-
|
603
|
-
|
604
|
-
|
601
|
+
int options;
|
602
|
+
cmark_node *node;
|
603
|
+
Check_Type(rb_options, T_FIXNUM);
|
605
604
|
|
606
|
-
|
607
|
-
|
605
|
+
options = FIX2INT(rb_options);
|
606
|
+
TypedData_Get_Struct(self, cmark_node, &rb_Markly_Node_Type, node);
|
608
607
|
|
609
|
-
|
610
|
-
|
611
|
-
|
608
|
+
char *text = cmark_render_plaintext(node, options, width);
|
609
|
+
VALUE ruby_text = rb_str_new2(text);
|
610
|
+
free(text);
|
612
611
|
|
613
|
-
|
612
|
+
return ruby_text;
|
614
613
|
}
|
615
614
|
|
616
615
|
/*
|
@@ -622,15 +621,15 @@ static VALUE rb_render_plaintext(int argc, VALUE *argv, VALUE self) {
|
|
622
621
|
* Raises Error if the node can't be inserted.
|
623
622
|
*/
|
624
623
|
static VALUE rb_node_insert_after(VALUE self, VALUE sibling) {
|
625
|
-
|
624
|
+
cmark_node *node1, *node2;
|
626
625
|
TypedData_Get_Struct(self, cmark_node, &rb_Markly_Node_Type, node1);
|
627
626
|
TypedData_Get_Struct(sibling, cmark_node, &rb_Markly_Node_Type, node2);
|
628
627
|
|
629
|
-
|
630
|
-
|
631
|
-
|
628
|
+
if (!cmark_node_insert_after(node1, node2)) {
|
629
|
+
rb_raise(rb_Markly_Error, "could not insert after");
|
630
|
+
}
|
632
631
|
|
633
|
-
|
632
|
+
return Qtrue;
|
634
633
|
}
|
635
634
|
|
636
635
|
/*
|
@@ -642,15 +641,15 @@ static VALUE rb_node_insert_after(VALUE self, VALUE sibling) {
|
|
642
641
|
* Raises Error if the node can't be inserted.
|
643
642
|
*/
|
644
643
|
static VALUE rb_node_prepend_child(VALUE self, VALUE child) {
|
645
|
-
|
644
|
+
cmark_node *node1, *node2;
|
646
645
|
TypedData_Get_Struct(self, cmark_node, &rb_Markly_Node_Type, node1);
|
647
646
|
TypedData_Get_Struct(child, cmark_node, &rb_Markly_Node_Type, node2);
|
648
647
|
|
649
|
-
|
650
|
-
|
651
|
-
|
648
|
+
if (!cmark_node_prepend_child(node1, node2)) {
|
649
|
+
rb_raise(rb_Markly_Error, "could not prepend child");
|
650
|
+
}
|
652
651
|
|
653
|
-
|
652
|
+
return Qtrue;
|
654
653
|
}
|
655
654
|
|
656
655
|
/*
|
@@ -662,15 +661,15 @@ static VALUE rb_node_prepend_child(VALUE self, VALUE child) {
|
|
662
661
|
* Raises Error if the node can't be inserted.
|
663
662
|
*/
|
664
663
|
static VALUE rb_node_append_child(VALUE self, VALUE child) {
|
665
|
-
|
664
|
+
cmark_node *node1, *node2;
|
666
665
|
TypedData_Get_Struct(self, cmark_node, &rb_Markly_Node_Type, node1);
|
667
666
|
TypedData_Get_Struct(child, cmark_node, &rb_Markly_Node_Type, node2);
|
668
667
|
|
669
|
-
|
670
|
-
|
671
|
-
|
668
|
+
if (!cmark_node_append_child(node1, node2)) {
|
669
|
+
rb_raise(rb_Markly_Error, "could not append child");
|
670
|
+
}
|
672
671
|
|
673
|
-
|
672
|
+
return Qtrue;
|
674
673
|
}
|
675
674
|
|
676
675
|
/* Public: Fetches the first child of the current node.
|
@@ -678,12 +677,12 @@ static VALUE rb_node_append_child(VALUE self, VALUE child) {
|
|
678
677
|
* Returns a {Node} if a child exists, `nil` otherise.
|
679
678
|
*/
|
680
679
|
static VALUE rb_node_last_child(VALUE self) {
|
681
|
-
|
682
|
-
|
680
|
+
cmark_node *node, *child;
|
681
|
+
TypedData_Get_Struct(self, cmark_node, &rb_Markly_Node_Type, node);
|
683
682
|
|
684
|
-
|
683
|
+
child = cmark_node_last_child(node);
|
685
684
|
|
686
|
-
|
685
|
+
return rb_Markly_Node_wrap(child);
|
687
686
|
}
|
688
687
|
|
689
688
|
/* Public: Fetches the parent of the current node.
|
@@ -691,12 +690,12 @@ static VALUE rb_node_last_child(VALUE self) {
|
|
691
690
|
* Returns a {Node} if a parent exists, `nil` otherise.
|
692
691
|
*/
|
693
692
|
static VALUE rb_node_parent(VALUE self) {
|
694
|
-
|
695
|
-
|
693
|
+
cmark_node *node, *parent;
|
694
|
+
TypedData_Get_Struct(self, cmark_node, &rb_Markly_Node_Type, node);
|
696
695
|
|
697
|
-
|
696
|
+
parent = cmark_node_parent(node);
|
698
697
|
|
699
|
-
|
698
|
+
return rb_Markly_Node_wrap(parent);
|
700
699
|
}
|
701
700
|
|
702
701
|
/* Public: Fetches the previous sibling of the current node.
|
@@ -704,12 +703,12 @@ static VALUE rb_node_parent(VALUE self) {
|
|
704
703
|
* Returns a {Node} if a parent exists, `nil` otherise.
|
705
704
|
*/
|
706
705
|
static VALUE rb_node_previous(VALUE self) {
|
707
|
-
|
708
|
-
|
706
|
+
cmark_node *node, *previous;
|
707
|
+
TypedData_Get_Struct(self, cmark_node, &rb_Markly_Node_Type, node);
|
709
708
|
|
710
|
-
|
709
|
+
previous = cmark_node_previous(node);
|
711
710
|
|
712
|
-
|
711
|
+
return rb_Markly_Node_wrap(previous);
|
713
712
|
}
|
714
713
|
|
715
714
|
/*
|
@@ -719,16 +718,16 @@ static VALUE rb_node_previous(VALUE self) {
|
|
719
718
|
* Raises a Error if the URL can't be retrieved.
|
720
719
|
*/
|
721
720
|
static VALUE rb_node_get_url(VALUE self) {
|
722
|
-
|
723
|
-
|
724
|
-
|
721
|
+
const char *text;
|
722
|
+
cmark_node *node;
|
723
|
+
TypedData_Get_Struct(self, cmark_node, &rb_Markly_Node_Type, node);
|
725
724
|
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
725
|
+
text = cmark_node_get_url(node);
|
726
|
+
if (text == NULL) {
|
727
|
+
rb_raise(rb_Markly_Error, "could not get url");
|
728
|
+
}
|
730
729
|
|
731
|
-
|
730
|
+
return rb_str_new2(text);
|
732
731
|
}
|
733
732
|
|
734
733
|
/*
|
@@ -739,18 +738,18 @@ static VALUE rb_node_get_url(VALUE self) {
|
|
739
738
|
* Raises a Error if the URL can't be set.
|
740
739
|
*/
|
741
740
|
static VALUE rb_node_set_url(VALUE self, VALUE url) {
|
742
|
-
|
743
|
-
|
744
|
-
|
741
|
+
cmark_node *node;
|
742
|
+
char *text;
|
743
|
+
Check_Type(url, T_STRING);
|
745
744
|
|
746
|
-
|
747
|
-
|
745
|
+
TypedData_Get_Struct(self, cmark_node, &rb_Markly_Node_Type, node);
|
746
|
+
text = StringValueCStr(url);
|
748
747
|
|
749
|
-
|
750
|
-
|
751
|
-
|
748
|
+
if (!cmark_node_set_url(node, text)) {
|
749
|
+
rb_raise(rb_Markly_Error, "could not set url");
|
750
|
+
}
|
752
751
|
|
753
|
-
|
752
|
+
return Qnil;
|
754
753
|
}
|
755
754
|
|
756
755
|
/*
|
@@ -760,16 +759,16 @@ static VALUE rb_node_set_url(VALUE self, VALUE url) {
|
|
760
759
|
* Raises a Error if the title can't be retrieved.
|
761
760
|
*/
|
762
761
|
static VALUE rb_node_get_title(VALUE self) {
|
763
|
-
|
764
|
-
|
765
|
-
|
762
|
+
const char *text;
|
763
|
+
cmark_node *node;
|
764
|
+
TypedData_Get_Struct(self, cmark_node, &rb_Markly_Node_Type, node);
|
766
765
|
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
766
|
+
text = cmark_node_get_title(node);
|
767
|
+
if (text == NULL) {
|
768
|
+
rb_raise(rb_Markly_Error, "could not get title");
|
769
|
+
}
|
771
770
|
|
772
|
-
|
771
|
+
return rb_str_new2(text);
|
773
772
|
}
|
774
773
|
|
775
774
|
/*
|
@@ -780,18 +779,18 @@ static VALUE rb_node_get_title(VALUE self) {
|
|
780
779
|
* Raises a Error if the title can't be set.
|
781
780
|
*/
|
782
781
|
static VALUE rb_node_set_title(VALUE self, VALUE title) {
|
783
|
-
|
784
|
-
|
785
|
-
|
782
|
+
char *text;
|
783
|
+
cmark_node *node;
|
784
|
+
Check_Type(title, T_STRING);
|
786
785
|
|
787
|
-
|
788
|
-
|
786
|
+
TypedData_Get_Struct(self, cmark_node, &rb_Markly_Node_Type, node);
|
787
|
+
text = StringValueCStr(title);
|
789
788
|
|
790
|
-
|
791
|
-
|
792
|
-
|
789
|
+
if (!cmark_node_set_title(node, text)) {
|
790
|
+
rb_raise(rb_Markly_Error, "could not set title");
|
791
|
+
}
|
793
792
|
|
794
|
-
|
793
|
+
return Qnil;
|
795
794
|
}
|
796
795
|
|
797
796
|
/*
|
@@ -801,17 +800,17 @@ static VALUE rb_node_set_title(VALUE self, VALUE title) {
|
|
801
800
|
* Raises a Error if the header level can't be retrieved.
|
802
801
|
*/
|
803
802
|
static VALUE rb_node_get_header_level(VALUE self) {
|
804
|
-
|
805
|
-
|
806
|
-
|
803
|
+
int header_level;
|
804
|
+
cmark_node *node;
|
805
|
+
TypedData_Get_Struct(self, cmark_node, &rb_Markly_Node_Type, node);
|
807
806
|
|
808
|
-
|
807
|
+
header_level = cmark_node_get_header_level(node);
|
809
808
|
|
810
|
-
|
811
|
-
|
812
|
-
|
809
|
+
if (header_level == 0) {
|
810
|
+
rb_raise(rb_Markly_Error, "could not get header_level");
|
811
|
+
}
|
813
812
|
|
814
|
-
|
813
|
+
return INT2NUM(header_level);
|
815
814
|
}
|
816
815
|
|
817
816
|
/*
|
@@ -822,18 +821,18 @@ static VALUE rb_node_get_header_level(VALUE self) {
|
|
822
821
|
* Raises a Error if the header level can't be set.
|
823
822
|
*/
|
824
823
|
static VALUE rb_node_set_header_level(VALUE self, VALUE level) {
|
825
|
-
|
826
|
-
|
827
|
-
|
824
|
+
int l;
|
825
|
+
cmark_node *node;
|
826
|
+
Check_Type(level, T_FIXNUM);
|
828
827
|
|
829
|
-
|
830
|
-
|
828
|
+
TypedData_Get_Struct(self, cmark_node, &rb_Markly_Node_Type, node);
|
829
|
+
l = FIX2INT(level);
|
831
830
|
|
832
|
-
|
833
|
-
|
834
|
-
|
831
|
+
if (!cmark_node_set_header_level(node, l)) {
|
832
|
+
rb_raise(rb_Markly_Error, "could not set header_level");
|
833
|
+
}
|
835
834
|
|
836
|
-
|
835
|
+
return Qnil;
|
837
836
|
}
|
838
837
|
|
839
838
|
/*
|
@@ -843,22 +842,22 @@ static VALUE rb_node_set_header_level(VALUE self, VALUE level) {
|
|
843
842
|
* Raises a Error if the title can't be retrieved.
|
844
843
|
*/
|
845
844
|
static VALUE rb_node_get_list_type(VALUE self) {
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
845
|
+
int list_type;
|
846
|
+
cmark_node *node;
|
847
|
+
VALUE symbol;
|
848
|
+
TypedData_Get_Struct(self, cmark_node, &rb_Markly_Node_Type, node);
|
849
|
+
|
850
|
+
list_type = cmark_node_get_list_type(node);
|
851
|
+
|
852
|
+
if (list_type == CMARK_BULLET_LIST) {
|
853
|
+
symbol = sym_bullet_list;
|
854
|
+
} else if (list_type == CMARK_ORDERED_LIST) {
|
855
|
+
symbol = sym_ordered_list;
|
856
|
+
} else {
|
857
|
+
rb_raise(rb_Markly_Error, "could not get list_type");
|
858
|
+
}
|
859
|
+
|
860
|
+
return symbol;
|
862
861
|
}
|
863
862
|
|
864
863
|
/*
|
@@ -869,25 +868,25 @@ static VALUE rb_node_get_list_type(VALUE self) {
|
|
869
868
|
* Raises a Error if the list type can't be set.
|
870
869
|
*/
|
871
870
|
static VALUE rb_node_set_list_type(VALUE self, VALUE list_type) {
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
871
|
+
int type = 0;
|
872
|
+
cmark_node *node;
|
873
|
+
Check_Type(list_type, T_SYMBOL);
|
874
|
+
|
875
|
+
TypedData_Get_Struct(self, cmark_node, &rb_Markly_Node_Type, node);
|
876
|
+
|
877
|
+
if (list_type == sym_bullet_list) {
|
878
|
+
type = CMARK_BULLET_LIST;
|
879
|
+
} else if (list_type == sym_ordered_list) {
|
880
|
+
type = CMARK_ORDERED_LIST;
|
881
|
+
} else {
|
882
|
+
rb_raise(rb_Markly_Error, "invalid list_type");
|
883
|
+
}
|
885
884
|
|
886
|
-
|
887
|
-
|
888
|
-
|
885
|
+
if (!cmark_node_set_list_type(node, type)) {
|
886
|
+
rb_raise(rb_Markly_Error, "could not set list_type");
|
887
|
+
}
|
889
888
|
|
890
|
-
|
889
|
+
return Qnil;
|
891
890
|
}
|
892
891
|
|
893
892
|
/*
|
@@ -898,16 +897,16 @@ static VALUE rb_node_set_list_type(VALUE self, VALUE list_type) {
|
|
898
897
|
* Raises a Error if the starting number can't be retrieved.
|
899
898
|
*/
|
900
899
|
static VALUE rb_node_get_list_start(VALUE self) {
|
901
|
-
|
902
|
-
|
900
|
+
cmark_node *node;
|
901
|
+
TypedData_Get_Struct(self, cmark_node, &rb_Markly_Node_Type, node);
|
903
902
|
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
903
|
+
if (cmark_node_get_type(node) != CMARK_NODE_LIST ||
|
904
|
+
cmark_node_get_list_type(node) != CMARK_ORDERED_LIST) {
|
905
|
+
rb_raise(rb_Markly_Error, "can't get list_start for non-ordered list %d",
|
906
|
+
cmark_node_get_list_type(node));
|
907
|
+
}
|
909
908
|
|
910
|
-
|
909
|
+
return INT2NUM(cmark_node_get_list_start(node));
|
911
910
|
}
|
912
911
|
|
913
912
|
/*
|
@@ -919,18 +918,18 @@ static VALUE rb_node_get_list_start(VALUE self) {
|
|
919
918
|
* Raises a Error if the starting number can't be set.
|
920
919
|
*/
|
921
920
|
static VALUE rb_node_set_list_start(VALUE self, VALUE start) {
|
922
|
-
|
923
|
-
|
924
|
-
|
921
|
+
int s;
|
922
|
+
cmark_node *node;
|
923
|
+
Check_Type(start, T_FIXNUM);
|
925
924
|
|
926
|
-
|
927
|
-
|
925
|
+
TypedData_Get_Struct(self, cmark_node, &rb_Markly_Node_Type, node);
|
926
|
+
s = FIX2INT(start);
|
928
927
|
|
929
|
-
|
930
|
-
|
931
|
-
|
928
|
+
if (!cmark_node_set_list_start(node, s)) {
|
929
|
+
rb_raise(rb_Markly_Error, "could not set list_start");
|
930
|
+
}
|
932
931
|
|
933
|
-
|
932
|
+
return Qnil;
|
934
933
|
}
|
935
934
|
|
936
935
|
/*
|
@@ -940,17 +939,17 @@ static VALUE rb_node_set_list_start(VALUE self, VALUE start) {
|
|
940
939
|
* Raises a Error if the starting number can't be retrieved.
|
941
940
|
*/
|
942
941
|
static VALUE rb_node_get_list_tight(VALUE self) {
|
943
|
-
|
944
|
-
|
945
|
-
|
942
|
+
int flag;
|
943
|
+
cmark_node *node;
|
944
|
+
TypedData_Get_Struct(self, cmark_node, &rb_Markly_Node_Type, node);
|
946
945
|
|
947
|
-
|
948
|
-
|
949
|
-
|
946
|
+
if (cmark_node_get_type(node) != CMARK_NODE_LIST) {
|
947
|
+
rb_raise(rb_Markly_Error, "can't get list_tight for non-list");
|
948
|
+
}
|
950
949
|
|
951
|
-
|
950
|
+
flag = cmark_node_get_list_tight(node);
|
952
951
|
|
953
|
-
|
952
|
+
return flag ? Qtrue : Qfalse;
|
954
953
|
}
|
955
954
|
|
956
955
|
/*
|
@@ -961,16 +960,16 @@ static VALUE rb_node_get_list_tight(VALUE self) {
|
|
961
960
|
* Raises a Error if the tightness can't be set.
|
962
961
|
*/
|
963
962
|
static VALUE rb_node_set_list_tight(VALUE self, VALUE tight) {
|
964
|
-
|
965
|
-
|
966
|
-
|
967
|
-
|
963
|
+
int t;
|
964
|
+
cmark_node *node;
|
965
|
+
TypedData_Get_Struct(self, cmark_node, &rb_Markly_Node_Type, node);
|
966
|
+
t = RTEST(tight);
|
968
967
|
|
969
|
-
|
970
|
-
|
971
|
-
|
968
|
+
if (!cmark_node_set_list_tight(node, t)) {
|
969
|
+
rb_raise(rb_Markly_Error, "could not set list_tight");
|
970
|
+
}
|
972
971
|
|
973
|
-
|
972
|
+
return Qnil;
|
974
973
|
}
|
975
974
|
|
976
975
|
/*
|
@@ -980,17 +979,17 @@ static VALUE rb_node_set_list_tight(VALUE self, VALUE tight) {
|
|
980
979
|
* Raises a Error if the fence info can't be retrieved.
|
981
980
|
*/
|
982
981
|
static VALUE rb_node_get_fence_info(VALUE self) {
|
983
|
-
|
984
|
-
|
985
|
-
|
982
|
+
const char *fence_info;
|
983
|
+
cmark_node *node;
|
984
|
+
TypedData_Get_Struct(self, cmark_node, &rb_Markly_Node_Type, node);
|
986
985
|
|
987
|
-
|
986
|
+
fence_info = cmark_node_get_fence_info(node);
|
988
987
|
|
989
|
-
|
990
|
-
|
991
|
-
|
988
|
+
if (fence_info == NULL) {
|
989
|
+
rb_raise(rb_Markly_Error, "could not get fence_info");
|
990
|
+
}
|
992
991
|
|
993
|
-
|
992
|
+
return rb_str_new2(fence_info);
|
994
993
|
}
|
995
994
|
|
996
995
|
/*
|
@@ -1001,32 +1000,32 @@ static VALUE rb_node_get_fence_info(VALUE self) {
|
|
1001
1000
|
* Raises a Error if the fence info can't be set.
|
1002
1001
|
*/
|
1003
1002
|
static VALUE rb_node_set_fence_info(VALUE self, VALUE info) {
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
1003
|
+
char *text;
|
1004
|
+
cmark_node *node;
|
1005
|
+
Check_Type(info, T_STRING);
|
1007
1006
|
|
1008
|
-
|
1009
|
-
|
1007
|
+
TypedData_Get_Struct(self, cmark_node, &rb_Markly_Node_Type, node);
|
1008
|
+
text = StringValueCStr(info);
|
1010
1009
|
|
1011
|
-
|
1012
|
-
|
1013
|
-
|
1010
|
+
if (!cmark_node_set_fence_info(node, text)) {
|
1011
|
+
rb_raise(rb_Markly_Error, "could not set fence_info");
|
1012
|
+
}
|
1014
1013
|
|
1015
|
-
|
1014
|
+
return Qnil;
|
1016
1015
|
}
|
1017
1016
|
|
1018
1017
|
static VALUE rb_node_get_tasklist_item_checked(VALUE self) {
|
1019
|
-
|
1020
|
-
|
1021
|
-
|
1018
|
+
int tasklist_state;
|
1019
|
+
cmark_node *node;
|
1020
|
+
TypedData_Get_Struct(self, cmark_node, &rb_Markly_Node_Type, node);
|
1022
1021
|
|
1023
|
-
|
1022
|
+
tasklist_state = cmark_gfm_extensions_get_tasklist_item_checked(node);
|
1024
1023
|
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1024
|
+
if (tasklist_state == 1) {
|
1025
|
+
return Qtrue;
|
1026
|
+
} else {
|
1027
|
+
return Qfalse;
|
1028
|
+
}
|
1030
1029
|
}
|
1031
1030
|
|
1032
1031
|
/*
|
@@ -1038,207 +1037,204 @@ static VALUE rb_node_get_tasklist_item_checked(VALUE self) {
|
|
1038
1037
|
* Raises a Error if the checkbox state can't be set.
|
1039
1038
|
*/
|
1040
1039
|
static VALUE rb_node_set_tasklist_item_checked(VALUE self, VALUE item_checked) {
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
1045
|
-
|
1046
|
-
|
1047
|
-
|
1048
|
-
|
1049
|
-
|
1050
|
-
|
1051
|
-
|
1052
|
-
|
1053
|
-
|
1054
|
-
|
1040
|
+
int tasklist_state;
|
1041
|
+
cmark_node *node;
|
1042
|
+
TypedData_Get_Struct(self, cmark_node, &rb_Markly_Node_Type, node);
|
1043
|
+
tasklist_state = RTEST(item_checked);
|
1044
|
+
|
1045
|
+
if (!cmark_gfm_extensions_set_tasklist_item_checked(node, tasklist_state)) {
|
1046
|
+
rb_raise(rb_Markly_Error, "could not set tasklist_item_checked");
|
1047
|
+
};
|
1048
|
+
|
1049
|
+
if (tasklist_state) {
|
1050
|
+
return Qtrue;
|
1051
|
+
} else {
|
1052
|
+
return Qfalse;
|
1053
|
+
}
|
1055
1054
|
}
|
1056
1055
|
|
1057
|
-
|
1058
|
-
|
1059
|
-
|
1060
|
-
|
1061
|
-
TypedData_Get_Struct(self, cmark_node, &rb_Markly_Node_Type, node);
|
1056
|
+
static VALUE rb_node_get_parent_footnote_def(VALUE self) {
|
1057
|
+
cmark_node *node;
|
1058
|
+
cmark_node *parent;
|
1059
|
+
TypedData_Get_Struct(self, cmark_node, &rb_Markly_Node_Type, node);
|
1062
1060
|
|
1063
|
-
|
1061
|
+
parent = cmark_node_parent_footnote_def(node);
|
1064
1062
|
|
1065
|
-
|
1066
|
-
return rb_str_new2("checked");
|
1067
|
-
} else {
|
1068
|
-
return rb_str_new2("unchecked");
|
1069
|
-
}
|
1063
|
+
return rb_Markly_Node_wrap(parent);
|
1070
1064
|
}
|
1071
1065
|
|
1072
1066
|
static VALUE rb_node_get_table_alignments(VALUE self) {
|
1073
|
-
|
1074
|
-
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1078
|
-
|
1079
|
-
|
1080
|
-
|
1081
|
-
|
1082
|
-
|
1083
|
-
|
1084
|
-
|
1085
|
-
|
1086
|
-
|
1087
|
-
|
1088
|
-
|
1089
|
-
|
1090
|
-
|
1091
|
-
|
1092
|
-
|
1093
|
-
|
1094
|
-
|
1095
|
-
|
1096
|
-
|
1097
|
-
|
1067
|
+
uint16_t column_count, i;
|
1068
|
+
uint8_t *alignments;
|
1069
|
+
cmark_node *node;
|
1070
|
+
VALUE ary;
|
1071
|
+
TypedData_Get_Struct(self, cmark_node, &rb_Markly_Node_Type, node);
|
1072
|
+
|
1073
|
+
column_count = cmark_gfm_extensions_get_table_columns(node);
|
1074
|
+
alignments = cmark_gfm_extensions_get_table_alignments(node);
|
1075
|
+
|
1076
|
+
if (!column_count || !alignments) {
|
1077
|
+
rb_raise(rb_Markly_Error, "could not get column_count or alignments");
|
1078
|
+
}
|
1079
|
+
|
1080
|
+
ary = rb_ary_new();
|
1081
|
+
for (i = 0; i < column_count; ++i) {
|
1082
|
+
if (alignments[i] == 'l')
|
1083
|
+
rb_ary_push(ary, sym_left);
|
1084
|
+
else if (alignments[i] == 'c')
|
1085
|
+
rb_ary_push(ary, sym_center);
|
1086
|
+
else if (alignments[i] == 'r')
|
1087
|
+
rb_ary_push(ary, sym_right);
|
1088
|
+
else
|
1089
|
+
rb_ary_push(ary, Qnil);
|
1090
|
+
}
|
1091
|
+
return ary;
|
1098
1092
|
}
|
1099
1093
|
|
1100
1094
|
/* Internal: Escapes href URLs safely. */
|
1101
1095
|
static VALUE rb_html_escape_href(VALUE self, VALUE rb_text) {
|
1102
|
-
|
1103
|
-
|
1104
|
-
|
1096
|
+
char *result;
|
1097
|
+
cmark_node *node;
|
1098
|
+
Check_Type(rb_text, T_STRING);
|
1105
1099
|
|
1106
|
-
|
1100
|
+
TypedData_Get_Struct(self, cmark_node, &rb_Markly_Node_Type, node);
|
1107
1101
|
|
1108
|
-
|
1109
|
-
|
1102
|
+
cmark_mem *mem = cmark_node_mem(node);
|
1103
|
+
cmark_strbuf buf = CMARK_BUF_INIT(mem);
|
1110
1104
|
|
1111
|
-
|
1112
|
-
|
1113
|
-
|
1114
|
-
|
1115
|
-
|
1105
|
+
if (houdini_escape_href(&buf, (const uint8_t *)RSTRING_PTR(rb_text),
|
1106
|
+
RSTRING_LEN(rb_text))) {
|
1107
|
+
result = (char *)cmark_strbuf_detach(&buf);
|
1108
|
+
return rb_str_new2(result);
|
1109
|
+
}
|
1116
1110
|
|
1117
|
-
|
1111
|
+
return rb_text;
|
1118
1112
|
}
|
1119
1113
|
|
1120
1114
|
/* Internal: Escapes HTML content safely. */
|
1121
1115
|
static VALUE rb_html_escape_html(VALUE self, VALUE rb_text) {
|
1122
|
-
|
1123
|
-
|
1124
|
-
|
1116
|
+
char *result;
|
1117
|
+
cmark_node *node;
|
1118
|
+
Check_Type(rb_text, T_STRING);
|
1125
1119
|
|
1126
|
-
|
1120
|
+
TypedData_Get_Struct(self, cmark_node, &rb_Markly_Node_Type, node);
|
1127
1121
|
|
1128
|
-
|
1129
|
-
|
1122
|
+
cmark_mem *mem = cmark_node_mem(node);
|
1123
|
+
cmark_strbuf buf = CMARK_BUF_INIT(mem);
|
1130
1124
|
|
1131
|
-
|
1132
|
-
|
1133
|
-
|
1134
|
-
|
1135
|
-
|
1125
|
+
if (houdini_escape_html0(&buf, (const uint8_t *)RSTRING_PTR(rb_text),
|
1126
|
+
RSTRING_LEN(rb_text), 0)) {
|
1127
|
+
result = (char *)cmark_strbuf_detach(&buf);
|
1128
|
+
return rb_str_new2(result);
|
1129
|
+
}
|
1136
1130
|
|
1137
|
-
|
1131
|
+
return rb_text;
|
1138
1132
|
}
|
1139
1133
|
|
1140
1134
|
VALUE rb_Markly_extensions(VALUE self) {
|
1141
|
-
|
1142
|
-
|
1143
|
-
|
1144
|
-
|
1145
|
-
|
1146
|
-
|
1147
|
-
|
1148
|
-
|
1149
|
-
|
1150
|
-
|
1135
|
+
cmark_llist *exts, *it;
|
1136
|
+
cmark_syntax_extension *ext;
|
1137
|
+
VALUE ary = rb_ary_new();
|
1138
|
+
|
1139
|
+
cmark_mem *mem = cmark_get_default_mem_allocator();
|
1140
|
+
exts = cmark_list_syntax_extensions(mem);
|
1141
|
+
for (it = exts; it; it = it->next) {
|
1142
|
+
ext = it->data;
|
1143
|
+
rb_ary_push(ary, rb_str_new2(ext->name));
|
1144
|
+
}
|
1151
1145
|
|
1152
|
-
|
1146
|
+
cmark_llist_free(mem, exts);
|
1153
1147
|
|
1154
|
-
|
1148
|
+
return ary;
|
1155
1149
|
}
|
1156
1150
|
|
1157
|
-
__attribute__((visibility("default"))) void Init_markly() {
|
1158
|
-
|
1159
|
-
|
1160
|
-
|
1161
|
-
|
1162
|
-
|
1163
|
-
|
1164
|
-
|
1165
|
-
|
1166
|
-
|
1167
|
-
|
1168
|
-
|
1169
|
-
|
1170
|
-
|
1171
|
-
|
1172
|
-
|
1173
|
-
|
1174
|
-
|
1175
|
-
|
1176
|
-
|
1177
|
-
|
1178
|
-
|
1179
|
-
|
1180
|
-
|
1181
|
-
|
1182
|
-
|
1183
|
-
|
1184
|
-
|
1185
|
-
|
1186
|
-
|
1187
|
-
|
1188
|
-
|
1189
|
-
|
1190
|
-
|
1191
|
-
|
1192
|
-
|
1151
|
+
__attribute__((visibility("default"))) void Init_markly(void) {
|
1152
|
+
sym_document = ID2SYM(rb_intern("document"));
|
1153
|
+
sym_blockquote = ID2SYM(rb_intern("blockquote"));
|
1154
|
+
sym_list = ID2SYM(rb_intern("list"));
|
1155
|
+
sym_list_item = ID2SYM(rb_intern("list_item"));
|
1156
|
+
sym_code_block = ID2SYM(rb_intern("code_block"));
|
1157
|
+
sym_html = ID2SYM(rb_intern("html"));
|
1158
|
+
sym_paragraph = ID2SYM(rb_intern("paragraph"));
|
1159
|
+
sym_header = ID2SYM(rb_intern("header"));
|
1160
|
+
sym_hrule = ID2SYM(rb_intern("hrule"));
|
1161
|
+
sym_text = ID2SYM(rb_intern("text"));
|
1162
|
+
sym_softbreak = ID2SYM(rb_intern("softbreak"));
|
1163
|
+
sym_linebreak = ID2SYM(rb_intern("linebreak"));
|
1164
|
+
sym_code = ID2SYM(rb_intern("code"));
|
1165
|
+
sym_inline_html = ID2SYM(rb_intern("inline_html"));
|
1166
|
+
sym_emph = ID2SYM(rb_intern("emph"));
|
1167
|
+
sym_strong = ID2SYM(rb_intern("strong"));
|
1168
|
+
sym_link = ID2SYM(rb_intern("link"));
|
1169
|
+
sym_image = ID2SYM(rb_intern("image"));
|
1170
|
+
sym_footnote_reference = ID2SYM(rb_intern("footnote_reference"));
|
1171
|
+
sym_footnote_definition = ID2SYM(rb_intern("footnote_definition"));
|
1172
|
+
|
1173
|
+
sym_bullet_list = ID2SYM(rb_intern("bullet_list"));
|
1174
|
+
sym_ordered_list = ID2SYM(rb_intern("ordered_list"));
|
1175
|
+
|
1176
|
+
sym_left = ID2SYM(rb_intern("left"));
|
1177
|
+
sym_right = ID2SYM(rb_intern("right"));
|
1178
|
+
sym_center = ID2SYM(rb_intern("center"));
|
1179
|
+
|
1180
|
+
rb_Markly = rb_define_module("Markly");
|
1181
|
+
rb_define_singleton_method(rb_Markly, "extensions", rb_Markly_extensions, 0);
|
1182
|
+
|
1183
|
+
rb_Markly_Error = rb_define_class_under(rb_Markly, "Error", rb_eStandardError);
|
1184
|
+
rb_define_singleton_method(rb_Markly_Node, "parse", rb_Markly_Parser_parse, 1);
|
1185
|
+
|
1186
|
+
rb_Markly_Parser = rb_define_class_under(rb_Markly, "Parser", rb_cObject);
|
1193
1187
|
rb_define_alloc_func(rb_Markly_Parser, rb_Markly_Parser_alloc);
|
1194
1188
|
rb_define_method(rb_Markly_Parser, "initialize", rb_Markly_Parser_initialize, 1);
|
1195
1189
|
rb_define_method(rb_Markly_Parser, "enable", rb_Markly_Parser_enable, 1);
|
1196
1190
|
rb_define_method(rb_Markly_Parser, "parse", rb_Markly_Parser_parse, 1);
|
1197
1191
|
|
1198
|
-
|
1199
|
-
|
1192
|
+
rb_Markly_Node = rb_define_class_under(rb_Markly, "Node", rb_cObject);
|
1193
|
+
rb_undef_alloc_func(rb_Markly_Node);
|
1194
|
+
rb_define_singleton_method(rb_Markly_Node, "new", rb_node_new, 1);
|
1200
1195
|
|
1201
1196
|
rb_define_method(rb_Markly_Node, "replace", rb_node_replace, 1);
|
1202
1197
|
|
1203
|
-
|
1204
|
-
|
1205
|
-
|
1206
|
-
|
1207
|
-
|
1208
|
-
|
1209
|
-
|
1210
|
-
|
1211
|
-
|
1212
|
-
|
1213
|
-
|
1214
|
-
|
1215
|
-
|
1216
|
-
|
1217
|
-
|
1218
|
-
|
1219
|
-
|
1220
|
-
|
1221
|
-
|
1222
|
-
|
1223
|
-
|
1224
|
-
|
1225
|
-
|
1226
|
-
|
1227
|
-
|
1228
|
-
|
1229
|
-
|
1230
|
-
|
1231
|
-
|
1232
|
-
|
1233
|
-
|
1234
|
-
|
1235
|
-
|
1236
|
-
|
1237
|
-
|
1238
|
-
|
1239
|
-
|
1240
|
-
|
1241
|
-
|
1242
|
-
|
1243
|
-
|
1198
|
+
rb_define_method(rb_Markly_Node, "string_content", rb_node_get_string_content, 0);
|
1199
|
+
rb_define_method(rb_Markly_Node, "string_content=", rb_node_set_string_content, 1);
|
1200
|
+
rb_define_method(rb_Markly_Node, "type", rb_node_get_type, 0);
|
1201
|
+
rb_define_method(rb_Markly_Node, "type_string", rb_node_get_type_string, 0);
|
1202
|
+
rb_define_method(rb_Markly_Node, "source_position", rb_node_get_source_position, 0);
|
1203
|
+
rb_define_method(rb_Markly_Node, "delete", rb_node_unlink, 0);
|
1204
|
+
rb_define_method(rb_Markly_Node, "first_child", rb_node_first_child, 0);
|
1205
|
+
rb_define_method(rb_Markly_Node, "next", rb_node_next, 0);
|
1206
|
+
rb_define_method(rb_Markly_Node, "insert_before", rb_node_insert_before, 1);
|
1207
|
+
rb_define_method(rb_Markly_Node, "_render_html", rb_render_html, 2);
|
1208
|
+
rb_define_method(rb_Markly_Node, "_render_commonmark", rb_render_commonmark, -1);
|
1209
|
+
rb_define_method(rb_Markly_Node, "_render_plaintext", rb_render_plaintext, -1);
|
1210
|
+
rb_define_method(rb_Markly_Node, "insert_after", rb_node_insert_after, 1);
|
1211
|
+
rb_define_method(rb_Markly_Node, "prepend_child", rb_node_prepend_child, 1);
|
1212
|
+
rb_define_method(rb_Markly_Node, "append_child", rb_node_append_child, 1);
|
1213
|
+
rb_define_method(rb_Markly_Node, "last_child", rb_node_last_child, 0);
|
1214
|
+
rb_define_method(rb_Markly_Node, "parent", rb_node_parent, 0);
|
1215
|
+
rb_define_method(rb_Markly_Node, "previous", rb_node_previous, 0);
|
1216
|
+
rb_define_method(rb_Markly_Node, "url", rb_node_get_url, 0);
|
1217
|
+
rb_define_method(rb_Markly_Node, "url=", rb_node_set_url, 1);
|
1218
|
+
rb_define_method(rb_Markly_Node, "title", rb_node_get_title, 0);
|
1219
|
+
rb_define_method(rb_Markly_Node, "title=", rb_node_set_title, 1);
|
1220
|
+
rb_define_method(rb_Markly_Node, "header_level", rb_node_get_header_level, 0);
|
1221
|
+
rb_define_method(rb_Markly_Node, "header_level=", rb_node_set_header_level, 1);
|
1222
|
+
rb_define_method(rb_Markly_Node, "list_type", rb_node_get_list_type, 0);
|
1223
|
+
rb_define_method(rb_Markly_Node, "list_type=", rb_node_set_list_type, 1);
|
1224
|
+
rb_define_method(rb_Markly_Node, "list_start", rb_node_get_list_start, 0);
|
1225
|
+
rb_define_method(rb_Markly_Node, "list_start=", rb_node_set_list_start, 1);
|
1226
|
+
rb_define_method(rb_Markly_Node, "list_tight", rb_node_get_list_tight, 0);
|
1227
|
+
rb_define_method(rb_Markly_Node, "list_tight=", rb_node_set_list_tight, 1);
|
1228
|
+
rb_define_method(rb_Markly_Node, "fence_info", rb_node_get_fence_info, 0);
|
1229
|
+
rb_define_method(rb_Markly_Node, "fence_info=", rb_node_set_fence_info, 1);
|
1230
|
+
rb_define_method(rb_Markly_Node, "table_alignments", rb_node_get_table_alignments, 0);
|
1231
|
+
rb_define_method(rb_Markly_Node, "tasklist_item_checked?", rb_node_get_tasklist_item_checked, 0);
|
1232
|
+
rb_define_method(rb_Markly_Node, "tasklist_item_checked=", rb_node_set_tasklist_item_checked, 1);
|
1233
|
+
|
1234
|
+
rb_define_method(rb_Markly_Node, "parent_footnote_def", rb_node_get_parent_footnote_def, 0);
|
1235
|
+
|
1236
|
+
rb_define_method(rb_Markly_Node, "html_escape_href", rb_html_escape_href, 1);
|
1237
|
+
rb_define_method(rb_Markly_Node, "html_escape_html", rb_html_escape_html, 1);
|
1238
|
+
|
1239
|
+
cmark_gfm_core_extensions_ensure_registered();
|
1244
1240
|
}
|