commonmarker 0.18.2 → 0.19.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of commonmarker might be problematic. Click here for more details.

Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -3
  3. data/Rakefile +10 -3
  4. data/bin/commonmarker +3 -1
  5. data/commonmarker.gemspec +7 -2
  6. data/ext/commonmarker/cmark-gfm-core-extensions.h +3 -0
  7. data/ext/commonmarker/cmark-gfm_version.h +2 -2
  8. data/ext/commonmarker/commonmark.c +4 -2
  9. data/ext/commonmarker/commonmarker.c +15 -0
  10. data/ext/commonmarker/core-extensions.c +2 -0
  11. data/ext/commonmarker/ext_scanners.c +738 -520
  12. data/ext/commonmarker/ext_scanners.h +2 -0
  13. data/ext/commonmarker/extconf.rb +3 -1
  14. data/ext/commonmarker/houdini_href_e.c +1 -1
  15. data/ext/commonmarker/inlines.c +4 -3
  16. data/ext/commonmarker/render.c +2 -1
  17. data/ext/commonmarker/scanners.c +2 -2
  18. data/ext/commonmarker/table.c +5 -3
  19. data/ext/commonmarker/tasklist.c +135 -0
  20. data/ext/commonmarker/tasklist.h +8 -0
  21. data/lib/commonmarker.rb +2 -0
  22. data/lib/commonmarker/config.rb +3 -1
  23. data/lib/commonmarker/node.rb +2 -0
  24. data/lib/commonmarker/renderer.rb +6 -2
  25. data/lib/commonmarker/renderer/html_renderer.rb +24 -2
  26. data/lib/commonmarker/version.rb +3 -1
  27. data/test/benchmark.rb +3 -1
  28. data/test/test_attributes.rb +3 -1
  29. data/test/test_basics.rb +2 -0
  30. data/test/test_commonmark.rb +2 -0
  31. data/test/test_doc.rb +2 -0
  32. data/test/test_encoding.rb +2 -0
  33. data/test/test_extensions.rb +24 -22
  34. data/test/test_footnotes.rb +2 -0
  35. data/test/test_gc.rb +4 -2
  36. data/test/test_helper.rb +11 -8
  37. data/test/test_linebreaks.rb +2 -0
  38. data/test/test_maliciousness.rb +2 -0
  39. data/test/test_node.rb +3 -1
  40. data/test/test_options.rb +2 -0
  41. data/test/test_pathological_inputs.rb +2 -0
  42. data/test/test_plaintext.rb +2 -0
  43. data/test/test_renderer.rb +2 -0
  44. data/test/test_smartpunct.rb +2 -0
  45. data/test/test_spec.rb +2 -0
  46. data/test/test_tasklists.rb +27 -0
  47. metadata +55 -9
@@ -11,11 +11,13 @@ bufsize_t _scan_table_start(const unsigned char *p);
11
11
  bufsize_t _scan_table_cell(const unsigned char *p);
12
12
  bufsize_t _scan_table_cell_end(const unsigned char *p);
13
13
  bufsize_t _scan_table_row_end(const unsigned char *p);
14
+ bufsize_t _scan_tasklist(const unsigned char *p);
14
15
 
15
16
  #define scan_table_start(c, l, n) _ext_scan_at(&_scan_table_start, c, l, n)
16
17
  #define scan_table_cell(c, l, n) _ext_scan_at(&_scan_table_cell, c, l, n)
17
18
  #define scan_table_cell_end(c, l, n) _ext_scan_at(&_scan_table_cell_end, c, l, n)
18
19
  #define scan_table_row_end(c, l, n) _ext_scan_at(&_scan_table_row_end, c, l, n)
20
+ #define scan_tasklist(c, l, n) _ext_scan_at(&_scan_tasklist, c, l, n)
19
21
 
20
22
  #ifdef __cplusplus
21
23
  }
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'mkmf'
2
4
 
3
- $CFLAGS << " -std=c99"
5
+ $CFLAGS << ' -std=c99'
4
6
 
5
7
  create_makefile('commonmarker/commonmarker')
@@ -15,7 +15,7 @@
15
15
  * - The characters which are *not* safe to be in
16
16
  * an URL because they are RESERVED characters.
