commonmarker 0.20.1 → 0.22.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.

data/test/test_node.rb CHANGED
@@ -12,7 +12,7 @@ class TestNode < Minitest::Test
12
12
  @doc.walk do |node|
13
13
  nodes << node.type
14
14
  end
15
- assert_equal [:document, :paragraph, :text, :emph, :text, :text], nodes
15
+ assert_equal %i[document paragraph text emph text text], nodes
16
16
  end
17
17
 
18
18
  def test_each
@@ -20,29 +20,29 @@ class TestNode < Minitest::Test
20
20
  @doc.first_child.each do |node|
21
21
  nodes << node.type
22
22
  end
23
- assert_equal [:text, :emph, :text], nodes
23
+ assert_equal %i[text emph text], nodes
24
24
  end
25
25
 
26
26
  def test_deprecated_each_child
27
27
  nodes = []
28
- out, err = capture_io do
28
+ _, err = capture_io do
29
29
  @doc.first_child.each_child do |node|
30
30
  nodes << node.type
31
31
  end
32
32
  end
33
- assert_equal [:text, :emph, :text], nodes
34
- assert_match /`each_child` is deprecated/, err
33
+ assert_equal %i[text emph text], nodes
34
+ assert_match(/`each_child` is deprecated/, err)
35
35
  end
36
36
 
37
37
  def test_select
38
38
  nodes = @doc.first_child.select { |node| node.type == :text }
39
39
  assert_equal CommonMarker::Node, nodes.first.class
40
- assert_equal [:text, :text], nodes.map(&:type)
40
+ assert_equal %i[text text], nodes.map(&:type)
41
41
  end
42
42
 
43
43
  def test_map
44
44
  nodes = @doc.first_child.map(&:type)
45
- assert_equal [:text, :emph, :text], nodes
45
+ assert_equal %i[text emph text], nodes
46
46
  end
47
47
 
48
48
  def test_insert_illegal
@@ -63,9 +63,7 @@ class TestNode < Minitest::Test
63
63
 
64
64
  def test_walk_and_set_string_content
65
65
  @doc.walk do |node|
66
- if node.type == :text && node.string_content == 'there'
67
- node.string_content = 'world'
68
- end
66
+ node.string_content = 'world' if node.type == :text && node.string_content == 'there'
69
67
  end
70
68
  result = HtmlRenderer.new.render(@doc)
71
69
  assert_equal "<p>Hi <em>world</em>, I am mostly text!</p>\n", result
@@ -82,10 +80,10 @@ class TestNode < Minitest::Test
82
80
  end
83
81
 
84
82
  def test_inspect
