commonmarker 0.14.7 → 0.14.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f425674c391066d58b5512c04eb239de205ee2ea
4
- data.tar.gz: 907ae22ce32eef2427eb20cac8a3bbe9dee340b4
3
+ metadata.gz: c7671aeb47f1d80b9f0af919244c4ca5878e7f20
4
+ data.tar.gz: bf4171308460c0489f99c40c61c15a8ba5a73a7b
5
5
  SHA512:
6
- metadata.gz: d0a64fa64caeaf5b25a040509ca3efc47416acc6fcd18cb912cff1feaac5e10cf27e549052f3c8e9e77162a945f8c923e7805a60bf7218d30084eab594354690
7
- data.tar.gz: 6d112655ccd7e0a9a1cf40b06a777550358087ab6edc4b14cedab64b15da7829019e8d14d89e54739c3954c1f5d36ff9f6ab085406dbdffbd5093204a2057f75
6
+ metadata.gz: 90eef935178fc24266997b0e1bad721f2e640d9923b77244f602e6e70f9f98507368e96827d02d5fecc8765a45b3196d5966afa64c98fc2d24001f5a759e9123
7
+ data.tar.gz: bcf2f257b01acee2e0bf1d0314118b12f3be96ef72cf6abba11823af25d78605fc058f79e91c0cf402c559770bd45f04856fe9adf73391df787e462de1ff01ac
@@ -2,6 +2,7 @@
2
2
  #include <inlines.h>
3
3
  #include <parser.h>
4
4
  #include <references.h>
5
+ #include <string.h>
5
6
 
6
7
  #include "ext_scanners.h"
7
8
  #include "strikethrough.h"
