commonmarker 0.23.4 → 0.23.5

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.

@@ -1,72 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class TestCommands < Minitest::Test
6
- def test_basic
7
- out = make_bin('strong.md')
8
- assert_equal('<p>I am <strong>strong</strong></p>', out)
9
- end
10
-
11
- def test_does_not_have_extensions
12
- out = make_bin('table.md')
13
- assert_includes out, '| a'
14
- refute_includes out, '<p><del>hi</del>'
15
- refute_includes out, '<table> <tr> <th> a </th> <td> c </td>'
16
- end
17
-
18
- def test_understands_extensions
19
- out = make_bin('table.md', '--extension=table')
20
- refute_includes out, '| a'
21
- refute_includes out, '<p><del>hi</del>'
22
- %w[<table> <tr> <th> a </th> <td> c </td>].each { |html| assert_includes out, html }
23
- end
24
-
25
- def test_understands_multiple_extensions
26
- out = make_bin('table.md', '--extension=table,strikethrough')
27
- refute_includes out, '| a'
28
- assert_includes out, '<p><del>hi</del>'
29
- %w[<table> <tr> <th> a </th> <td> c </td>].each { |html| assert_includes out, html }
30
- end
31
-
32
- def test_understands_html_format_with_renderer_and_extensions
33
- out = make_bin('table.md', '--to=html --extension=table,strikethrough --html-renderer')
34
- refute_includes out, '| a'
35
- assert_includes out, '<p><del>hi</del>'
36
- %w[<table> <tr> <th> a </th> <td> c </td>].each { |html| assert_includes out, html }
37
- end
38
-
39
- def test_understands_xml_format
40
- out = make_bin('strong.md', '--to=xml')
41
- assert_includes out, '<?xml version="1.0" encoding="UTF-8"?>'
42
- assert_includes out, '<text xml:space="preserve">strong</text>'
43
- end
44
-
45
- def test_understands_commonmark_format
46
- out = make_bin('strong.md', '--to=commonmark')
47
- assert_equal('I am **strong**', out)
48
- end
49
-
50
- def test_understands_plaintext_format
51
- out = make_bin('strong.md', '--to=plaintext')
52
- assert_equal('I am strong', out)
53
- end
54
-
55
- def test_aborts_invalid_format
56
- _out, err = capture_subprocess_io do
57
- make_bin('strong.md', '--to=unknown')
58
- end
59
-
60
- assert_match "format 'unknown' not found", err
61
- end
62
-
63
- def test_aborts_format_and_html_renderer_combinations
64
- (CommonMarker::Config::OPTS[:format] - [:html]).each do |format|
65
- _out, err = capture_subprocess_io do
66
- make_bin('strong.md', "--to=#{format} --html-renderer")
67
- end
68
-
69
- assert_match "format '#{format}' does not support using the HtmlRenderer renderer", err
70
- end
71
- end
72
- end
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class TestCommonmark < Minitest::Test
6
- HTML_COMMENT = /<!--.*?-->\s?/.freeze
7
-
8
- def setup
9
- @markdown = <<~MD
10
- Hi *there*!
11
-
12
- 1. I am a numeric list.
13
- 2. I continue the list.
14
- * Suddenly, an unordered list!
15
- * What fun!
16
-
17
- Okay, _enough_.
18
-
19
- | a | b |
20
- | --- | --- |
21
- | c | d |
22
- MD
23
- end
24
-
25
- def render_doc(doc)
26
- CommonMarker.render_doc(doc, :DEFAULT, %i[table])
27
- end
28
-
29
- def test_to_commonmark
30
- compare = render_doc(@markdown).to_commonmark
31
-
32
- assert_equal \
33
- render_doc(@markdown).to_html.squeeze(' ').gsub(HTML_COMMENT, ''),
34
- render_doc(compare).to_html.squeeze(' ').gsub(HTML_COMMENT, '')
35
- end
36
- end
data/test/test_doc.rb DELETED
@@ -1,130 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class TestDocNode < Minitest::Test
6
- def setup
7
- @doc = CommonMarker.render_doc('Hi *there*. This has __many nodes__!')
8
- @first_child = @doc.first_child
9
- @last_child = @doc.last_child
10
- @link = CommonMarker.render_doc('[GitHub](https://www.github.com)').first_child.first_child
11
- @image = CommonMarker.render_doc('![alt text](https://github.com/favicon.ico "Favicon")')
12
- @image = @image.first_child.first_child
13
- @header = CommonMarker.render_doc('### Header Three').first_child
14
- @ul_list = CommonMarker.render_doc("* Bullet\n*Bullet").first_child
15
- @ol_list = CommonMarker.render_doc("1. One\n2. Two").first_child
16
- @fence = CommonMarker.render_doc("``` ruby\nputs 'wow'\n```").first_child
17
- end
18
-
19
- def test_get_type
20
- assert_equal(:document, @doc.type)
21
- end
22
-
23
- def test_get_type_string
24
- assert_equal('document', @doc.type_string)
25
- end
26
-
27
- def test_get_first_child
28
- assert_equal(:paragraph, @first_child.type)
29
- end
30
-
31
- def test_get_next
32
- assert_equal(:emph, @first_child.first_child.next.type)
33
- end
34
-
35
- def test_insert_before
36
- paragraph = Node.new(:paragraph)
37
- assert(@first_child.insert_before(paragraph))
38
- assert_match "<p></p>\n<p>Hi <em>there</em>.", @doc.to_html
39
- end
40
-
41
- def test_insert_after
42
- paragraph = Node.new(:paragraph)
43
- assert(@first_child.insert_after(paragraph))
44
- assert_match "<strong>many nodes</strong>!</p>\n<p></p>\n", @doc.to_html
45
- end
46
-
47
- def test_prepend_child
48
- code = Node.new(:code)
49
- assert(@first_child.prepend_child(code))
50
- assert_match '<p><code></code>Hi <em>there</em>.', @doc.to_html
51
- end
52
-
53
- def test_append_child
54
- strong = Node.new(:strong)
55
- assert(@first_child.append_child(strong))
56
- assert_match "!<strong></strong></p>\n", @doc.to_html
57
- end
58
-
59
- def test_get_last_child
60
- assert_equal(:paragraph, @last_child.type)
61
- end
62
-
63
- def test_get_parent
64
- assert_equal(:paragraph, @first_child.first_child.next.parent.type)
65
- end
66
-
67
- def test_get_previous
68
- assert_equal(:text, @first_child.first_child.next.previous.type)
69
- end
70
-
71
- def test_get_url
72
- assert_equal('https://www.github.com', @link.url)
73
- end
74
-
75
- def test_set_url
76
- assert_equal('https://www.mozilla.org', @link.url = 'https://www.mozilla.org')
77
- end
78
-
79
- def test_get_title
80
- assert_equal('Favicon', @image.title)
81
- end
82
-
83
- def test_set_title
84
- assert_equal('Octocat', @image.title = 'Octocat')
85
- end
86
-
87
- def test_get_header_level
88
- assert_equal(3, @header.header_level)
89
- end
90
-
91
- def test_set_header_level
92
- assert_equal(6, @header.header_level = 6)
93
- end
94
-
95
- def test_get_list_type
96
- assert_equal(:bullet_list, @ul_list.list_type)
97
- assert_equal(:ordered_list, @ol_list.list_type)
98
- end
99
-
100
- def test_set_list_type
101
- assert_equal(:ordered_list, @ul_list.list_type = :ordered_list)
102
- assert_equal(:bullet_list, @ol_list.list_type = :bullet_list)
103
- end
104
-
105
- def test_get_list_start
106
- assert_equal(1, @ol_list.list_start)
107
- end
108
-
109
- def test_set_list_start
110
- assert_equal(8, @ol_list.list_start = 8)
111
- end
112
-
113
- def test_get_list_tight
114
- assert(@ul_list.list_tight)
115
- assert(@ol_list.list_tight)
116
- end
117
-
118
- def test_set_list_tight
119
- refute(@ul_list.list_tight = false)
120
- refute(@ol_list.list_tight = false)
121
- end
122
-
123
- def test_get_fence_info
124
- assert_equal('ruby', @fence.fence_info)
125
- end
126
-
127
- def test_set_fence_info
128
- assert_equal('javascript', @fence.fence_info = 'javascript')
129
- end
130
- end
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class TestEncoding < Minitest::Test
6
- # see http://git.io/vq4FR
7
- def test_encoding
8
- contents = fixtures_file('curly.md')
9
- doc = CommonMarker.render_doc(contents, :SMART)
10
- render = doc.to_html
11
- assert_equal('<p>This curly quote “makes commonmarker throw an exception”.</p>', render.rstrip)
12
-
13
- render = doc.to_xml
14
- assert_includes(render, '<text xml:space="preserve">This curly quote “makes commonmarker throw an exception”.</text>')
15
- end
16
-
17
- def test_string_content_is_utf8
18
- doc = CommonMarker.render_doc('Hi *there*')
19
- text = doc.first_child.last_child.first_child
20
- assert_equal('there', text.string_content)
21
- assert_equal('UTF-8', text.string_content.encoding.name)
22
- end
23
- end
@@ -1,116 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class TestExtensions < Minitest::Test
6
- def setup
7
- @markdown = fixtures_file('table.md')
8
- end
9
-
10
- def test_uses_specified_extensions
11
- CommonMarker.render_html(@markdown, :DEFAULT, %i[]).tap do |out|
12
- assert_includes out, '| a'
13
- assert_includes out, '| <strong>x</strong>'
14
- assert_includes out, '~~hi~~'
15
- end
16
-
17
- CommonMarker.render_html(@markdown, :DEFAULT, %i[table]).tap do |out|
18
- refute_includes out, '| a'
19
- %w[<table> <tr> <th> a </th> <td> c </td> <strong>x</strong>].each { |html| assert_includes out, html }
20
- assert_includes out, '~~hi~~'
21
- end
22
-
23
- CommonMarker.render_html(@markdown, :DEFAULT, %i[strikethrough]).tap do |out|
24
- assert_includes out, '| a'
25
- refute_includes out, '~~hi~~'
26
- assert_includes out, '<del>hi</del>'
27
- end
28
-
29
- doc = CommonMarker.render_doc('~a~ ~~b~~ ~~~c~~~', :STRIKETHROUGH_DOUBLE_TILDE, [:strikethrough])
30
- assert_equal("<p>~a~ <del>b</del> ~~~c~~~</p>\n", doc.to_html)
31
-
32
- html = CommonMarker.render_html('~a~ ~~b~~ ~~~c~~~', :STRIKETHROUGH_DOUBLE_TILDE, [:strikethrough])
33
- assert_equal("<p>~a~ <del>b</del> ~~~c~~~</p>\n", html)
34
-
35
- CommonMarker.render_html(@markdown, :DEFAULT, %i[table strikethrough]).tap do |out|
36
- refute_includes out, '| a'
37
- refute_includes out, '| <strong>x</strong>'
38
- refute_includes out, '~~hi~~'
39
- end
40
- end
41
-
42
- def test_extensions_with_renderers
43
- doc = CommonMarker.render_doc(@markdown, :DEFAULT, %i[table])
44
-
45
- doc.to_html.tap do |out|
46
- refute_includes out, '| a'
47
- %w[<table> <tr> <th> a </th> <td> c </td> <strong>x</strong>].each { |html| assert_includes out, html }
48
- assert_includes out, '~~hi~~'
49
- end
50
-
51
- HtmlRenderer.new.render(doc).tap do |out|
52
- refute_includes out, '| a'
53
- %w[<table> <tr> <th> a </th> <td> c </td> <strong>x</strong>].each { |html| assert_includes out, html }
54
- assert_includes out, '~~hi~~'
55
- end
56
-
57
- doc = CommonMarker.render_doc('~a~ ~~b~~ ~~~c~~~', :STRIKETHROUGH_DOUBLE_TILDE, [:strikethrough])
58
- assert_equal("<p>~a~ <del>b</del> ~~~c~~~</p>\n", HtmlRenderer.new.render(doc))
59
- end
60
-
61
- def test_bad_extension_specifications
62
- assert_raises(TypeError) { CommonMarker.render_html(@markdown, :DEFAULT, 'nope') }
63
- assert_raises(TypeError) { CommonMarker.render_html(@markdown, :DEFAULT, ['table']) }
64
- assert_raises(ArgumentError) { CommonMarker.render_html(@markdown, :DEFAULT, %i[table bad]) }
65
- end
66
-
67
- def test_comments_are_kept_as_expected
68
- assert_equal "<!--hello--> <blah> &lt;xmp>\n",
69
- CommonMarker.render_html("<!--hello--> <blah> <xmp>\n", :UNSAFE, %i[tagfilter])
70
- end
71
-
72
- def test_table_prefer_style_attributes
73
- assert_equal(<<~HTML, CommonMarker.render_html(<<~MD, :TABLE_PREFER_STYLE_ATTRIBUTES, %i[table]))
74
- <table>
75
- <thead>
76
- <tr>
77
- <th style="text-align: left">aaa</th>
78
- <th>bbb</th>
79
- <th style="text-align: center">ccc</th>
80
- <th>ddd</th>
81
- <th style="text-align: right">eee</th>
82
- </tr>
83
- </thead>
84
- <tbody>
85
- <tr>
86
- <td style="text-align: left">fff</td>
87
- <td>ggg</td>
88
- <td style="text-align: center">hhh</td>
89
- <td>iii</td>
90
- <td style="text-align: right">jjj</td>
91
- </tr>
92
- </tbody>
93
- </table>
94
- HTML
95
- aaa | bbb | ccc | ddd | eee
96
- :-- | --- | :-: | --- | --:
97
- fff | ggg | hhh | iii | jjj
98
- MD
99
- end
100
-
101
- def test_plaintext
102
- assert_equal(<<~HTML, CommonMarker.render_doc(<<~MD, :DEFAULT, %i[table strikethrough]).to_plaintext)
103
- Hello ~there~.
104
-
105
- | a |
106
- | --- |
107
- | b |
108
- HTML
109
- Hello ~~there~~.
110
-
111
- | a |
112
- | - |
113
- | b |
114
- MD
115
- end
116
- end
@@ -1,60 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class TestFootnotes < Minitest::Test
6
- def setup
7
- @doc = CommonMarker.render_doc("Hello[^hi].\n\n[^hi]: Hey!\n", :FOOTNOTES)
8
- end
9
-
10
- def test_to_html
11
- expected = <<~HTML
12
- <p>Hello<sup class="footnote-ref"><a href="#fn-hi" id="fnref-hi" data-footnote-ref>1</a></sup>.</p>
13
- <section class="footnotes" data-footnotes>
14
- <ol>
15
- <li id="fn-hi">
16
- <p>Hey! <a href="#fnref-hi" class="footnote-backref" data-footnote-backref aria-label="Back to content">↩</a></p>
17
- </li>
18
- </ol>
19
- </section>
20
- HTML
21
-
22
- assert_equal expected, @doc.to_html
23
- end
24
-
25
- def test_html_renderer
26
- expected = <<~HTML
27
- <p>Hello<sup class="footnote-ref"><a href="#fn1" id="fnref1">1</a></sup>.</p>
28
- <section class="footnotes">
29
- <ol>
30
- <li id="fn1">
31
- <p>Hey! <a href="#fnref1" class="footnote-backref">↩</a></p>
32
- </li>
33
- </ol>
34
- </section>
35
- HTML
36
-
37
- assert_equal expected, CommonMarker::HtmlRenderer.new.render(@doc)
38
- end
39
-
40
- def test_render_html
41
- md = <<~MARKDOWN
42
- # footnotes
43
- Let's render some footnotes[^1]
44
-
45
- [^1]: This is a footnote
46
- MARKDOWN
47
- expected = <<~HTML
48
- <h1>footnotes</h1>
49
- <p>Let's render some footnotes<sup class="footnote-ref"><a href="#fn-1" id="fnref-1" data-footnote-ref>1</a></sup></p>
50
- <section class="footnotes" data-footnotes>
51
- <ol>
52
- <li id="fn-1">
53
- <p>This is a footnote <a href="#fnref-1" class="footnote-backref" data-footnote-backref aria-label="Back to content">↩</a></p>
54
- </li>
55
- </ol>
56
- </section>
57
- HTML
58
- assert_equal expected, CommonMarker.render_html(md, :FOOTNOTES)
59
- end
60
- end
data/test/test_gc.rb DELETED
@@ -1,47 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # rubocop:disable Lint/UselessAssignment
4
- require 'test_helper'
5
-
6
- class TestNode < Minitest::Test
7
- # These tests are somewhat fragile. It would be better to allocate lots
8
- # of memory after a GC run to make sure that potentially freed memory
9
- # isn't valid by accident.
10
-
11
- def test_drop_parent_reference
12
- doc = CommonMarker.render_doc('Hi *there*')
13
- text = doc.first_child.last_child.first_child
14
- doc = nil
15
- GC.start
16
- # Test that doc has not been freed.
17
- assert_equal 'there', text.string_content
18
- end
19
-
20
- def test_drop_child_reference
21
- doc = CommonMarker.render_doc('Hi *there*')
22
- text = doc.first_child.last_child.first_child
23
- text = nil
24
- GC.start
25
- # Test that the cached child object is still valid.
26
- text = doc.first_child.last_child.first_child
27
- assert_equal 'there', text.string_content
28
- end
29
-
30
- def test_remove_parent
31
- doc = CommonMarker.render_doc('Hi *there*')
32
- para = doc.first_child
33
- para.delete
34
- doc = nil
35
- para = nil
36
- # TODO: Test that the `para` node was actually freed after unlinking.
37
- end
38
-
39
- def test_add_parent
40
- doc = Node.new(:document)
41
- hrule = Node.new(:hrule)
42
- doc.append_child(hrule)
43
- # If the hrule node was erroneously freed, this would result in a double
44
- # free.
45
- end
46
- end
47
- # rubocop:enable Lint/UselessAssignment
data/test/test_helper.rb DELETED
@@ -1,71 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'commonmarker'
4
- require 'minitest/autorun'
5
- require 'minitest/pride'
6
- require 'minitest/focus'
7
-
8
- include CommonMarker # rubocop:disable Style/MixinUsage
9
-
10
- FIXTURES_DIR = File.join(File.dirname(__FILE__), 'fixtures')
11
-
12
- def fixtures_file(file)
13
- File.read(File.join(FIXTURES_DIR, file), encoding: 'utf-8')
14
- end
15
-
16
- def make_bin(file, args = '')
17
- `ruby bin/commonmarker #{File.join(FIXTURES_DIR, file)} #{args}`.chomp
18
- end
19
-
20
- def open_spec_file(filename)
21
- line_number = 0
22
- start_line = 0
23
- end_line = 0
24
- example_number = 0
25
- markdown_lines = []
26
- html_lines = []
27
- state = 0 # 0 regular text, 1 markdown example, 2 html output
28
- headertext = ''
29
- tests = []
30
- extensions = []
31
-
32
- header_re = Regexp.new('#+ ')
33
- filepath = File.join('ext', 'commonmarker', 'cmark-upstream', 'test', filename)
34
-
35
- File.readlines(filepath, encoding: 'utf-8').each do |line|
36
- line_number += 1
37
-
38
- l = line.strip
39
- if l =~ /^`{32} example(.*)$/
40
- state = 1
41
- extensions = Regexp.last_match(1).split
42
- elsif l == '`' * 32
43
- state = 0
44
- example_number += 1
45
- end_line = line_number
46
- tests << {
47
- markdown: markdown_lines.join.tr('→', "\t"),
48
- html: html_lines.join.tr('→', "\t").rstrip,
49
- example: example_number,
50
- start_line: start_line,
51
- end_line: end_line,
52
- section: headertext,
53
- extensions: extensions.map(&:to_sym)
54
- }
55
- start_line = 0
56
- markdown_lines = []
57
- html_lines = []
58
- elsif l == '.'
59
- state = 2
60
- elsif state == 1
61
- start_line = line_number - 1 if start_line.zero?
62
- markdown_lines << line.to_s
63
- elsif state == 2
64
- html_lines << line.to_s
65
- elsif state.zero? && header_re.match(line)
66
- headertext = line.sub(header_re, '').strip
67
- end
68
- end
69
-
70
- tests
71
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class TestLinebreaks < Minitest::Test
6
- def test_hardbreak_no_spaces
7
- doc = CommonMarker.render_doc("foo\nbaz")
8
- assert_equal "<p>foo<br />\nbaz</p>\n", doc.to_html(:HARDBREAKS)
9
- end
10
-
11
- def test_hardbreak_with_spaces
12
- doc = CommonMarker.render_doc("foo \nbaz")
13
- assert_equal "<p>foo<br />\nbaz</p>\n", doc.to_html(:HARDBREAKS)
14
- end
15
- end