qiita_marker 0.23.2.1 → 0.23.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +19 -17
- data/README.md +2 -0
- data/Rakefile +57 -56
- data/bin/qiita_marker +2 -7
- data/ext/qiita_marker/autolink.c +57 -10
- data/ext/qiita_marker/cmark-gfm_version.h +2 -2
- data/ext/qiita_marker/html.c +1 -1
- data/ext/qiita_marker/qfm.h +3 -0
- data/ext/qiita_marker/qfm_custom_block.c +1 -14
- data/ext/qiita_marker/qfm_mention_no_emphasis.c +1 -1
- data/ext/qiita_marker/qiita_marker.c +30 -44
- data/ext/qiita_marker/scanners.c +2438 -2450
- data/ext/qiita_marker/table.c +28 -2
- data/lib/qiita_marker/config.rb +5 -3
- data/lib/qiita_marker/node/inspect.rb +8 -18
- data/lib/qiita_marker/node.rb +6 -6
- data/lib/qiita_marker/renderer/html_renderer.rb +39 -39
- data/lib/qiita_marker/renderer.rb +5 -5
- data/lib/qiita_marker/version.rb +1 -1
- data/lib/qiita_marker.rb +9 -11
- data/qiita_marker.gemspec +27 -29
- metadata +3 -61
- data/test/benchmark.rb +0 -32
- data/test/fixtures/curly.md +0 -1
- data/test/fixtures/dingus.md +0 -10
- data/test/fixtures/strong.md +0 -1
- data/test/fixtures/table.md +0 -10
- data/test/test_attributes.rb +0 -24
- data/test/test_basics.rb +0 -35
- data/test/test_commands.rb +0 -72
- data/test/test_commonmark.rb +0 -36
- data/test/test_doc.rb +0 -130
- data/test/test_encoding.rb +0 -23
- data/test/test_extensions.rb +0 -116
- data/test/test_footnotes.rb +0 -60
- data/test/test_gc.rb +0 -47
- data/test/test_helper.rb +0 -71
- data/test/test_linebreaks.rb +0 -15
- data/test/test_maliciousness.rb +0 -262
- data/test/test_node.rb +0 -89
- data/test/test_options.rb +0 -37
- data/test/test_pathological_inputs.rb +0 -94
- data/test/test_plaintext.rb +0 -46
- data/test/test_qfm_code_data_metadata.rb +0 -26
- data/test/test_qfm_custom_block.rb +0 -23
- data/test/test_qfm_mention_no_emphasis.rb +0 -60
- data/test/test_renderer.rb +0 -47
- data/test/test_smartpunct.rb +0 -27
- data/test/test_spec.rb +0 -30
- data/test/test_tasklists.rb +0 -43
- data/test/test_xml.rb +0 -107
data/test/benchmark.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'qiita_marker'
|
4
|
-
require 'github/markdown'
|
5
|
-
require 'redcarpet'
|
6
|
-
require 'kramdown'
|
7
|
-
require 'benchmark'
|
8
|
-
|
9
|
-
def dobench(name, &blk)
|
10
|
-
puts name
|
11
|
-
puts Benchmark.measure(&blk)
|
12
|
-
end
|
13
|
-
|
14
|
-
benchinput = File.open('test/benchinput.md', 'r').read
|
15
|
-
|
16
|
-
printf("input size = %<bytes>d bytes\n\n", benchinput.bytesize)
|
17
|
-
|
18
|
-
dobench('redcarpet') do
|
19
|
-
Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: false, tables: false).render(benchinput)
|
20
|
-
end
|
21
|
-
|
22
|
-
dobench('qiita_marker with to_html') do
|
23
|
-
QiitaMarker.render_html(benchinput)
|
24
|
-
end
|
25
|
-
|
26
|
-
dobench('qiita_marker with ruby HtmlRenderer') do
|
27
|
-
QiitaMarker::HtmlRenderer.new.render(QiitaMarker.render_doc(benchinput))
|
28
|
-
end
|
29
|
-
|
30
|
-
dobench('kramdown') do
|
31
|
-
Kramdown::Document.new(benchinput).to_html(benchinput)
|
32
|
-
end
|
data/test/fixtures/curly.md
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
This curly quote “makes qiita_marker throw an exception”.
|
data/test/fixtures/dingus.md
DELETED
data/test/fixtures/strong.md
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
I am **strong**
|
data/test/fixtures/table.md
DELETED
data/test/test_attributes.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class TestAttributes < Minitest::Test
|
6
|
-
def setup
|
7
|
-
contents = fixtures_file('dingus.md')
|
8
|
-
@doc = QiitaMarker.render_doc(contents.strip)
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_sourcepos
|
12
|
-
sourcepos = []
|
13
|
-
|
14
|
-
@doc.walk do |node|
|
15
|
-
sourcepos << node.sourcepos
|
16
|
-
end
|
17
|
-
|
18
|
-
sourcepos.delete_if { |h| h.values.all?(&:zero?) }
|
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 }]
|
21
|
-
|
22
|
-
assert_equal result, sourcepos
|
23
|
-
end
|
24
|
-
end
|
data/test/test_basics.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class TestBasics < Minitest::Test
|
6
|
-
def setup
|
7
|
-
@doc = QiitaMarker.render_doc('Hi *there*')
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_to_html
|
11
|
-
assert_equal "<p>Hi <em>there</em></p>\n", @doc.to_html
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_markdown_to_html
|
15
|
-
html = QiitaMarker.render_html('Hi *there*')
|
16
|
-
assert_equal "<p>Hi <em>there</em></p>\n", html
|
17
|
-
end
|
18
|
-
|
19
|
-
# basic test that just checks if every option is accepted & no errors are thrown
|
20
|
-
def test_accept_every_option
|
21
|
-
text = "Hello **world** -- how are _you_ today? I'm ~~fine~~, ~yourself~?"
|
22
|
-
parse_opt = %i[SOURCEPOS UNSAFE VALIDATE_UTF8 SMART LIBERAL_HTML_TAG FOOTNOTES STRIKETHROUGH_DOUBLE_TILDE]
|
23
|
-
render_opt = parse_opt + %i[HARDBREAKS NOBREAKS GITHUB_PRE_LANG TABLE_PREFER_STYLE_ATTRIBUTES FULL_INFO_STRING]
|
24
|
-
|
25
|
-
extensions = %i[table tasklist strikethrough autolink tagfilter]
|
26
|
-
|
27
|
-
assert_equal "<p>Hello <strong>world</strong> – how are <em>you</em> today? I’m <del>fine</del>, ~yourself~?</p>\n", QiitaMarker.render_doc(text, parse_opt, extensions).to_html
|
28
|
-
|
29
|
-
# NOTE: how tho the doc returned has sourcepos info, by default the renderer
|
30
|
-
# won't emit it. for that we need to pass in the render opt
|
31
|
-
assert_equal "<p data-sourcepos=\"1:1-1:65\">Hello <strong>world</strong> – how are <em>you</em> today? I’m <del>fine</del>, ~yourself~?</p>\n", QiitaMarker.render_doc(text, parse_opt, extensions).to_html(render_opt, extensions)
|
32
|
-
|
33
|
-
assert_equal "<p data-sourcepos=\"1:1-1:65\">Hello <strong>world</strong> – how are <em>you</em> today? I’m <del>fine</del>, ~yourself~?</p>\n", QiitaMarker.render_html(text, parse_opt, extensions)
|
34
|
-
end
|
35
|
-
end
|
data/test/test_commands.rb
DELETED
@@ -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
|
-
(QiitaMarker::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
|
data/test/test_commonmark.rb
DELETED
@@ -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
|
-
QiitaMarker.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 = QiitaMarker.render_doc('Hi *there*. This has __many nodes__!')
|
8
|
-
@first_child = @doc.first_child
|
9
|
-
@last_child = @doc.last_child
|
10
|
-
@link = QiitaMarker.render_doc('[GitHub](https://www.github.com)').first_child.first_child
|
11
|
-
@image = QiitaMarker.render_doc('![alt text](https://github.com/favicon.ico "Favicon")')
|
12
|
-
@image = @image.first_child.first_child
|
13
|
-
@header = QiitaMarker.render_doc('### Header Three').first_child
|
14
|
-
@ul_list = QiitaMarker.render_doc("* Bullet\n*Bullet").first_child
|
15
|
-
@ol_list = QiitaMarker.render_doc("1. One\n2. Two").first_child
|
16
|
-
@fence = QiitaMarker.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
|
data/test/test_encoding.rb
DELETED
@@ -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 = QiitaMarker.render_doc(contents, :SMART)
|
10
|
-
render = doc.to_html
|
11
|
-
assert_equal('<p>This curly quote “makes qiita_marker throw an exception”.</p>', render.rstrip)
|
12
|
-
|
13
|
-
render = doc.to_xml
|
14
|
-
assert_includes(render, '<text xml:space="preserve">This curly quote “makes qiita_marker throw an exception”.</text>')
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_string_content_is_utf8
|
18
|
-
doc = QiitaMarker.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
|
data/test/test_extensions.rb
DELETED
@@ -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
|
-
QiitaMarker.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
|
-
QiitaMarker.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
|
-
QiitaMarker.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 = QiitaMarker.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 = QiitaMarker.render_html('~a~ ~~b~~ ~~~c~~~', :STRIKETHROUGH_DOUBLE_TILDE, [:strikethrough])
|
33
|
-
assert_equal("<p>~a~ <del>b</del> ~~~c~~~</p>\n", html)
|
34
|
-
|
35
|
-
QiitaMarker.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 = QiitaMarker.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 = QiitaMarker.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) { QiitaMarker.render_html(@markdown, :DEFAULT, 'nope') }
|
63
|
-
assert_raises(TypeError) { QiitaMarker.render_html(@markdown, :DEFAULT, ['table']) }
|
64
|
-
assert_raises(ArgumentError) { QiitaMarker.render_html(@markdown, :DEFAULT, %i[table bad]) }
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_comments_are_kept_as_expected
|
68
|
-
assert_equal "<!--hello--> <blah> <xmp>\n",
|
69
|
-
QiitaMarker.render_html("<!--hello--> <blah> <xmp>\n", :UNSAFE, %i[tagfilter])
|
70
|
-
end
|
71
|
-
|
72
|
-
def test_table_prefer_style_attributes
|
73
|
-
assert_equal(<<~HTML, QiitaMarker.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, QiitaMarker.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
|
data/test/test_footnotes.rb
DELETED
@@ -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 = QiitaMarker.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, QiitaMarker::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, QiitaMarker.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 = QiitaMarker.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 = QiitaMarker.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 = QiitaMarker.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 'qiita_marker'
|
4
|
-
require 'minitest/autorun'
|
5
|
-
require 'minitest/pride'
|
6
|
-
require 'minitest/focus'
|
7
|
-
|
8
|
-
include QiitaMarker # 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/qiita_marker #{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', 'qiita_marker', '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
|