17
17
  *
18
- * We asume (lazily) that any RESERVED char that
18
+ * We assume (lazily) that any RESERVED char that
19
19
  * appears inside an URL is actually meant to
20
20
  * have its native function (i.e. as an URL
21
21
  * component/separator) and hence needs no escaping.
@@ -760,9 +760,10 @@ static delimiter *S_insert_emph(subject *subj, delimiter *opener,
760
760
  }
761
761
  cmark_node_insert_after(opener_inl, emph);
762
762
 
763
- emph->start_line = emph->end_line = subj->line;
764
- emph->start_column = opener_inl->start_column + subj->column_offset;
765
- emph->end_column = closer_inl->end_column + subj->column_offset;
763
+ emph->start_line = opener_inl->start_line;
764
+ emph->end_line = closer_inl->end_line;
765
+ emph->start_column = opener_inl->start_column;
766
+ emph->end_column = closer_inl->end_column;
766
767
 
767
768
  // if opener has 0 characters, remove it and its associated inline
768
769
  if (opener_num_chars == 0) {
@@ -57,6 +57,7 @@ static void S_out(cmark_renderer *renderer, cmark_node *node,
57
57
  }
58
58
  }
59
59
  renderer->column = 0;
60
+ renderer->last_breakable = 0;
60
61
  renderer->begin_line = true;
61
62
  renderer->begin_content = true;
62
63
  renderer->need_cr -= 1;
@@ -188,7 +189,7 @@ char *cmark_render(cmark_mem *mem, cmark_node *root, int options, int width,
188
189
  }
189
190
 
190
191
  // ensure final newline