85
- assert_match /#<CommonMarker::Node\(document\):/, @doc.inspect
83
+ assert_match(/#<CommonMarker::Node\(document\):/, @doc.inspect)
86
84
  end
87
85
 
88
86
  def test_pretty_print
89
- assert_match /#<CommonMarker::Node\(document\):/, PP.pp(@doc, ''.dup)
87
+ assert_match(/#<CommonMarker::Node\(document\):/, PP.pp(@doc, +''))
90
88
  end
91
89
  end
data/test/test_options.rb CHANGED
@@ -4,34 +4,34 @@ require 'test_helper'
4
4
 
5
5
  class TestExtensions < Minitest::Test
6
6
  def test_full_info_string
7
- md = <<-MD
8
- ```ruby
9
- module Foo
10
- ```
7
+ md = <<~MD
8
+ ```ruby
9
+ module Foo
10
+ ```
11
11
  MD
12
12
 
13
13
  CommonMarker.render_html(md, :FULL_INFO_STRING).tap do |out|
14
- assert_includes out, %q(<pre><code class="language-ruby">)
14
+ assert_includes out, '<pre><code class="language-ruby">'
15
15
  end
16
16
 
17
- md = <<-MD
18
- ```ruby my info string
19
- module Foo
20
- ```
17
+ md = <<~MD
18
+ ```ruby my info string
19
+ module Foo
20
+ ```
21
21
  MD
22
22
 
23
23
  CommonMarker.render_html(md, :FULL_INFO_STRING).tap do |out|
24
- assert_includes out, %q(<pre><code class="language-ruby" data-meta="my info string">)
24
+ assert_includes out, '<pre><code class="language-ruby" data-meta="my info string">'
25
25
  end
26
26
 
27
- md = <<-MD
28
- ```ruby my \x00 string
29
- module Foo
30
- ```
27
+ md = <<~MD
28
+ ```ruby my \x00 string
29
+ module Foo
30
+ ```
31
31
  MD
32
32
 
33
33
  CommonMarker.render_html(md, :FULL_INFO_STRING).tap do |out|
34
- assert_includes out, %Q(<pre><code class="language-ruby" data-meta="my � string">)
34
+ assert_includes out, %(<pre><code class="language-ruby" data-meta="my � string">)
35
35
  end
36
36
  end
37
37
  end
@@ -3,14 +3,14 @@
3
3
  require 'test_helper'
4
4
  require 'minitest/benchmark' if ENV['BENCH']
5
5
 
6
- def markdown(s)
7
- CommonMarker.render_doc(s).to_html
6
+ def markdown(str)
7
+ CommonMarker.render_doc(str).to_html
8
8
  end
9
9
 
10
10
  # list of pairs consisting of input and a regex that must match the output.
11
11
  pathological = {
12
12
  'nested strong emph' =>
13
- [('*a **a ' * 65_000) + 'b' + (' a** a*' * 65_000),
13
+ ["#{'*a **a ' * 65_000}b#{' a** a*' * 65_000}",
14
14
  Regexp.compile('(<em>a <strong>a ){65_000}b( a</strong> a</em>){65_000}')],
15
15
  'many emph closers with no openers' =>
16
16
  [('a_ ' * 65_000),
@@ -34,10 +34,10 @@ pathological = {
34
34
  ['**x [a*b**c*](d)',
35
35
  Regexp.compile('\\*\\*x <a href=\'d\'>a<em>b</em><em>c</em></a>')],
36
36
  'nested brackets' =>
37
- [('[' * 50_000) + 'a' + (']' * 50_000),
37
+ ["#{'[' * 50_000}a#{']' * 50_000}",
38
38
  Regexp.compile('\[{50000}a\]{50000}')],
39
39
  'nested block quotes' =>
40
- [(('> ' * 50_000) + 'a'),
40
+ ["#{'> ' * 50_000}a",
41
41
  Regexp.compile('(<blockquote>\n){50000}')],
42
42
  'U+0000 in input' =>
43
43
  ['abc\u0000de\u0000',
@@ -53,41 +53,41 @@ end
53
53
 
54
54
  if ENV['BENCH']
55
55
  class PathologicalInputsPerformanceTest < Minitest::Benchmark
56
- def bench_pathological_1
56
+ def test_bench_pathological_one
57
57
  assert_performance_linear 0.99 do |n|
58
58
  star = '*' * (n * 10)
59
59
  markdown("#{star}#{star}hi#{star}#{star}")
60
60
  end
61
61
  end
62
62
 
63
- def bench_pathological_2
63
+ def test_bench_pathological_two
64
64
  assert_performance_linear 0.99 do |n|
65
65
  c = '`t`t`t`t`t`t' * (n * 10)
66
66
  markdown(c)
67
67
  end
68
68
  end
69
69
 
70
- def bench_pathological_3
70
+ def test_bench_pathological_three
71
71
  assert_performance_linear 0.99 do |n|
72
72
  markdown(" [a]: #{'A' * n}\n\n#{'[a][]' * n}\n")
73
73
  end
74
74
  end
75
75
 
76
- def bench_pathological_4
76
+ def test_bench_pathological_four
77
77
  assert_performance_linear 0.5 do |n|
78
78
  markdown("#{'[' * n}a#{']' * n}")
79
79
  end
80
80
  end
81
81
 
82
- def bench_pathological_5
82
+ def test_bench_pathological_five
83
83
  assert_performance_linear 0.99 do |n|
84
84
  markdown("#{'**a *a ' * n}#{'a* a**' * n}")
85
85
  end
86
86
  end
87
87
 
88
- def bench_unbound_recursion
88
+ def test_bench_unbound_recursion
89
89
  assert_performance_linear 0.99 do |n|
90
- markdown(('[' * n) + 'foo' + ('](bar)' * n))
90
+ markdown("#{'[' * n}foo#{'](bar)' * n}")
91
91
  end
92
92
  end
93
93
  end
@@ -4,19 +4,19 @@ require 'test_helper'
4
4
 
5
5
  class TestPlaintext < Minitest::Test
6
6
  def setup
7
- @markdown = <<-MD
8
- Hi *there*!
7
+ @markdown = <<~MD
8
+ Hi *there*!
9
9
 
10
- 1. I am a numeric list.
11
- 2. I continue the list.
12
- * Suddenly, an unordered list!
13
- * What fun!
10
+ 1. I am a numeric list.
11
+ 2. I continue the list.
12
+ * Suddenly, an unordered list!
13
+ * What fun!
14
14
 
15
- Okay, _enough_.
15
+ Okay, _enough_.
16
16
 
17
- | a | b |
18
- | --- | --- |
19
- | c | d |
17
+ | a | b |
18
+ | --- | --- |
19
+ | c | d |
20
20
  MD
21
21
  end
22
22
 
@@ -27,20 +27,20 @@ Okay, _enough_.
27
27
  def test_to_commonmark
28
28
  compare = render_doc(@markdown).to_plaintext
29
29
 
30
- assert_equal <<-PLAINTEXT, compare
31
- Hi there!
30
+ assert_equal <<~PLAINTEXT, compare
31
+ Hi there!
32
32
 
33
- 1. I am a numeric list.
34
- 2. I continue the list.
33
+ 1. I am a numeric list.
34
+ 2. I continue the list.
35
35
 
36
- - Suddenly, an unordered list!
37
- - What fun!
36
+ - Suddenly, an unordered list!
37
+ - What fun!
38
38
 
39
- Okay, enough.
39
+ Okay, enough.
40
40
 
41
- | a | b |
42
- | --- | --- |
43
- | c | d |
44
- PLAINTEXT
41
+ | a | b |
42
+ | --- | --- |
43
+ | c | d |
44
+ PLAINTEXT
45
45
  end
46
46
  end
@@ -14,17 +14,34 @@ class TestRenderer < Minitest::Test
14
14
  end
15
15
 
16
16
  def test_multiple_tables
17
- content = '''
18
- | Input | Expected | Actual |
19
- | ----------- | ---------------- | --------- |
20
- | One | Two | Three |
21
-
22
- | Header | Row | Example |
23
- | :------: | ---: | :------ |
24
- | Foo | Bar | Baz |
25
- '''
26
- doc = CommonMarker.render_doc(content, :DEFAULT, [:autolink, :table, :tagfilter])
17
+ content = <<~DOC
18
+ | Input | Expected | Actual |
19
+ | ----------- | ---------------- | --------- |
20
+ | One | Two | Three |
21
+
22
+ | Header | Row | Example |
23
+ | :------: | ---: | :------ |
24
+ | Foo | Bar | Baz |
25
+ DOC
26
+ doc = CommonMarker.render_doc(content, :DEFAULT, %i[autolink table tagfilter])
27
27
  results = CommonMarker::HtmlRenderer.new.render(doc)
28
28
  assert_equal 2, results.scan(/<tbody>/).size
29
29
  end
30
+
31
+ def test_escape_html_encoding
32
+ my_renderer = Class.new(HtmlRenderer) do
33
+ attr_reader :input_encoding, :output_encoding
34
+
35
+ def text(node)
36
+ @input_encoding = node.string_content.encoding
37
+ escape_html(node.string_content).tap do |escaped|
38
+ @output_encoding = escaped.encoding
39
+ end
40
+ end
41
+ end
42
+
43
+ renderer = my_renderer.new
44
+ assert_equal Encoding::UTF_8, renderer.render(@doc).encoding
45
+ assert_equal renderer.input_encoding, renderer.output_encoding
46
+ end
30
47
  end
data/test/test_spec.rb CHANGED
@@ -8,6 +8,7 @@ class TestSpec < Minitest::Test
8
8
 
9
9
  spec.each do |testcase|
10
10
  next if testcase[:extensions].include?(:disabled)
11
+
11
12
  doc = CommonMarker.render_doc(testcase[:markdown], :DEFAULT, testcase[:extensions])
12
13
 
13
14
  define_method("test_to_html_example_#{testcase[:example]}") do
@@ -21,8 +22,8 @@ class TestSpec < Minitest::Test
21
22
  end
22
23
 
23
24
  define_method("test_sourcepos_example_#{testcase[:example]}") do
24
- lhs = doc.to_html([:UNSAFE, :SOURCEPOS], testcase[:extensions]).rstrip
25
- rhs = HtmlRenderer.new(options: [:UNSAFE, :SOURCEPOS], extensions: testcase[:extensions]).render(doc).rstrip
25
+ lhs = doc.to_html(%i[UNSAFE SOURCEPOS], testcase[:extensions]).rstrip
26
+ rhs = HtmlRenderer.new(options: %i[UNSAFE SOURCEPOS], extensions: testcase[:extensions]).render(doc).rstrip
26
27
  assert_equal lhs, rhs, testcase[:markdown]
27
28
  end
28
29
  end
@@ -7,13 +7,13 @@ class TestTasklists < Minitest::Test
7
7
  text = <<-MD
8
8
  - [x] Add task list
9
9
  - [ ] Define task list
10
- MD
10
+ MD
11
11
  @doc = CommonMarker.render_doc(text, :DEFAULT, %i[tasklist])
12
- @expected = <<-HTML
13
- <ul>
14
- <li><input type="checkbox" checked="" disabled="" /> Add task list</li>
15
- <li><input type="checkbox" disabled="" /> Define task list</li>
16
- </ul>
12
+ @expected = <<~HTML
13
+ <ul>
14
+ <li><input type="checkbox" checked="" disabled="" /> Add task list</li>
15
+ <li><input type="checkbox" disabled="" /> Define task list</li>
16
+ </ul>
17
17
  HTML
18
18
  end
19
19
 
@@ -28,6 +28,16 @@ MD
28
28
  def test_tasklist_state
29
29
  list = @doc.first_child
30
30
  assert_equal 'checked', list.first_child.tasklist_state
31
+ assert list.first_child.tasklist_item_checked?
31
32
  assert_equal 'unchecked', list.first_child.next.tasklist_state
33
+ refute list.first_child.next.tasklist_item_checked?
34
+ end
35
+
36
+ def test_set_tasklist_state
37
+ list = @doc.first_child
38
+ list.first_child.tasklist_item_checked = false
39
+ refute list.first_child.tasklist_item_checked?
40
+ list.first_child.next.tasklist_item_checked = true
41
+ assert list.first_child.next.tasklist_item_checked?
32
42
  end
33
43
  end
metadata CHANGED
@@ -1,88 +1,74 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: commonmarker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.20.1
4
+ version: 0.22.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Garen Torikian
8
8
  - Ashe Connor
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-04-29 00:00:00.000000000 Z
12
+ date: 2021-06-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: ruby-enum
16
- requirement: !ruby/object:Gem::Requirement
17
- requirements:
18
- - - "~>"
19
- - !ruby/object:Gem::Version
20
- version: '0.5'
21
- type: :runtime
22
- prerelease: false
23
- version_requirements: !ruby/object:Gem::Requirement
24
- requirements:
25
- - - "~>"
26
- - !ruby/object:Gem::Version
27
- version: '0.5'
28
- - !ruby/object:Gem::Dependency
29
- name: minitest
15
+ name: awesome_print
30
16
  requirement: !ruby/object:Gem::Requirement
31
17
  requirements:
32
- - - "~>"
18
+ - - ">="
33
19
  - !ruby/object:Gem::Version
34
- version: '5.6'
20
+ version: '0'
35
21
  type: :development
36
22
  prerelease: false
37
23
  version_requirements: !ruby/object:Gem::Requirement
38
24
  requirements:
39
- - - "~>"
25
+ - - ">="
40
26
  - !ruby/object:Gem::Version
41
- version: '5.6'
27
+ version: '0'
42
28
  - !ruby/object:Gem::Dependency
43
- name: minitest-focus
29
+ name: json
44
30
  requirement: !ruby/object:Gem::Requirement
45
31
  requirements:
46
32
  - - "~>"
47
33
  - !ruby/object:Gem::Version
48
- version: '1.1'
34
+ version: '2.3'
49
35
  type: :development
50
36
  prerelease: false
51
37
  version_requirements: !ruby/object:Gem::Requirement
52
38
  requirements:
53
39
  - - "~>"
54
40
  - !ruby/object:Gem::Version
55
- version: '1.1'
41
+ version: '2.3'
56
42
  - !ruby/object:Gem::Dependency
57
- name: rake-compiler
43
+ name: minitest
58
44
  requirement: !ruby/object:Gem::Requirement
59
45
  requirements:
60
46
  - - "~>"
61
47
  - !ruby/object:Gem::Version
62
- version: '0.9'
48
+ version: '5.6'
63
49
  type: :development
64
50
  prerelease: false
65
51
  version_requirements: !ruby/object:Gem::Requirement
66
52
  requirements:
67
53
  - - "~>"
68
54
  - !ruby/object:Gem::Version
69
- version: '0.9'
55
+ version: '5.6'
70
56
  - !ruby/object:Gem::Dependency
71
- name: json
57
+ name: minitest-focus
72
58
  requirement: !ruby/object:Gem::Requirement
73
59
  requirements:
74
60
  - - "~>"
75
61
  - !ruby/object:Gem::Version
76
- version: 1.8.1
62
+ version: '1.1'
77
63
  type: :development
78
64
  prerelease: false
79
65
  version_requirements: !ruby/object:Gem::Requirement
80
66
  requirements:
81
67
  - - "~>"
82
68
  - !ruby/object:Gem::Version
83
- version: 1.8.1
69
+ version: '1.1'
84
70
  - !ruby/object:Gem::Dependency
85
- name: awesome_print
71
+ name: rake
86
72
  requirement: !ruby/object:Gem::Requirement
87
73
  requirements:
88
74
  - - ">="
@@ -96,33 +82,33 @@ dependencies:
96
82
  - !ruby/object:Gem::Version
97
83
  version: '0'
98
84
  - !ruby/object:Gem::Dependency
99
- name: rake
85
+ name: rake-compiler
100
86
  requirement: !ruby/object:Gem::Requirement
101
87
  requirements:
102
- - - ">="
88
+ - - "~>"
103
89
  - !ruby/object:Gem::Version
104
- version: '0'
90
+ version: '0.9'
105
91
  type: :development
106
92
  prerelease: false
107
93
  version_requirements: !ruby/object:Gem::Requirement
108
94
  requirements:
109
- - - ">="
95
+ - - "~>"
110
96
  - !ruby/object:Gem::Version
111
- version: '0'
97
+ version: '0.9'
112
98
  - !ruby/object:Gem::Dependency
113
99
  name: rdoc
114
100
  requirement: !ruby/object:Gem::Requirement
115
101
  requirements:
116
102
  - - "~>"
117
103
  - !ruby/object:Gem::Version
118
- version: '5.1'
104
+ version: '6.2'
119
105
  type: :development
120
106
  prerelease: false
121
107
  version_requirements: !ruby/object:Gem::Requirement
122
108
  requirements:
123
109
  - - "~>"
124
110
  - !ruby/object:Gem::Version
125
- version: '5.1'
111
+ version: '6.2'
126
112
  - !ruby/object:Gem::Dependency
127
113
  name: rubocop
128
114
  requirement: !ruby/object:Gem::Requirement
@@ -153,7 +139,7 @@ dependencies:
153
139
  version: '0'
154
140
  description: A fast, safe, extensible parser for CommonMark. This wraps the official
155
141
  libcmark library.
156
- email:
142
+ email:
157
143
  executables:
158
144
  - commonmarker
159
145
  extensions:
@@ -246,8 +232,11 @@ files:
246
232
  - test/benchmark.rb
247
233
  - test/fixtures/curly.md
248
234
  - test/fixtures/dingus.md
235
+ - test/fixtures/strong.md
236
+ - test/fixtures/table.md
249
237
  - test/test_attributes.rb
250
238
  - test/test_basics.rb
239
+ - test/test_commands.rb
251
240
  - test/test_commonmark.rb
252
241
  - test/test_doc.rb
253
242
  - test/test_encoding.rb
@@ -269,7 +258,7 @@ homepage: https://github.com/gjtorikian/commonmarker
269
258
  licenses:
270
259
  - MIT
271
260
  metadata: {}
272
- post_install_message:
261
+ post_install_message:
273
262
  rdoc_options:
274
263
  - "-x"
275
264
  - ext/commonmarker/cmark/.*
@@ -280,38 +269,43 @@ required_ruby_version: !ruby/object:Gem::Requirement
280
269
  requirements:
281
270
  - - ">="
282
271
  - !ruby/object:Gem::Version
283
- version: 2.0.0
272
+ version: '2.6'
273
+ - - "<"
274
+ - !ruby/object:Gem::Version
275
+ version: '4.0'
284
276
  required_rubygems_version: !ruby/object:Gem::Requirement
285
277
  requirements:
286
278
  - - ">="
287
279
  - !ruby/object:Gem::Version
288
280
  version: '0'
289
281
  requirements: []
290
- rubyforge_project:
291
- rubygems_version: 2.5.1
292
- signing_key:
282
+ rubygems_version: 3.1.4
283
+ signing_key:
293
284
  specification_version: 4
294
285
  summary: CommonMark parser and renderer. Written in C, wrapped in Ruby.
295
286
  test_files:
296
- - test/benchmark.rb
297
- - test/fixtures/curly.md
298
- - test/fixtures/dingus.md
299
287
  - test/test_attributes.rb
300
- - test/test_basics.rb
301
- - test/test_commonmark.rb
288
+ - test/test_linebreaks.rb
302
289
  - test/test_doc.rb
290
+ - test/test_plaintext.rb
291
+ - test/test_pathological_inputs.rb
292
+ - test/test_node.rb
293
+ - test/test_maliciousness.rb
294
+ - test/test_commands.rb
295
+ - test/test_tasklists.rb
296
+ - test/test_commonmark.rb
303
297
  - test/test_encoding.rb
304
- - test/test_extensions.rb
298
+ - test/test_smartpunct.rb
299
+ - test/test_spec.rb
305
300
  - test/test_footnotes.rb
306
- - test/test_gc.rb
301
+ - test/test_extensions.rb
302
+ - test/fixtures/dingus.md
303
+ - test/fixtures/strong.md
304
+ - test/fixtures/table.md
305
+ - test/fixtures/curly.md
307
306
  - test/test_helper.rb
308
- - test/test_linebreaks.rb
309
- - test/test_maliciousness.rb
310
- - test/test_node.rb
311
307
  - test/test_options.rb
312
- - test/test_pathological_inputs.rb
313
- - test/test_plaintext.rb
308
+ - test/benchmark.rb
309
+ - test/test_basics.rb
314
310
  - test/test_renderer.rb
315
- - test/test_smartpunct.rb
316
- - test/test_spec.rb
317
- - test/test_tasklists.rb
311
+ - test/test_gc.rb