@@ -18,10 +19,13 @@ typedef struct {
18
19
  typedef struct {
19
20
  uint16_t n_columns;
20
21
  uint8_t *alignments;
21
- table_row *last_matched_row;
22
22
  } node_table;
23
23
 
24
- typedef struct { bool is_header; } node_table_row;
24
+ typedef struct {
25
+ bool is_header;
26
+ unsigned char *raw_content;
27
+ size_t raw_content_len;
28
+ } node_table_row;
25
29
 
26
30
  static void free_table_cell(cmark_mem *mem, void *data) {
27
31
  cmark_node_free((cmark_node *)data);
@@ -39,11 +43,14 @@ static void free_table_row(cmark_mem *mem, table_row *row) {
39
43
  static void free_node_table(cmark_mem *mem, void *ptr) {
40
44
  node_table *t = (node_table *)ptr;
41
45
  mem->free(t->alignments);
42
- free_table_row(mem, t->last_matched_row);
43
46
  mem->free(t);
44
47
  }
45
48
 
46
- static void free_node_table_row(cmark_mem *mem, void *ptr) { mem->free(ptr); }
49
+ static void free_node_table_row(cmark_mem *mem, void *ptr) {
50
+ node_table_row *ntr = (node_table_row *)ptr;
51
+ mem->free(ntr->raw_content);
52
+ mem->free(ntr);
53
+ }
47
54
 
48
55
  static int get_n_table_columns(cmark_node *node) {
49
56
  if (!node || node->type != CMARK_NODE_TABLE)
@@ -75,14 +82,6 @@ static int set_table_alignments(cmark_node *node, uint8_t *alignments) {
75
82
  return 1;
76
83
  }
77
84
 
78
- static int is_table_header(cmark_node *node, int is_table_header) {
79
- if (!node || node->type != CMARK_NODE_TABLE_ROW)
80
- return 0;
81
-
82
- ((node_table_row *)node->as.opaque)->is_header = (is_table_header != 0);
83
- return 1;
84
- }
85
-
86
85
  static void maybe_consume_pipe(cmark_node **n, int *offset) {
87
86
  if (*n && (*n)->type == CMARK_NODE_TEXT && *offset < (*n)->as.literal.len &&
88
87
  (*n)->as.literal.data[*offset] == '|')
@@ -251,6 +250,7 @@ static cmark_node *try_opening_table_header(cmark_syntax_extension *self,
251
250
  cmark_node *table_header;
252
251
  table_row *header_row = NULL;
253
252
  table_row *marker_row = NULL;
253
+ node_table_row *ntr;
254
254
  const char *parent_string;
255
255
  uint16_t i;
256
256
 
@@ -318,19 +318,11 @@ static cmark_node *try_opening_table_header(cmark_syntax_extension *self,
318
318
  cmark_parser_get_offset(parser));
319
319
  cmark_node_set_syntax_extension(table_header, self);
320
320
 
321
- table_header->as.opaque = parser->mem->calloc(1, sizeof(node_table_row));
322
- is_table_header(table_header, true);
323
-
324
- {
325
- cmark_llist *tmp, *next;
326
-
327
- for (tmp = header_row->cells; tmp; tmp = next) {
328
- cmark_node *header_cell = (cmark_node *)tmp->data;
329
- cmark_node_append_child(table_header, header_cell);
330
- next = header_row->cells = tmp->next;
331
- parser->mem->free(tmp);
332
- }
333
- }
321
+ table_header->as.opaque = ntr = (node_table_row *)parser->mem->calloc(1, sizeof(node_table_row));
322
+ ntr->is_header = true;
323
+ ntr->raw_content_len = strlen(parent_string);
324
+ ntr->raw_content = (unsigned char *)malloc(ntr->raw_content_len);
325
+ memcpy(ntr->raw_content, parent_string, ntr->raw_content_len);
334
326
 
335
327
  cmark_parser_advance_offset(
336
328
  parser, (char *)input,
@@ -346,8 +338,7 @@ static cmark_node *try_opening_table_row(cmark_syntax_extension *self,
346
338
  cmark_node *parent_container,
347
339
  unsigned char *input, int len) {
348
340
  cmark_node *table_row_block;
349
- node_table *nt;
350
- table_row *row;
341
+ node_table_row *ntr;
351
342
 
352
343
  if (cmark_parser_is_blank(parser))
353
344
  return NULL;
@@ -357,40 +348,11 @@ static cmark_node *try_opening_table_row(cmark_syntax_extension *self,
357
348
  cmark_parser_get_offset(parser));
358
349
 
359
350
  cmark_node_set_syntax_extension(table_row_block, self);
360
- table_row_block->as.opaque = parser->mem->calloc(1, sizeof(node_table_row));
361
-
362
- /* We don't advance the offset here */
363
- nt = (node_table *)parent_container->as.opaque;
364
- if (nt->last_matched_row) {
365
- row = nt->last_matched_row;
366
- nt->last_matched_row = NULL;
367
- } else
368
- row = row_from_string(self, parser,
369
- input + cmark_parser_get_first_nonspace(parser),
370
- len - cmark_parser_get_first_nonspace(parser));
371
-
372
- {
373
- cmark_llist *tmp, *next;
374
- int i;
375
- int table_columns = get_n_table_columns(parent_container);
376
-
377
- for (tmp = row->cells, i = 0; tmp && i < table_columns; tmp = next, ++i) {
378
- cmark_node *cell = (cmark_node *)tmp->data;
379
- assert(cell->type == CMARK_NODE_TABLE_CELL);
380
- cmark_node_append_child(table_row_block, cell);
381
- row->cells = next = tmp->next;
382
- parser->mem->free(tmp);
383
- }
351
+ table_row_block->as.opaque = ntr = (node_table_row *)parser->mem->calloc(1, sizeof(node_table_row));
384
352
 
385
- for (; i < table_columns; ++i) {
386
- cmark_node *cell =
387
- cmark_parser_add_child(parser, table_row_block, CMARK_NODE_TABLE_CELL,
388
- cmark_parser_get_offset(parser));
389
- cmark_node_set_syntax_extension(cell, self);
390
- }
391
- }
392
-
393
- free_table_row(parser->mem, row);
353
+ ntr->raw_content_len = len - cmark_parser_get_first_nonspace(parser);
354
+ ntr->raw_content = (unsigned char *)malloc(len);
355
+ memcpy(ntr->raw_content, input + cmark_parser_get_first_nonspace(parser), ntr->raw_content_len);
394
356
 
395
357
  cmark_parser_advance_offset(parser, (char *)input,
396
358
  len - 1 - cmark_parser_get_offset(parser), false);
@@ -417,25 +379,20 @@ static int matches(cmark_syntax_extension *self, cmark_parser *parser,
417
379
  unsigned char *input, int len,
418
380
  cmark_node *parent_container) {
419
381
  int res = 0;
420
- node_table *nt;
421
382
 
422
383
  if (cmark_node_get_type(parent_container) == CMARK_NODE_TABLE) {
423
384
  table_row *new_row = row_from_string(
424
385
  self, parser, input + cmark_parser_get_first_nonspace(parser),
425
386
  len - cmark_parser_get_first_nonspace(parser));
426
- if (new_row && new_row->n_columns) {
387
+ if (new_row && new_row->n_columns)
427
388
  res = 1;
428
- nt = (node_table *)parent_container->as.opaque;
429
- free_table_row(parser->mem, nt->last_matched_row);
430
- nt->last_matched_row = new_row;
431
- } else
432
- free_table_row(parser->mem, new_row);
389
+ free_table_row(parser->mem, new_row);
433
390
  }
434
391
 
435
392
  return res;
436
393
  }
437
394
 
438
- static const char *get_type_string(cmark_syntax_extension *ext,
395
+ static const char *get_type_string(cmark_syntax_extension *self,
439
396
  cmark_node *node) {
440
397
  if (node->type == CMARK_NODE_TABLE) {
441
398
  return "table";
@@ -711,7 +668,7 @@ static void html_render(cmark_syntax_extension *extension,
711
668
  }
712
669
  }
713
670
 
714
- static void opaque_free(cmark_syntax_extension *ext, cmark_mem *mem, cmark_node *node) {
671
+ static void opaque_free(cmark_syntax_extension *self, cmark_mem *mem, cmark_node *node) {
715
672
  if (node->type == CMARK_NODE_TABLE) {
716
673
  free_node_table(mem, node->as.opaque);
717
674
  } else if (node->type == CMARK_NODE_TABLE_ROW) {
@@ -719,27 +676,80 @@ static void opaque_free(cmark_syntax_extension *ext, cmark_mem *mem, cmark_node
719
676
  }
720
677
  }
721
678
 
722
- static int escape(cmark_syntax_extension *ext, cmark_node *node, int c) {
679
+ static int escape(cmark_syntax_extension *self, cmark_node *node, int c) {
723
680
  return c == '|';
724
681
  }
725
682
 
683
+ static cmark_node *postprocess(cmark_syntax_extension *self, cmark_parser *parser, cmark_node *root) {
684
+ cmark_iter *iter;
685
+ cmark_event_type ev;
686
+ cmark_node *node;
687
+ node_table_row *ntr;
688
+ table_row *row;
689
+
690
+ iter = cmark_iter_new(root);
691
+
692
+ while ((ev = cmark_iter_next(iter)) != CMARK_EVENT_DONE) {
693
+ node = cmark_iter_get_node(iter);
694
+ if (ev == CMARK_EVENT_EXIT && node->type == CMARK_NODE_TABLE_ROW) {
695
+ ntr = (node_table_row *)node->as.opaque;
696
+ if (!ntr->raw_content)
697
+ continue;
698
+ row = row_from_string(self, parser,
699
+ ntr->raw_content,
700
+ (int)ntr->raw_content_len);
701
+ free(ntr->raw_content);
702
+ ntr->raw_content = NULL;
703
+ ntr->raw_content_len = 0;
704
+
705
+ {
706
+ cmark_llist *tmp, *next;
707
+ int i;
708
+ int table_columns = get_n_table_columns(node->parent);
709
+
710
+ for (tmp = row->cells, i = 0; tmp && i < table_columns; tmp = next, ++i) {
711
+ cmark_node *cell = (cmark_node *)tmp->data;
712
+ assert(cell->type == CMARK_NODE_TABLE_CELL);
713
+ cmark_node_append_child(node, cell);
714
+ row->cells = next = tmp->next;
715
+ parser->mem->free(tmp);
716
+ }
717
+
718
+ for (; i < table_columns; ++i) {
719
+ cmark_node *cell =
720
+ cmark_parser_add_child(parser, node, CMARK_NODE_TABLE_CELL,
721
+ cmark_parser_get_offset(parser));
722
+ cmark_node_set_syntax_extension(cell, self);
723
+ }
724
+ }
725
+
726
+ free_table_row(parser->mem, row);
727
+ }
728
+ }
729
+
730
+ cmark_iter_free(iter);
731
+
732
+ return root;
733
+ }
734
+
726
735
  cmark_syntax_extension *create_table_extension(void) {
727
- cmark_syntax_extension *ext = cmark_syntax_extension_new("table");
728
-
729
- cmark_syntax_extension_set_match_block_func(ext, matches);
730
- cmark_syntax_extension_set_open_block_func(ext, try_opening_table_block);
731
- cmark_syntax_extension_set_get_type_string_func(ext, get_type_string);
732
- cmark_syntax_extension_set_can_contain_func(ext, can_contain);
733
- cmark_syntax_extension_set_contains_inlines_func(ext, contains_inlines);
734
- cmark_syntax_extension_set_commonmark_render_func(ext, commonmark_render);
735
- cmark_syntax_extension_set_latex_render_func(ext, latex_render);
736
- cmark_syntax_extension_set_man_render_func(ext, man_render);
737
- cmark_syntax_extension_set_html_render_func(ext, html_render);
738
- cmark_syntax_extension_set_opaque_free_func(ext, opaque_free);
739
- cmark_syntax_extension_set_commonmark_escape_func(ext, escape);
736
+ cmark_syntax_extension *self = cmark_syntax_extension_new("table");
737
+
738
+ cmark_syntax_extension_set_match_block_func(self, matches);
739
+ cmark_syntax_extension_set_open_block_func(self, try_opening_table_block);
740
+ cmark_syntax_extension_set_get_type_string_func(self, get_type_string);
741
+ cmark_syntax_extension_set_can_contain_func(self, can_contain);
742
+ cmark_syntax_extension_set_contains_inlines_func(self, contains_inlines);
743
+ cmark_syntax_extension_set_commonmark_render_func(self, commonmark_render);
744
+ cmark_syntax_extension_set_latex_render_func(self, latex_render);
745
+ cmark_syntax_extension_set_man_render_func(self, man_render);
746
+ cmark_syntax_extension_set_html_render_func(self, html_render);
747
+ cmark_syntax_extension_set_opaque_free_func(self, opaque_free);
748
+ cmark_syntax_extension_set_commonmark_escape_func(self, escape);
749
+ cmark_syntax_extension_set_postprocess_func(self, postprocess);
740
750
  CMARK_NODE_TABLE = cmark_syntax_extension_add_node(0);
741
751
  CMARK_NODE_TABLE_ROW = cmark_syntax_extension_add_node(0);
742
752
  CMARK_NODE_TABLE_CELL = cmark_syntax_extension_add_node(0);
743
753
 
744
- return ext;
754
+ return self;
745
755
  }
@@ -380,6 +380,30 @@ This shouldn't assert.
380
380
  </tr></tbody></table>
381
381
  ````````````````````````````````
382
382
 
383
+ ### Reference-style links
384
+
385
+ ```````````````````````````````` example
386
+ Here's a link to [Freedom Planet 2][].
387
+
388
+ | Here's a link to [Freedom Planet 2][] in a table header. |
389
+ | --- |
390
+ | Here's a link to [Freedom Planet 2][] in a table row. |
391
+
392
+ [Freedom Planet 2]: http://www.freedomplanet2.com/
393
+ .
394
+ <p>Here's a link to <a href="http://www.freedomplanet2.com/">Freedom Planet 2</a>.</p>
395
+ <table>
396
+ <thead>
397
+ <tr>
398
+ <th>Here's a link to <a href="http://www.freedomplanet2.com/">Freedom Planet 2</a> in a table header.</th>
399
+ </tr>
400
+ </thead>
401
+ <tbody>
402
+ <tr>
403
+ <td>Here's a link to <a href="http://www.freedomplanet2.com/">Freedom Planet 2</a> in a table row.</td>
404
+ </tr></tbody></table>
405
+ ````````````````````````````````
406
+
383
407
 
384
408
  ## Strikethroughs
385
409
 
@@ -1,3 +1,3 @@
1
1
  module CommonMarker
2
- VERSION = '0.14.7'.freeze
2
+ VERSION = '0.14.8'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: commonmarker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.7
4
+ version: 0.14.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Garen Torikian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-13 00:00:00.000000000 Z
11
+ date: 2017-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-enum