commonmarker 0.20.2 → 0.21.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.
- checksums.yaml +4 -4
- data/README.md +1 -3
- data/Rakefile +16 -4
- data/commonmarker.gemspec +8 -11
- data/ext/commonmarker/cmark-gfm-core-extensions.h +24 -1
- data/ext/commonmarker/commonmarker.c +120 -78
- data/ext/commonmarker/node.h +1 -0
- data/ext/commonmarker/table.c +52 -13
- data/ext/commonmarker/tasklist.c +33 -13
- data/lib/commonmarker.rb +5 -4
- data/lib/commonmarker/config.rb +5 -4
- data/lib/commonmarker/node.rb +1 -1
- data/lib/commonmarker/node/inspect.rb +11 -11
- data/lib/commonmarker/renderer.rb +7 -5
- data/lib/commonmarker/renderer/html_renderer.rb +21 -34
- data/lib/commonmarker/version.rb +1 -1
- data/test/benchmark.rb +1 -1
- data/test/test_attributes.rb +2 -2
- data/test/test_commonmark.rb +11 -11
- data/test/test_encoding.rb +0 -1
- data/test/test_extensions.rb +39 -40
- data/test/test_footnotes.rb +9 -9
- data/test/test_gc.rb +2 -0
- data/test/test_helper.rb +7 -8
- data/test/test_maliciousness.rb +192 -190
- data/test/test_node.rb +10 -12
- data/test/test_options.rb +15 -15
- data/test/test_pathological_inputs.rb +2 -2
- data/test/test_plaintext.rb +21 -21
- data/test/test_renderer.rb +9 -9
- data/test/test_spec.rb +3 -2
- data/test/test_tasklists.rb +16 -6
- metadata +42 -42
data/lib/commonmarker/version.rb
CHANGED
data/test/benchmark.rb
CHANGED
@@ -13,7 +13,7 @@ end
|
|
13
13
|
|
14
14
|
benchinput = File.open('test/benchinput.md', 'r').read
|
15
15
|
|
16
|
-
printf("input size =
|
16
|
+
printf("input size = %<bytes>d bytes\n\n", benchinput.bytesize)
|
17
17
|
|
18
18
|
dobench('redcarpet') do
|
19
19
|
Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: false, tables: false).render(benchinput)
|
data/test/test_attributes.rb
CHANGED
@@ -15,9 +15,9 @@ class TestAttributes < Minitest::Test
|
|
15
15
|
sourcepos << node.sourcepos
|
16
16
|
end
|
17
17
|
|
18
|
-
sourcepos.delete_if { |h| h.values.all?
|
18
|
+
sourcepos.delete_if { |h| h.values.all?(&:zero?) }
|
19
19
|
|
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}]
|
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 }]
|
21
21
|
|
22
22
|
assert_equal result, sourcepos
|
23
23
|
end
|
data/test/test_commonmark.rb
CHANGED
@@ -3,22 +3,22 @@
|
|
3
3
|
require 'test_helper'
|
4
4
|
|
5
5
|
class TestCommonmark < Minitest::Test
|
6
|
-
HTML_COMMENT =
|
6
|
+
HTML_COMMENT = /<!--.*?-->\s?/.freeze
|
7
7
|
|
8
8
|
def setup
|
9
|
-
@markdown =
|
10
|
-
Hi *there*!
|
9
|
+
@markdown = <<~MD
|
10
|
+
Hi *there*!
|
11
11
|
|
12
|
-
1. I am a numeric list.
|
13
|
-
2. I continue the list.
|
14
|
-
* Suddenly, an unordered list!
|
15
|
-
* What fun!
|
12
|
+
1. I am a numeric list.
|
13
|
+
2. I continue the list.
|
14
|
+
* Suddenly, an unordered list!
|
15
|
+
* What fun!
|
16
16
|
|
17
|
-
Okay, _enough_.
|
17
|
+
Okay, _enough_.
|
18
18
|
|
19
|
-
| a | b |
|
20
|
-
| --- | --- |
|
21
|
-
| c | d |
|
19
|
+
| a | b |
|
20
|
+
| --- | --- |
|
21
|
+
| c | d |
|
22
22
|
MD
|
23
23
|
end
|
24
24
|
|
data/test/test_encoding.rb
CHANGED
data/test/test_extensions.rb
CHANGED
@@ -16,7 +16,7 @@ class TestExtensions < Minitest::Test
|
|
16
16
|
|
17
17
|
CommonMarker.render_html(@markdown, :DEFAULT, %i[table]).tap do |out|
|
18
18
|
refute out.include?('| a')
|
19
|
-
%w
|
19
|
+
%w[<table> <tr> <th> a </th> <td> c </td> <strong>x</strong>].each { |html| assert out.include?(html) }
|
20
20
|
assert out.include?('~~hi~~')
|
21
21
|
end
|
22
22
|
|
@@ -34,7 +34,6 @@ class TestExtensions < Minitest::Test
|
|
34
34
|
refute out.include?('| <strong>x</strong>')
|
35
35
|
refute out.include?('~~hi~~')
|
36
36
|
end
|
37
|
-
|
38
37
|
end
|
39
38
|
|
40
39
|
def test_extensions_with_renderers
|
@@ -42,13 +41,13 @@ class TestExtensions < Minitest::Test
|
|
42
41
|
|
43
42
|
doc.to_html.tap do |out|
|
44
43
|
refute out.include?('| a')
|
45
|
-
%w
|
44
|
+
%w[<table> <tr> <th> a </th> <td> c </td> <strong>x</strong>].each { |html| assert out.include?(html) }
|
46
45
|
assert out.include?('~~hi~~')
|
47
46
|
end
|
48
47
|
|
49
48
|
HtmlRenderer.new.render(doc).tap do |out|
|
50
49
|
refute out.include?('| a')
|
51
|
-
%w
|
50
|
+
%w[<table> <tr> <th> a </th> <td> c </td> <strong>x</strong>].each { |html| assert out.include?(html) }
|
52
51
|
assert out.include?('~~hi~~')
|
53
52
|
end
|
54
53
|
|
@@ -64,51 +63,51 @@ class TestExtensions < Minitest::Test
|
|
64
63
|
|
65
64
|
def test_comments_are_kept_as_expected
|
66
65
|
assert_equal "<!--hello--> <blah> <xmp>\n",
|
67
|
-
|
66
|
+
CommonMarker.render_html("<!--hello--> <blah> <xmp>\n", :UNSAFE, %i[tagfilter])
|
68
67
|
end
|
69
68
|
|
70
69
|
def test_table_prefer_style_attributes
|
71
|
-
|
72
|
-
<table>
|
73
|
-
<thead>
|
74
|
-
<tr>
|
75
|
-
<th style="text-align: left">aaa</th>
|
76
|
-
<th>bbb</th>
|
77
|
-
<th style="text-align: center">ccc</th>
|
78
|
-
<th>ddd</th>
|
79
|
-
<th style="text-align: right">eee</th>
|
80
|
-
</tr>
|
81
|
-
</thead>
|
82
|
-
<tbody>
|
83
|
-
<tr>
|
84
|
-
<td style="text-align: left">fff</td>
|
85
|
-
<td>ggg</td>
|
86
|
-
<td style="text-align: center">hhh</td>
|
87
|
-
<td>iii</td>
|
88
|
-
<td style="text-align: right">jjj</td>
|
89
|
-
</tr>
|
90
|
-
</tbody>
|
91
|
-
</table>
|
92
|
-
|
93
|
-
aaa | bbb | ccc | ddd | eee
|
94
|
-
:-- | --- | :-: | --- | --:
|
95
|
-
fff | ggg | hhh | iii | jjj
|
96
|
-
|
70
|
+
assert_equal(<<~HTML, CommonMarker.render_html(<<~MD, :TABLE_PREFER_STYLE_ATTRIBUTES, %i[table]))
|
71
|
+
<table>
|
72
|
+
<thead>
|
73
|
+
<tr>
|
74
|
+
<th style="text-align: left">aaa</th>
|
75
|
+
<th>bbb</th>
|
76
|
+
<th style="text-align: center">ccc</th>
|
77
|
+
<th>ddd</th>
|
78
|
+
<th style="text-align: right">eee</th>
|
79
|
+
</tr>
|
80
|
+
</thead>
|
81
|
+
<tbody>
|
82
|
+
<tr>
|
83
|
+
<td style="text-align: left">fff</td>
|
84
|
+
<td>ggg</td>
|
85
|
+
<td style="text-align: center">hhh</td>
|
86
|
+
<td>iii</td>
|
87
|
+
<td style="text-align: right">jjj</td>
|
88
|
+
</tr>
|
89
|
+
</tbody>
|
90
|
+
</table>
|
91
|
+
HTML
|
92
|
+
aaa | bbb | ccc | ddd | eee
|
93
|
+
:-- | --- | :-: | --- | --:
|
94
|
+
fff | ggg | hhh | iii | jjj
|
95
|
+
MD
|
97
96
|
end
|
98
97
|
|
99
98
|
def test_plaintext
|
100
|
-
assert_equal(
|
101
|
-
Hello ~there~.
|
99
|
+
assert_equal(<<~HTML, CommonMarker.render_doc(<<~MD, :DEFAULT, %i[table strikethrough]).to_plaintext)
|
100
|
+
Hello ~there~.
|
102
101
|
|
103
|
-
| a |
|
104
|
-
| --- |
|
105
|
-
| b |
|
102
|
+
| a |
|
103
|
+
| --- |
|
104
|
+
| b |
|
106
105
|
HTML
|
107
|
-
Hello ~~there~~.
|
106
|
+
Hello ~~there~~.
|
108
107
|
|
109
|
-
| a |
|
110
|
-
| - |
|
111
|
-
| b |
|
108
|
+
| a |
|
109
|
+
| - |
|
110
|
+
| b |
|
112
111
|
MD
|
113
112
|
end
|
114
113
|
end
|
data/test/test_footnotes.rb
CHANGED
@@ -5,15 +5,15 @@ require 'test_helper'
|
|
5
5
|
class TestFootnotes < Minitest::Test
|
6
6
|
def setup
|
7
7
|
@doc = CommonMarker.render_doc("Hello[^hi].\n\n[^hi]: Hey!\n", :FOOTNOTES)
|
8
|
-
@expected =
|
9
|
-
<p>Hello<sup class="footnote-ref"><a href="#fn1" id="fnref1">1</a></sup>.</p>
|
10
|
-
<section class="footnotes">
|
11
|
-
<ol>
|
12
|
-
<li id="fn1">
|
13
|
-
<p>Hey! <a href="#fnref1" class="footnote-backref">↩</a></p>
|
14
|
-
</li>
|
15
|
-
</ol>
|
16
|
-
</section>
|
8
|
+
@expected = <<~HTML
|
9
|
+
<p>Hello<sup class="footnote-ref"><a href="#fn1" id="fnref1">1</a></sup>.</p>
|
10
|
+
<section class="footnotes">
|
11
|
+
<ol>
|
12
|
+
<li id="fn1">
|
13
|
+
<p>Hey! <a href="#fnref1" class="footnote-backref">↩</a></p>
|
14
|
+
</li>
|
15
|
+
</ol>
|
16
|
+
</section>
|
17
17
|
HTML
|
18
18
|
end
|
19
19
|
|
data/test/test_gc.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# coding: utf-8
|
2
1
|
# frozen_string_literal: true
|
3
2
|
|
4
3
|
require 'commonmarker'
|
@@ -6,7 +5,7 @@ require 'minitest/autorun'
|
|
6
5
|
require 'minitest/pride'
|
7
6
|
require 'minitest/focus'
|
8
7
|
|
9
|
-
include CommonMarker
|
8
|
+
include CommonMarker # rubocop:disable Style/MixinUsage
|
10
9
|
|
11
10
|
FIXTURES_DIR = File.join(File.dirname(__FILE__), 'fixtures')
|
12
11
|
|
@@ -39,7 +38,7 @@ def open_spec_file(filename)
|
|
39
38
|
l = line.strip
|
40
39
|
if l =~ /^`{32} example(.*)$/
|
41
40
|
state = 1
|
42
|
-
extensions =
|
41
|
+
extensions = Regexp.last_match(1).split
|
43
42
|
elsif l == '`' * 32
|
44
43
|
state = 0
|
45
44
|
example_number += 1
|
@@ -51,7 +50,7 @@ def open_spec_file(filename)
|
|
51
50
|
start_line: start_line,
|
52
51
|
end_line: end_line,
|
53
52
|
section: headertext,
|
54
|
-
extensions: extensions.map(&:to_sym)
|
53
|
+
extensions: extensions.map(&:to_sym)
|
55
54
|
}
|
56
55
|
start_line = 0
|
57
56
|
markdown_lines = []
|
@@ -59,11 +58,11 @@ def open_spec_file(filename)
|
|
59
58
|
elsif l == '.'
|
60
59
|
state = 2
|
61
60
|
elsif state == 1
|
62
|
-
start_line = line_number - 1 if start_line
|
63
|
-
markdown_lines <<
|
61
|
+
start_line = line_number - 1 if start_line.zero?
|
62
|
+
markdown_lines << line.to_s
|
64
63
|
elsif state == 2
|
65
|
-
html_lines <<
|
66
|
-
elsif state
|
64
|
+
html_lines << line.to_s
|
65
|
+
elsif state.zero? && header_re.match(line)
|
67
66
|
headertext = line.sub(header_re, '').strip
|
68
67
|
end
|
69
68
|
end
|
data/test/test_maliciousness.rb
CHANGED
@@ -2,264 +2,266 @@
|
|
2
2
|
|
3
3
|
require 'test_helper'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
def test_init_with_bad_type
|
11
|
-
assert_raises TypeError do
|
12
|
-
Node.new(123)
|
5
|
+
module CommonMarker
|
6
|
+
class TestMaliciousness < Minitest::Test
|
7
|
+
def setup
|
8
|
+
@doc = CommonMarker.render_doc('Hi *there*')
|
13
9
|
end
|
14
10
|
|
15
|
-
|
16
|
-
|
17
|
-
|
11
|
+
def test_init_with_bad_type
|
12
|
+
assert_raises TypeError do
|
13
|
+
Node.new(123)
|
14
|
+
end
|
18
15
|
|
19
|
-
|
20
|
-
|
21
|
-
|
16
|
+
assert_raises NodeError do
|
17
|
+
Node.new(:totes_fake)
|
18
|
+
end
|
22
19
|
|
23
|
-
|
24
|
-
|
25
|
-
|
20
|
+
assert_raises TypeError do
|
21
|
+
Node.new([])
|
22
|
+
end
|
26
23
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
24
|
+
assert_raises TypeError do
|
25
|
+
Node.new([23])
|
26
|
+
end
|
31
27
|
|
32
|
-
|
33
|
-
|
34
|
-
|
28
|
+
assert_raises TypeError do
|
29
|
+
Node.new(nil)
|
30
|
+
end
|
35
31
|
end
|
36
32
|
|
37
|
-
|
38
|
-
|
39
|
-
|
33
|
+
def test_rendering_with_bad_type
|
34
|
+
assert_raises TypeError do
|
35
|
+
CommonMarker.render_html("foo \n baz", 123)
|
36
|
+
end
|
40
37
|
|
41
|
-
|
42
|
-
|
43
|
-
|
38
|
+
assert_raises TypeError do
|
39
|
+
CommonMarker.render_html("foo \n baz", :totes_fake)
|
40
|
+
end
|
44
41
|
|
45
|
-
|
46
|
-
|
47
|
-
|
42
|
+
assert_raises TypeError do
|
43
|
+
CommonMarker.render_html("foo \n baz", [])
|
44
|
+
end
|
48
45
|
|
49
|
-
|
50
|
-
|
51
|
-
|
46
|
+
assert_raises TypeError do
|
47
|
+
CommonMarker.render_html("foo \n baz", [23])
|
48
|
+
end
|
52
49
|
|
53
|
-
|
54
|
-
|
55
|
-
|
50
|
+
assert_raises TypeError do
|
51
|
+
CommonMarker.render_html("foo \n baz", nil)
|
52
|
+
end
|
56
53
|
|
57
|
-
|
58
|
-
|
59
|
-
|
54
|
+
assert_raises TypeError do
|
55
|
+
CommonMarker.render_html("foo \n baz", [:SMART, 'totes_fake'])
|
56
|
+
end
|
60
57
|
|
61
|
-
|
62
|
-
|
63
|
-
|
58
|
+
assert_raises TypeError do
|
59
|
+
CommonMarker.render_html(123)
|
60
|
+
end
|
64
61
|
|
65
|
-
|
66
|
-
|
67
|
-
|
62
|
+
assert_raises TypeError do
|
63
|
+
CommonMarker.render_html([123])
|
64
|
+
end
|
68
65
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
assert_equal err.message, 'option \':SMART\' does not exist for CommonMarker::Config::Render'
|
66
|
+
assert_raises TypeError do
|
67
|
+
CommonMarker.render_html(nil)
|
68
|
+
end
|
73
69
|
|
74
|
-
|
75
|
-
|
76
|
-
|
70
|
+
err = assert_raises TypeError do
|
71
|
+
CommonMarker.render_html("foo \n baz", [:SMART])
|
72
|
+
end
|
73
|
+
assert_equal err.message, 'option \':SMART\' does not exist for CommonMarker::Config::Render'
|
77
74
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
assert_equal err.message, 'option \':safe\' does not exist for CommonMarker::Config::Parse'
|
75
|
+
assert_raises TypeError do
|
76
|
+
CommonMarker.render_doc("foo \n baz", 123)
|
77
|
+
end
|
82
78
|
|
83
|
-
|
84
|
-
|
85
|
-
|
79
|
+
err = assert_raises TypeError do
|
80
|
+
CommonMarker.render_doc("foo \n baz", :safe)
|
81
|
+
end
|
82
|
+
assert_equal err.message, 'option \':safe\' does not exist for CommonMarker::Config::Parse'
|
86
83
|
|
87
|
-
|
88
|
-
|
89
|
-
|
84
|
+
assert_raises TypeError do
|
85
|
+
CommonMarker.render_doc("foo \n baz", :totes_fake)
|
86
|
+
end
|
90
87
|
|
91
|
-
|
92
|
-
|
93
|
-
|
88
|
+
assert_raises TypeError do
|
89
|
+
CommonMarker.render_doc("foo \n baz", [])
|
90
|
+
end
|
94
91
|
|
95
|
-
|
96
|
-
|
97
|
-
|
92
|
+
assert_raises TypeError do
|
93
|
+
CommonMarker.render_doc("foo \n baz", [23])
|
94
|
+
end
|
98
95
|
|
99
|
-
|
100
|
-
|
101
|
-
|
96
|
+
assert_raises TypeError do
|
97
|
+
CommonMarker.render_doc("foo \n baz", nil)
|
98
|
+
end
|
102
99
|
|
103
|
-
|
104
|
-
|
105
|
-
|
100
|
+
assert_raises TypeError do
|
101
|
+
CommonMarker.render_doc("foo \n baz", [:SMART, 'totes_fake'])
|
102
|
+
end
|
106
103
|
|
107
|
-
|
108
|
-
|
109
|
-
|
104
|
+
assert_raises TypeError do
|
105
|
+
CommonMarker.render_doc(123)
|
106
|
+
end
|
110
107
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
end
|
108
|
+
assert_raises TypeError do
|
109
|
+
CommonMarker.render_doc([123])
|
110
|
+
end
|
115
111
|
|
116
|
-
|
117
|
-
|
118
|
-
|
112
|
+
assert_raises TypeError do
|
113
|
+
CommonMarker.render_doc(nil)
|
114
|
+
end
|
119
115
|
end
|
120
|
-
end
|
121
|
-
|
122
|
-
def test_bad_walking
|
123
|
-
assert_nil @doc.parent
|
124
|
-
assert_nil @doc.previous
|
125
|
-
end
|
126
116
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
117
|
+
def test_bad_set_string_content
|
118
|
+
assert_raises TypeError do
|
119
|
+
@doc.string_content = 123
|
120
|
+
end
|
131
121
|
end
|
132
122
|
|
133
|
-
|
134
|
-
|
135
|
-
@doc.
|
123
|
+
def test_bad_walking
|
124
|
+
assert_nil @doc.parent
|
125
|
+
assert_nil @doc.previous
|
136
126
|
end
|
137
127
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
128
|
+
def test_bad_insertion
|
129
|
+
code = Node.new(:code)
|
130
|
+
assert_raises NodeError do
|
131
|
+
@doc.insert_before(code)
|
132
|
+
end
|
142
133
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
134
|
+
paragraph = Node.new(:paragraph)
|
135
|
+
assert_raises NodeError do
|
136
|
+
@doc.insert_after(paragraph)
|
137
|
+
end
|
147
138
|
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
end
|
139
|
+
document = Node.new(:document)
|
140
|
+
assert_raises NodeError do
|
141
|
+
@doc.prepend_child(document)
|
142
|
+
end
|
153
143
|
|
154
|
-
|
155
|
-
|
156
|
-
|
144
|
+
assert_raises NodeError do
|
145
|
+
@doc.append_child(document)
|
146
|
+
end
|
157
147
|
end
|
158
148
|
|
159
|
-
|
160
|
-
|
161
|
-
|
149
|
+
def test_bad_url_get
|
150
|
+
assert_raises NodeError do
|
151
|
+
@doc.url
|
152
|
+
end
|
162
153
|
end
|
163
|
-
end
|
164
154
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
end
|
155
|
+
def test_bad_url_set
|
156
|
+
assert_raises NodeError do
|
157
|
+
@doc.url = '123'
|
158
|
+
end
|
170
159
|
|
171
|
-
|
172
|
-
|
173
|
-
|
160
|
+
link = CommonMarker.render_doc('[GitHub](https://www.github.com)').first_child.first_child
|
161
|
+
assert_raises TypeError do
|
162
|
+
link.url = 123
|
163
|
+
end
|
174
164
|
end
|
175
165
|
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
166
|
+
def test_bad_title_get
|
167
|
+
assert_raises NodeError do
|
168
|
+
@doc.title
|
169
|
+
end
|
180
170
|
end
|
181
|
-
end
|
182
171
|
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
end
|
172
|
+
def test_bad_title_set
|
173
|
+
assert_raises NodeError do
|
174
|
+
@doc.title = '123'
|
175
|
+
end
|
188
176
|
|
189
|
-
|
190
|
-
|
191
|
-
|
177
|
+
image = CommonMarker.render_doc('![alt text](https://github.com/favicon.ico "Favicon")')
|
178
|
+
image = image.first_child.first_child
|
179
|
+
assert_raises TypeError do
|
180
|
+
image.title = 123
|
181
|
+
end
|
192
182
|
end
|
193
183
|
|
194
|
-
|
195
|
-
|
196
|
-
|
184
|
+
def test_bad_header_level_get
|
185
|
+
assert_raises NodeError do
|
186
|
+
@doc.header_level
|
187
|
+
end
|
197
188
|
end
|
198
|
-
end
|
199
189
|
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
end
|
190
|
+
def test_bad_header_level_set
|
191
|
+
assert_raises NodeError do
|
192
|
+
@doc.header_level = 1
|
193
|
+
end
|
205
194
|
|
206
|
-
|
207
|
-
|
208
|
-
|
195
|
+
header = CommonMarker.render_doc('### Header Three').first_child
|
196
|
+
assert_raises TypeError do
|
197
|
+
header.header_level = '123'
|
198
|
+
end
|
209
199
|
end
|
210
200
|
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
assert_raises TypeError do
|
216
|
-
ul_list.list_type = 1234
|
201
|
+
def test_bad_list_type_get
|
202
|
+
assert_raises NodeError do
|
203
|
+
@doc.list_type
|
204
|
+
end
|
217
205
|
end
|
218
|
-
end
|
219
206
|
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
end
|
207
|
+
def test_bad_list_type_set
|
208
|
+
assert_raises NodeError do
|
209
|
+
@doc.list_type = :bullet_list
|
210
|
+
end
|
225
211
|
|
226
|
-
|
227
|
-
|
228
|
-
|
212
|
+
ul_list = CommonMarker.render_doc("* Bullet\n*Bullet").first_child
|
213
|
+
assert_raises NodeError do
|
214
|
+
ul_list.list_type = :fake
|
215
|
+
end
|
216
|
+
assert_raises TypeError do
|
217
|
+
ul_list.list_type = 1234
|
218
|
+
end
|
229
219
|
end
|
230
220
|
|
231
|
-
|
232
|
-
|
233
|
-
|
221
|
+
def test_bad_list_start_get
|
222
|
+
assert_raises NodeError do
|
223
|
+
@doc.list_start
|
224
|
+
end
|
234
225
|
end
|
235
|
-
end
|
236
226
|
|
237
|
-
|
238
|
-
|
239
|
-
|
227
|
+
def test_bad_list_start_set
|
228
|
+
assert_raises NodeError do
|
229
|
+
@doc.list_start = 12
|
230
|
+
end
|
231
|
+
|
232
|
+
ol_list = CommonMarker.render_doc("1. One\n2. Two").first_child
|
233
|
+
assert_raises TypeError do
|
234
|
+
ol_list.list_start = :fake
|
235
|
+
end
|
240
236
|
end
|
241
|
-
end
|
242
237
|
|
243
|
-
|
244
|
-
|
245
|
-
|
238
|
+
def test_bad_list_tight_get
|
239
|
+
assert_raises NodeError do
|
240
|
+
@doc.list_tight
|
241
|
+
end
|
246
242
|
end
|
247
|
-
end
|
248
243
|
|
249
|
-
|
250
|
-
|
251
|
-
|
244
|
+
def test_bad_list_tight_set
|
245
|
+
assert_raises NodeError do
|
246
|
+
@doc.list_tight = false
|
247
|
+
end
|
252
248
|
end
|
253
|
-
end
|
254
249
|
|
255
|
-
|
256
|
-
|
257
|
-
|
250
|
+
def test_bad_fence_info_get
|
251
|
+
assert_raises NodeError do
|
252
|
+
@doc.fence_info
|
253
|
+
end
|
258
254
|
end
|
259
255
|
|
260
|
-
|
261
|
-
|
262
|
-
|
256
|
+
def test_bad_fence_info_set
|
257
|
+
assert_raises NodeError do
|
258
|
+
@doc.fence_info = 'ruby'
|
259
|
+
end
|
260
|
+
|
261
|
+
fence = CommonMarker.render_doc("``` ruby\nputs 'wow'\n```").first_child
|
262
|
+
assert_raises TypeError do
|
263
|
+
fence.fence_info = 123
|
264
|
+
end
|
263
265
|
end
|
264
266
|
end
|
265
267
|
end
|