191
- if (renderer.buffer->ptr[renderer.buffer->size - 1] != '\n') {
192
+ if (renderer.buffer->size == 0 || renderer.buffer->ptr[renderer.buffer->size - 1] != '\n') {
192
193
  cmark_strbuf_putc(renderer.buffer, '\n');
193
194
  }
194
195
 
@@ -1,4 +1,4 @@
1
- /* Generated by re2c 1.0.3 */
1
+ /* Generated by re2c 1.1.1 */
2
2
  #include <stdlib.h>
3
3
  #include "chunk.h"
4
4
  #include "scanners.h"
@@ -9226,7 +9226,7 @@ bufsize_t _scan_open_code_fence(const unsigned char *p)
9226
9226
  144, 192, 192, 192, 192, 192, 192, 192,
9227
9227
  192, 192, 192, 192, 192, 192, 192, 192,
9228
9228
  192, 192, 192, 192, 192, 192, 192, 192,
9229
- 192, 192, 192, 192, 192, 192, 96, 192,
9229
+ 192, 192, 192, 192, 192, 192, 224, 192,
9230
9230
  0, 0, 0, 0, 0, 0, 0, 0,
9231
9231
  0, 0, 0, 0, 0, 0, 0, 0,
9232
9232
  0, 0, 0, 0, 0, 0, 0, 0,
@@ -114,7 +114,7 @@ static table_row *row_from_string(cmark_syntax_extension *self,
114
114
  cmark_parser *parser, unsigned char *string,
115
115
  int len) {
116
116
  table_row *row = NULL;
117
- bufsize_t cell_matched, pipe_matched, offset;
117
+ bufsize_t cell_matched = 1, pipe_matched = 1, offset;
118
118
 
119
119
  row = (table_row *)parser->mem->calloc(1, sizeof(table_row));
120
120
  row->n_columns = 0;
@@ -122,7 +122,9 @@ static table_row *row_from_string(cmark_syntax_extension *self,
122
122
 
123
123
  offset = scan_table_cell_end(string, len, 0);
124
124
 
125
- do {
125
+ // Parse the cells of the row. Stop if we reach the end of the input, or if we
126
+ // cannot detect any more cells.
127
+ while (offset < len && (cell_matched || pipe_matched)) {
126
128
  cell_matched = scan_table_cell(string, len, offset);
127
129
  pipe_matched = scan_table_cell_end(string, len, offset + cell_matched);
128
130
 
@@ -149,7 +151,7 @@ static table_row *row_from_string(cmark_syntax_extension *self,
149
151
  pipe_matched = scan_table_row_end(string, len, offset);
150
152
  offset += pipe_matched;
151
153
  }
152
- } while ((cell_matched || pipe_matched) && offset < len);
154
+ }
153
155
 
154
156
  if (offset != len || !row->n_columns) {
155
157
  free_table_row(parser->mem, row);
@@ -0,0 +1,135 @@
1
+ #include "tasklist.h"
2
+ #include <parser.h>
3
+ #include <render.h>
4
+ #include <html.h>
5
+ #include "ext_scanners.h"
6
+
7
+ typedef enum {
8
+ CMARK_TASKLIST_NOCHECKED,
9
+ CMARK_TASKLIST_CHECKED,
10
+ } cmark_tasklist_type;
11
+
12
+ static const char *get_type_string(cmark_syntax_extension *extension, cmark_node *node) {
13
+ return "tasklist";
14
+ }
15
+
16
+ char *cmark_gfm_extensions_get_tasklist_state(cmark_node *node) {
17
+ if (!node || ((int)node->as.opaque != CMARK_TASKLIST_CHECKED && (int)node->as.opaque != CMARK_TASKLIST_NOCHECKED))
18
+ return 0;
19
+
20
+ if ((int)node->as.opaque != CMARK_TASKLIST_CHECKED) {
21
+ return "checked";
22
+ }
23
+ else {
24
+ return "unchecked";
25
+ }
26
+ }
27
+
28
+ static bool parse_node_item_prefix(cmark_parser *parser, const char *input,
29
+ cmark_node *container) {
30
+ bool res = false;
31
+
32
+ if (parser->indent >=
33
+ container->as.list.marker_offset + container->as.list.padding) {
34
+ cmark_parser_advance_offset(parser, input, container->as.list.marker_offset +
35
+ container->as.list.padding,
36
+ true);
37
+ res = true;
38
+ } else if (parser->blank && container->first_child != NULL) {
39
+ // if container->first_child is NULL, then the opening line
40
+ // of the list item was blank after the list marker; in this
41
+ // case, we are done with the list item.
42
+ cmark_parser_advance_offset(parser, input, parser->first_nonspace - parser->offset,
43
+ false);
44
+ res = true;
45
+ }
46
+ return res;
47
+ }
48
+
49
+ static int matches(cmark_syntax_extension *self, cmark_parser *parser,
50
+ unsigned char *input, int len,
51
+ cmark_node *parent_container) {
52
+ return parse_node_item_prefix(parser, (const char*)input, parent_container);
53
+ }
54
+
55
+ static int can_contain(cmark_syntax_extension *extension, cmark_node *node,
56
+ cmark_node_type child_type) {
57
+ return (node->type == CMARK_NODE_ITEM) ? 1 : 0;
58
+ }
59
+
60
+ static cmark_node *open_tasklist_item(cmark_syntax_extension *self,
61
+ int indented, cmark_parser *parser,
62
+ cmark_node *parent_container,
63
+ unsigned char *input, int len) {
64
+ cmark_node_type node_type = cmark_node_get_type(parent_container);
65
+ if (node_type != CMARK_NODE_ITEM) {
66
+ return NULL;
67
+ }
68
+
69
+ bufsize_t matched = scan_tasklist(input, len, 0);
70
+ if (!matched) {
71
+ return NULL;
72
+ }
73
+
74
+ cmark_node_set_syntax_extension(parent_container, self);
75
+ cmark_parser_advance_offset(parser, (char *)input, 3, false);
76
+
77
+ if (strstr((char*)input, "[x]")) {
78
+ parent_container->as.opaque = (void *)CMARK_TASKLIST_CHECKED;
79
+ } else {
80
+ parent_container->as.opaque = (void *)CMARK_TASKLIST_NOCHECKED;
81
+ }
82
+
83
+ return NULL;
84
+ }
85
+
86
+ static void commonmark_render(cmark_syntax_extension *extension,
87
+ cmark_renderer *renderer, cmark_node *node,
88
+ cmark_event_type ev_type, int options) {
89
+ bool entering = (ev_type == CMARK_EVENT_ENTER);
90
+ if (entering) {
91
+ renderer->cr(renderer);
92
+ if ((int)node->as.opaque == CMARK_TASKLIST_CHECKED) {
93
+ renderer->out(renderer, node, "- [x] ", false, LITERAL);
94
+ } else {
95
+ renderer->out(renderer, node, "- [ ] ", false, LITERAL);
96
+ }
97
+ cmark_strbuf_puts(renderer->prefix, " ");
98
+ } else {
99
+ cmark_strbuf_truncate(renderer->prefix, renderer->prefix->size - 2);
100
+ renderer->cr(renderer);
101
+ }
102
+ }
103
+
104
+ static void html_render(cmark_syntax_extension *extension,
105
+ cmark_html_renderer *renderer, cmark_node *node,
106
+ cmark_event_type ev_type, int options) {
107
+ bool entering = (ev_type == CMARK_EVENT_ENTER);
108
+ if (entering) {
109
+ cmark_html_render_cr(renderer->html);
110
+ cmark_strbuf_puts(renderer->html, "<li");
111
+ cmark_html_render_sourcepos(node, renderer->html, options);
112
+ cmark_strbuf_putc(renderer->html, '>');
113
+ if ((int)node->as.opaque == CMARK_TASKLIST_CHECKED) {
114
+ cmark_strbuf_puts(renderer->html, "<input type=\"checkbox\" checked=\"\" disabled=\"\" /> ");
115
+ } else {
116
+ cmark_strbuf_puts(renderer->html, "<input type=\"checkbox\" disabled=\"\" /> ");
117
+ }
118
+ } else {
119
+ cmark_strbuf_puts(renderer->html, "</li>\n");
120
+ }
121
+ }
122
+
123
+ cmark_syntax_extension *create_tasklist_extension(void) {
124
+ cmark_syntax_extension *ext = cmark_syntax_extension_new("tasklist");
125
+
126
+ cmark_syntax_extension_set_match_block_func(ext, matches);
127
+ cmark_syntax_extension_set_get_type_string_func(ext, get_type_string);
128
+ cmark_syntax_extension_set_open_block_func(ext, open_tasklist_item);
129
+ cmark_syntax_extension_set_can_contain_func(ext, can_contain);
130
+ cmark_syntax_extension_set_commonmark_render_func(ext, commonmark_render);
131
+ cmark_syntax_extension_set_plaintext_render_func(ext, commonmark_render);
132
+ cmark_syntax_extension_set_html_render_func(ext, html_render);
133
+
134
+ return ext;
135
+ }
@@ -0,0 +1,8 @@
1
+ #ifndef TASKLIST_H
2
+ #define TASKLIST_H
3
+
4
+ #include "cmark-gfm-core-extensions.h"
5
+
6
+ cmark_syntax_extension *create_tasklist_extension(void);
7
+
8
+ #endif
data/lib/commonmarker.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  require 'commonmarker/commonmarker'
3
5
  require 'commonmarker/config'
4
6
  require 'commonmarker/node'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'ruby-enum'
2
4
  module CommonMarker
3
5
  # For Ruby::Enum, these must be classes, not modules
@@ -37,7 +39,7 @@ module CommonMarker
37
39
  # neckbearding around. the map will both check the opts and then bitwise-OR it
38
40
  option.map { |o| check_option(o, type); type.to_h[o] }.inject(0, :|)
39
41
  else
40
- raise TypeError, 'option type must be a valid symbol or array of symbols'
42
+ raise TypeError, "option type must be a valid symbol or array of symbols within the #{type} context"
41
43
  end
42
44
  end
43
45
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'commonmarker/node/inspect'
2
4
 
3
5
  module CommonMarker
@@ -1,3 +1,7 @@
1
+ # frozen_string_literal: true
2
+ # rubocop:disable Standard/RailsViewRenderLiteral
3
+ # rubocop:disable Standard/RailsControllerRenderLiteral
4
+
1
5
  require 'set'
2
6
  require 'stringio'
3
7
 
@@ -6,7 +10,7 @@ module CommonMarker
6
10
  attr_accessor :in_tight, :warnings, :in_plain
7
11
  def initialize(options: :DEFAULT, extensions: [])
8
12
  @opts = Config.process_options(options, :render)
9
- @stream = StringIO.new("".force_encoding("utf-8"))
13
+ @stream = StringIO.new(''.dup.force_encoding('utf-8'))
10
14
  @need_blocksep = false
11
15
  @warnings = Set.new []
12
16
  @in_tight = false
@@ -116,7 +120,7 @@ module CommonMarker
116
120
  end
117
121
 
118
122
  def sourcepos(node)
119
- return "" unless option_enabled?(:SOURCEPOS)
123
+ return '' unless option_enabled?(:SOURCEPOS)
120
124
  s = node.sourcepos
121
125
  " data-sourcepos=\"#{s[:start_line]}:#{s[:start_column]}-" \
122
126
  "#{s[:end_line]}:#{s[:end_column]}\""
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module CommonMarker
2
4
  class HtmlRenderer < Renderer
3
5
  def render(node)
@@ -26,7 +28,7 @@ module CommonMarker
26
28
  container("<p#{sourcepos(node)}>", '</p>') do
27
29
  out(:children)
28
30
  if node.parent.type == :footnote_definition && node.next.nil?
29
- out(" ")
31
+ out(' ')
30
32
  out_footnote_backref
31
33
  end
32
34
  end
@@ -60,12 +62,23 @@ module CommonMarker
60
62
 
61
63
  def list_item(node)
62
64
  block do
63
- container("<li#{sourcepos(node)}>", '</li>') do
65
+ tasklist_data = tasklist(node)
66
+ container("<li#{sourcepos(node)}#{tasklist_data}>#{' ' if tasklist?(node)}", '</li>') do
64
67
  out(:children)
65
68
  end
66
69
  end
67
70
  end
68
71
 
72
+ def tasklist(node)
73
+ return '' unless tasklist?(node)
74
+ state = if checked?(node)
75
+ 'disabled=""'
76
+ else
77
+ 'checked="" disabled=""'
78
+ end
79
+ return "><input type=\"checkbox\" #{state} /"
80
+ end
81
+
69
82
  def blockquote(node)
70
83
  block do
71
84
  container("<blockquote#{sourcepos(node)}>\n", '</blockquote>') do
@@ -239,5 +252,14 @@ module CommonMarker
239
252
  out("<a href=\"#fnref#@footnote_ix\" class=\"footnote-backref\">↩</a>")
240
253
  true
241
254
  end
255
+
256
+ def tasklist?(node)
257
+ node.type_string == 'tasklist'
258
+ end
259
+
260
+ def checked?(node)
261
+ node.tasklist_state == 'checked'
262
+ end
263
+
242
264
  end
243
265
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module CommonMarker
2
- VERSION = '0.18.2'.freeze
4
+ VERSION = '0.19.0'.freeze
3
5
  end
data/test/benchmark.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'commonmarker'
2
4
  require 'github/markdown'
3
5
  require 'redcarpet'
@@ -9,7 +11,7 @@ def dobench(name, &blk)
9
11
  puts Benchmark.measure(&blk)
10
12
  end
11
13
 
12
- benchinput = File.open('test/benchinput.md', 'r').read()
14
+ benchinput = File.open('test/benchinput.md', 'r').read
13
15
 
14
16
  printf("input size = %d bytes\n\n", benchinput.bytesize)
15
17
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_helper'
2
4
 
3
5
  class TestAttributes < Minitest::Test
@@ -15,7 +17,7 @@ class TestAttributes < Minitest::Test
15
17
 
16
18
  sourcepos.delete_if { |h| h.values.all? { |v| v == 0 } }
17
19
 
18
- result = [{:start_line=>1, :start_column=>1, :end_line=>10, :end_column=>12}, {:start_line=>1, :start_column=>1, :end_line=>1, :end_column=>17}, {:start_line=>1, :start_column=>4, :end_line=>1, :end_column=>17}, {:start_line=>3, :start_column=>1, :end_line=>5, :end_column=>36}, {:start_line=>3, :start_column=>1, :end_line=>3, :end_column=>55}, {:start_line=>4, :start_column=>1, :end_line=>4, :end_column=>53}, {:start_line=>4, :start_column=>2, :end_line=>4, :end_column=>14}, {:start_line=>4, :start_column=>54, :end_line=>4, :end_column=>58}, {:start_line=>5, :start_column=>1, :end_line=>5, :end_column=>36}, {:start_line=>7, :start_column=>1, :end_line=>10, :end_column=>12}, {:start_line=>7, :start_column=>1, :end_line=>7, :end_column=>11}, {:start_line=>7, :start_column=>4, :end_line=>7, :end_column=>11}, {:start_line=>7, :start_column=>4, :end_line=>7, :end_column=>11}, {:start_line=>8, :start_column=>1, :end_line=>10, :end_column=>12}, {:start_line=>8, :start_column=>4, :end_line=>8, :end_column=>11}, {:start_line=>8, :start_column=>4, :end_line=>8, :end_column=>11}, {:start_line=>9, :start_column=>4, :end_line=>10, :end_column=>12}, {:start_line=>9, :start_column=>4, :end_line=>9, :end_column=>12}, {:start_line=>9, :start_column=>6, :end_line=>9, :end_column=>12}, {:start_line=>9, :start_column=>6, :end_line=>9, :end_column=>12}, {:start_line=>10, :start_column=>4, :end_line=>10, :end_column=>12}, {:start_line=>10, :start_column=>6, :end_line=>10, :end_column=>12}, {:start_line=>10, :start_column=>6, :end_line=>10, :end_column=>12}]
20
+ result = [{start_line: 1, start_column: 1, end_line: 10, end_column: 12}, {start_line: 1, start_column: 1, end_line: 1, end_column: 17}, {start_line: 1, start_column: 4, end_line: 1, end_column: 17}, {start_line: 3, start_column: 1, end_line: 5, end_column: 36}, {start_line: 3, start_column: 1, end_line: 3, end_column: 55}, {start_line: 4, start_column: 1, end_line: 4, end_column: 53}, {start_line: 4, start_column: 2, end_line: 4, end_column: 14}, {start_line: 4, start_column: 54, end_line: 4, end_column: 58}, {start_line: 5, start_column: 1, end_line: 5, end_column: 36}, {start_line: 7, start_column: 1, end_line: 10, end_column: 12}, {start_line: 7, start_column: 1, end_line: 7, end_column: 11}, {start_line: 7, start_column: 4, end_line: 7, end_column: 11}, {start_line: 7, start_column: 4, end_line: 7, end_column: 11}, {start_line: 8, start_column: 1, end_line: 10, end_column: 12}, {start_line: 8, start_column: 4, end_line: 8, end_column: 11}, {start_line: 8, start_column: 4, end_line: 8, end_column: 11}, {start_line: 9, start_column: 4, end_line: 10, end_column: 12}, {start_line: 9, start_column: 4, end_line: 9, end_column: 12}, {start_line: 9, start_column: 6, end_line: 9, end_column: 12}, {start_line: 9, start_column: 6, end_line: 9, end_column: 12}, {start_line: 10, start_column: 4, end_line: 10, end_column: 12}, {start_line: 10, start_column: 6, end_line: 10, end_column: 12}, {start_line: 10, start_column: 6, end_line: 10, end_column: 12}]
19
21
 
20
22
  assert_equal result, sourcepos
21
23
  end
data/test/test_basics.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_helper'
2
4
 
3
5
  class TestBasics < Minitest::Test
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_helper'
2
4
 
3
5
  class TestCommonmark < Minitest::Test
data/test/test_doc.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_helper'
2
4
 
3
5
  class TestDocNode < Minitest::Test
@@ -1,4 +1,6 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
3
+
2
4
  require 'test_helper'
3
5
 
4
6
  class TestEncoding < Minitest::Test
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_helper'
2
4
 
3
5
  class TestExtensions < Minitest::Test
@@ -18,30 +20,30 @@ Another extension:
18
20
 
19
21
  def test_uses_specified_extensions
20
22
  CommonMarker.render_html(@markdown, :DEFAULT, %i[]).tap do |out|
21
- assert out.include?("| a")
22
- assert out.include?("| <strong>x</strong>")
23
- assert out.include?("~~hi~~")
23
+ assert out.include?('| a')
24
+ assert out.include?('| <strong>x</strong>')
25
+ assert out.include?('~~hi~~')
24
26
  end
25
27
 
26
28
  CommonMarker.render_html(@markdown, :DEFAULT, %i[table]).tap do |out|
27
- refute out.include?("| a")
28
- %w(<table> <tr> <th> a </th> <td> c </td> <strong>x</strong>).each {|html| assert out.include?(html) }
29
- assert out.include?("~~hi~~")
29
+ refute out.include?('| a')
30
+ %w(<table> <tr> <th> a </th> <td> c </td> <strong>x</strong>).each { |html| assert out.include?(html) }
31
+ assert out.include?('~~hi~~')
30
32
  end
31
33
 
32
34
  CommonMarker.render_html(@markdown, :DEFAULT, %i[strikethrough]).tap do |out|
33
- assert out.include?("| a")
34
- refute out.include?("~~hi~~")
35
- assert out.include?("<del>hi</del>")
35
+ assert out.include?('| a')
36
+ refute out.include?('~~hi~~')
37
+ assert out.include?('<del>hi</del>')
36
38
  end
37
39
 
38
- doc = CommonMarker.render_doc("~a~ ~~b~~ ~~~c~~~", :STRIKETHROUGH_DOUBLE_TILDE, [:strikethrough])
40
+ doc = CommonMarker.render_doc('~a~ ~~b~~ ~~~c~~~', :STRIKETHROUGH_DOUBLE_TILDE, [:strikethrough])
39
41
  assert_equal doc.to_html, "<p>~a~ <del>b</del> ~~~c~~~</p>\n"
40
42
 
41
43
  CommonMarker.render_html(@markdown, :DEFAULT, %i[table strikethrough]).tap do |out|
42
- refute out.include?("| a")
43
- refute out.include?("| <strong>x</strong>")
44
- refute out.include?("~~hi~~")
44
+ refute out.include?('| a')
45
+ refute out.include?('| <strong>x</strong>')
46
+ refute out.include?('~~hi~~')
45
47
  end
46
48
 
47
49
  end
@@ -50,24 +52,24 @@ Another extension:
50
52
  doc = CommonMarker.render_doc(@markdown, :DEFAULT, %i[table])
51
53
 
52
54
  doc.to_html.tap do |out|
53
- refute out.include?("| a")
54
- %w(<table> <tr> <th> a </th> <td> c </td> <strong>x</strong>).each {|html| assert out.include?(html) }
55
- assert out.include?("~~hi~~")
55
+ refute out.include?('| a')
56
+ %w(<table> <tr> <th> a </th> <td> c </td> <strong>x</strong>).each { |html| assert out.include?(html) }
57
+ assert out.include?('~~hi~~')
56
58
  end
57
59
 
58
60
  HtmlRenderer.new.render(doc).tap do |out|
59
- refute out.include?("| a")
60
- %w(<table> <tr> <th> a </th> <td> c </td> <strong>x</strong>).each {|html| assert out.include?(html) }
61
- assert out.include?("~~hi~~")
61
+ refute out.include?('| a')
62
+ %w(<table> <tr> <th> a </th> <td> c </td> <strong>x</strong>).each { |html| assert out.include?(html) }
63
+ assert out.include?('~~hi~~')
62
64
  end
63
65
 
64
- doc = CommonMarker.render_doc("~a~ ~~b~~ ~~~c~~~", :STRIKETHROUGH_DOUBLE_TILDE, [:strikethrough])
66
+ doc = CommonMarker.render_doc('~a~ ~~b~~ ~~~c~~~', :STRIKETHROUGH_DOUBLE_TILDE, [:strikethrough])
65
67
  assert_equal HtmlRenderer.new.render(doc), "<p>~a~ <del>b</del> ~~~c~~~</p>\n"
66
68
  end
67
69
 
68
70
  def test_bad_extension_specifications
69
- assert_raises(TypeError) { CommonMarker.render_html(@markdown, :DEFAULT, "nope") }
70
- assert_raises(TypeError) { CommonMarker.render_html(@markdown, :DEFAULT, ["table"]) }
71
+ assert_raises(TypeError) { CommonMarker.render_html(@markdown, :DEFAULT, 'nope') }
72
+ assert_raises(TypeError) { CommonMarker.render_html(@markdown, :DEFAULT, ['table']) }
71
73
  assert_raises(ArgumentError) { CommonMarker.render_html(@markdown, :DEFAULT, %i[table bad]) }
72
74
  end
73
75