qiita-markdown 0.44.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +2 -2
- data/.rubocop.yml +0 -4
- data/.rubocop_todo.yml +15 -239
- data/CHANGELOG.md +15 -0
- data/README.md +5 -3
- data/lib/qiita/markdown/filters/checkbox.rb +5 -1
- data/lib/qiita/markdown/filters/code_block.rb +13 -13
- data/lib/qiita/markdown/filters/custom_block.rb +8 -6
- data/lib/qiita/markdown/filters/external_link.rb +2 -0
- data/lib/qiita/markdown/filters/final_sanitizer.rb +126 -120
- data/lib/qiita/markdown/filters/footnote.rb +2 -0
- data/lib/qiita/markdown/filters/group_mention.rb +2 -2
- data/lib/qiita/markdown/filters/heading_anchor.rb +44 -0
- data/lib/qiita/markdown/filters/html_toc.rb +67 -0
- data/lib/qiita/markdown/filters/image_link.rb +6 -6
- data/lib/qiita/markdown/filters/inline_code_color.rb +8 -8
- data/lib/qiita/markdown/filters/mention.rb +11 -9
- data/lib/qiita/markdown/filters/qiita_marker.rb +55 -0
- data/lib/qiita/markdown/filters/simplify.rb +1 -0
- data/lib/qiita/markdown/filters/syntax_highlight.rb +4 -4
- data/lib/qiita/markdown/filters/truncate.rb +1 -3
- data/lib/qiita/markdown/filters/user_input_sanitizer.rb +34 -29
- data/lib/qiita/markdown/processor.rb +2 -1
- data/lib/qiita/markdown/summary_processor.rb +1 -1
- data/lib/qiita/markdown/transformers/filter_attributes.rb +1 -0
- data/lib/qiita/markdown/transformers/filter_iframe.rb +1 -2
- data/lib/qiita/markdown/transformers/filter_script.rb +1 -1
- data/lib/qiita/markdown/transformers/strip_invalid_node.rb +1 -3
- data/lib/qiita/markdown/version.rb +1 -1
- data/lib/qiita/markdown.rb +4 -5
- data/qiita-markdown.gemspec +7 -8
- data/spec/qiita/markdown/filters/checkbox_spec.rb +28 -0
- data/spec/qiita/markdown/filters/heading_anchor_spec.rb +73 -0
- data/spec/qiita/markdown/filters/html_toc_spec.rb +223 -0
- data/spec/qiita/markdown/filters/qiita_marker_spec.rb +60 -0
- data/spec/qiita/markdown/processor_spec.rb +64 -70
- data/spec/qiita/markdown/summary_processor_spec.rb +4 -4
- metadata +80 -102
- data/benchmark/heading_anchor_rendering.rb +0 -248
- data/benchmark/sample.md +0 -317
- data/lib/qiita/markdown/filters/greenmat.rb +0 -38
- data/lib/qiita/markdown/greenmat/heading_rendering.rb +0 -61
- data/lib/qiita/markdown/greenmat/html_renderer.rb +0 -60
- data/lib/qiita/markdown/greenmat/html_toc_renderer.rb +0 -78
- data/spec/qiita/markdown/filters/greenmat_spec.rb +0 -15
- data/spec/qiita/markdown/greenmat/html_toc_renderer_spec.rb +0 -156
@@ -1,36 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Qiita
|
2
4
|
module Markdown
|
3
5
|
module Filters
|
4
6
|
# Sanitizes user input if :strict context is given.
|
5
|
-
class UserInputSanitizer < HTML::Pipeline::Filter
|
7
|
+
class UserInputSanitizer < ::HTML::Pipeline::Filter
|
6
8
|
RULE = {
|
7
9
|
elements: %w[
|
8
|
-
a b blockquote br code dd del details div dl dt em font h1 h2 h3 h4 h5 h6
|
9
|
-
hr i img ins kbd li ol p pre q rp rt ruby s samp script iframe strike strong sub
|
10
|
+
a b blockquote br caption code dd del details div dl dt em font h1 h2 h3 h4 h5 h6
|
11
|
+
hr i img ins kbd li ol p pre q rp rt ruby s samp script iframe section strike strong sub
|
10
12
|
summary sup table tbody td tfoot th thead tr ul var
|
11
13
|
],
|
12
14
|
attributes: {
|
13
|
-
"a"
|
15
|
+
"a" => %w[class href rel title id],
|
14
16
|
"blockquote" => %w[cite] + Embed::Tweet::ATTRIBUTES,
|
15
|
-
"code"
|
16
|
-
"div"
|
17
|
-
"font"
|
18
|
-
"h1"
|
19
|
-
"h2"
|
20
|
-
"h3"
|
21
|
-
"h4"
|
22
|
-
"h5"
|
23
|
-
"h6"
|
24
|
-
"img"
|
25
|
-
"ins"
|
26
|
-
"li"
|
27
|
-
"p"
|
28
|
-
"q"
|
29
|
-
"
|
30
|
-
"
|
17
|
+
"code" => %w[data-metadata],
|
18
|
+
"div" => %w[class data-type data-metadata],
|
19
|
+
"font" => %w[color],
|
20
|
+
"h1" => %w[id],
|
21
|
+
"h2" => %w[id],
|
22
|
+
"h3" => %w[id],
|
23
|
+
"h4" => %w[id],
|
24
|
+
"h5" => %w[id],
|
25
|
+
"h6" => %w[id],
|
26
|
+
"img" => %w[alt height src title width],
|
27
|
+
"ins" => %w[cite datetime],
|
28
|
+
"li" => %w[id],
|
29
|
+
"p" => Embed::CodePen::ATTRIBUTES,
|
30
|
+
"q" => %w[cite],
|
31
|
+
"section" => %w[class],
|
32
|
+
"script" => %w[async src id].concat(
|
33
|
+
Embed::SpeekerDeck::ATTRIBUTES,
|
34
|
+
Embed::Docswell::ATTRIBUTES,
|
35
|
+
),
|
36
|
+
"iframe" => %w[
|
31
37
|
allowfullscreen
|
32
38
|
frameborder
|
33
39
|
height
|
40
|
+
loading
|
34
41
|
marginheight
|
35
42
|
marginwidth
|
36
43
|
scrolling
|
@@ -38,20 +45,18 @@ module Qiita
|
|
38
45
|
style
|
39
46
|
width
|
40
47
|
],
|
41
|
-
"sup"
|
42
|
-
"td"
|
43
|
-
"th"
|
48
|
+
"sup" => %w[id],
|
49
|
+
"td" => %w[colspan rowspan style],
|
50
|
+
"th" => %w[colspan rowspan style],
|
51
|
+
all: %w[data-sourcepos],
|
44
52
|
},
|
45
53
|
protocols: {
|
46
|
-
"a"
|
54
|
+
"a" => { "href" => ["http", "https", "mailto", :relative] },
|
47
55
|
"blockquote" => { "cite" => ["http", "https", :relative] },
|
48
|
-
"q"
|
56
|
+
"q" => { "cite" => ["http", "https", :relative] },
|
49
57
|
},
|
50
58
|
css: {
|
51
|
-
properties: %w[
|
52
|
-
text-align
|
53
|
-
border
|
54
|
-
],
|
59
|
+
properties: %w[text-align border],
|
55
60
|
},
|
56
61
|
transformers: [
|
57
62
|
Transformers::FilterAttributes,
|
@@ -45,7 +45,7 @@ module Qiita
|
|
45
45
|
def host_of(url)
|
46
46
|
if url
|
47
47
|
scheme = URI.parse(url).scheme
|
48
|
-
Addressable::URI.parse(url).host if [
|
48
|
+
Addressable::URI.parse(url).host if %w[http https].include? scheme
|
49
49
|
end
|
50
50
|
rescue Addressable::URI::InvalidURIError, URI::InvalidURIError
|
51
51
|
nil
|
data/lib/qiita/markdown.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
require "cgi"
|
2
|
-
require "greenmat"
|
3
2
|
require "html/pipeline"
|
4
3
|
require "linguist"
|
5
4
|
require "mem"
|
6
5
|
require "nokogiri"
|
6
|
+
require "qiita_marker"
|
7
7
|
require "rouge"
|
8
8
|
require "sanitize"
|
9
9
|
|
@@ -27,19 +27,18 @@ require "qiita/markdown/filters/emoji"
|
|
27
27
|
require "qiita/markdown/filters/external_link"
|
28
28
|
require "qiita/markdown/filters/final_sanitizer"
|
29
29
|
require "qiita/markdown/filters/footnote"
|
30
|
-
require "qiita/markdown/filters/greenmat"
|
31
30
|
require "qiita/markdown/filters/group_mention"
|
31
|
+
require "qiita/markdown/filters/heading_anchor"
|
32
|
+
require "qiita/markdown/filters/html_toc"
|
32
33
|
require "qiita/markdown/filters/image_link"
|
33
34
|
require "qiita/markdown/filters/inline_code_color"
|
34
35
|
require "qiita/markdown/filters/mention"
|
36
|
+
require "qiita/markdown/filters/qiita_marker"
|
35
37
|
require "qiita/markdown/filters/simplify"
|
36
38
|
require "qiita/markdown/filters/syntax_highlight"
|
37
39
|
require "qiita/markdown/filters/toc"
|
38
40
|
require "qiita/markdown/filters/truncate"
|
39
41
|
require "qiita/markdown/filters/user_input_sanitizer"
|
40
|
-
require "qiita/markdown/greenmat/heading_rendering"
|
41
|
-
require "qiita/markdown/greenmat/html_renderer"
|
42
|
-
require "qiita/markdown/greenmat/html_toc_renderer"
|
43
42
|
require "qiita/markdown/base_processor"
|
44
43
|
require "qiita/markdown/processor"
|
45
44
|
require "qiita/markdown/summary_processor"
|
data/qiita-markdown.gemspec
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
lib = File.expand_path("
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
2
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
3
|
require "qiita/markdown/version"
|
4
4
|
|
@@ -13,26 +13,25 @@ Gem::Specification.new do |spec|
|
|
13
13
|
|
14
14
|
spec.files = `git ls-files -z`.split("\x0")
|
15
15
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
16
|
spec.require_paths = ["lib"]
|
18
17
|
|
19
|
-
spec.required_ruby_version = ">= 2.
|
18
|
+
spec.required_ruby_version = ">= 2.7.0"
|
20
19
|
|
20
|
+
spec.add_dependency "addressable"
|
21
21
|
spec.add_dependency "gemoji"
|
22
22
|
spec.add_dependency "github-linguist", "~> 4.0"
|
23
23
|
spec.add_dependency "html-pipeline", "~> 2.0"
|
24
24
|
spec.add_dependency "mem"
|
25
25
|
spec.add_dependency "rouge", "3.26.0"
|
26
|
-
spec.add_dependency "greenmat", "3.5.1.4"
|
27
26
|
spec.add_dependency "sanitize"
|
28
|
-
spec.add_dependency "addressable"
|
29
27
|
spec.add_development_dependency "activesupport", "~> 5.2.7"
|
30
|
-
spec.add_development_dependency "benchmark-ips", "~> 1.2"
|
31
28
|
spec.add_development_dependency "bundler"
|
32
29
|
spec.add_development_dependency "codeclimate-test-reporter", "0.4.4"
|
33
|
-
spec.add_development_dependency "simplecov", "!= 0.18.0", "!= 0.18.1", "!= 0.18.2", "!= 0.18.3", "!= 0.18.4", "!= 0.18.5", "!= 0.19.0", "!= 0.19.1"
|
34
30
|
spec.add_development_dependency "pry"
|
31
|
+
spec.add_development_dependency "qiita_marker", "~> 0.23.6"
|
35
32
|
spec.add_development_dependency "rake", "~> 10.0"
|
36
33
|
spec.add_development_dependency "rspec", "~> 3.1"
|
37
|
-
spec.add_development_dependency "rubocop", "~> 1.
|
34
|
+
spec.add_development_dependency "rubocop", "~> 1.39.0"
|
35
|
+
spec.add_development_dependency "simplecov", "!= 0.18.0", "!= 0.18.1", "!= 0.18.2", "!= 0.18.3", "!= 0.18.4", "!= 0.18.5", "!= 0.19.0", "!= 0.19.1"
|
36
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
38
37
|
end
|
@@ -26,6 +26,34 @@ describe Qiita::Markdown::Filters::Checkbox do
|
|
26
26
|
expect(filter.call.to_s).to eq(output_html)
|
27
27
|
end
|
28
28
|
|
29
|
+
context "when list is loose" do
|
30
|
+
let(:input_html) do
|
31
|
+
<<~HTML
|
32
|
+
<li>
|
33
|
+
<p>[ ] a</p>
|
34
|
+
</li>
|
35
|
+
<li>
|
36
|
+
<p>[x] b</p>
|
37
|
+
</li>
|
38
|
+
HTML
|
39
|
+
end
|
40
|
+
|
41
|
+
let(:output_html) do
|
42
|
+
<<~HTML
|
43
|
+
<li class="task-list-item">
|
44
|
+
<p><input type="checkbox" class="task-list-item-checkbox" disabled>a</p>
|
45
|
+
</li>
|
46
|
+
<li class="task-list-item">
|
47
|
+
<p><input type="checkbox" class="task-list-item-checkbox" checked disabled>b</p>
|
48
|
+
</li>
|
49
|
+
HTML
|
50
|
+
end
|
51
|
+
|
52
|
+
it "replaces checkboxes" do
|
53
|
+
expect(filter.call.to_s).to eq(output_html)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
29
57
|
context "when input html has many spaces after checkbox mark" do
|
30
58
|
let(:input_html) do
|
31
59
|
<<~HTML
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe Qiita::Markdown::Filters::HeadingAnchor do
|
4
|
+
subject(:filter) { described_class.new(html) }
|
5
|
+
|
6
|
+
let(:html) do
|
7
|
+
<<~HTML
|
8
|
+
<h1>foo</h1>
|
9
|
+
<h2>bar</h2>
|
10
|
+
<h3>fizz</h3>
|
11
|
+
<p>paragraph</p>
|
12
|
+
<h4>buzz</h4>
|
13
|
+
<h5>hoge</h5>
|
14
|
+
<h6>fuga</h6>
|
15
|
+
<code>code</code>
|
16
|
+
HTML
|
17
|
+
end
|
18
|
+
|
19
|
+
it "renders ids" do
|
20
|
+
expect(filter.call.to_s).to eq(<<~HTML)
|
21
|
+
<h1 id="foo">foo</h1>
|
22
|
+
<h2 id="bar">bar</h2>
|
23
|
+
<h3 id="fizz">fizz</h3>
|
24
|
+
<p>paragraph</p>
|
25
|
+
<h4 id="buzz">buzz</h4>
|
26
|
+
<h5 id="hoge">hoge</h5>
|
27
|
+
<h6 id="fuga">fuga</h6>
|
28
|
+
<code>code</code>
|
29
|
+
HTML
|
30
|
+
end
|
31
|
+
|
32
|
+
context "with headings text is same" do
|
33
|
+
let(:html) do
|
34
|
+
<<~HTML
|
35
|
+
<h1>foo</h1>
|
36
|
+
<h2>foo</h2>
|
37
|
+
<h3>foo</h3>
|
38
|
+
<p>paragraph</p>
|
39
|
+
<h4>foo</h4>
|
40
|
+
<h5>foo</h5>
|
41
|
+
<h6>foo</h6>
|
42
|
+
<code>code</code>
|
43
|
+
HTML
|
44
|
+
end
|
45
|
+
|
46
|
+
it "renders suffixed ids" do
|
47
|
+
expect(filter.call.to_s).to eq(<<~HTML)
|
48
|
+
<h1 id="foo">foo</h1>
|
49
|
+
<h2 id="foo-1">foo</h2>
|
50
|
+
<h3 id="foo-2">foo</h3>
|
51
|
+
<p>paragraph</p>
|
52
|
+
<h4 id="foo-3">foo</h4>
|
53
|
+
<h5 id="foo-4">foo</h5>
|
54
|
+
<h6 id="foo-5">foo</h6>
|
55
|
+
<code>code</code>
|
56
|
+
HTML
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context "with characters that cannot included" do
|
61
|
+
let(:html) do
|
62
|
+
<<~HTML
|
63
|
+
<h1>test [foo-bar]</h1>
|
64
|
+
HTML
|
65
|
+
end
|
66
|
+
|
67
|
+
it "renders id with omitted characters" do
|
68
|
+
expect(filter.call.to_s).to eq(<<~HTML)
|
69
|
+
<h1 id="test-foo-bar">test [foo-bar]</h1>
|
70
|
+
HTML
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,223 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe Qiita::Markdown::Filters::HtmlToc do
|
4
|
+
subject(:filter) { described_class.new(html) }
|
5
|
+
|
6
|
+
context "with headings h1, h2, h3, h4, h5, h6" do
|
7
|
+
let(:html) do
|
8
|
+
<<~HTML
|
9
|
+
<h1 id="foo">foo</h1>
|
10
|
+
<h2 id="bar">bar</h2>
|
11
|
+
<h3 id="fizz">fizz</h3>
|
12
|
+
<p>paragraph</p>
|
13
|
+
<h4 id="buzz">buzz</h4>
|
14
|
+
<h5 id="hoge">hoge</h5>
|
15
|
+
<h6 id="fuga">fuga</h6>
|
16
|
+
<code>code</code>
|
17
|
+
HTML
|
18
|
+
end
|
19
|
+
|
20
|
+
let(:result) do
|
21
|
+
<<~HTML
|
22
|
+
<ul>
|
23
|
+
<li>
|
24
|
+
<a href="#foo">foo</a>
|
25
|
+
<ul>
|
26
|
+
<li>
|
27
|
+
<a href="#bar">bar</a>
|
28
|
+
<ul>
|
29
|
+
<li>
|
30
|
+
<a href="#fizz">fizz</a>
|
31
|
+
<ul>
|
32
|
+
<li>
|
33
|
+
<a href="#buzz">buzz</a>
|
34
|
+
<ul>
|
35
|
+
<li>
|
36
|
+
<a href="#hoge">hoge</a>
|
37
|
+
<ul>
|
38
|
+
<li>
|
39
|
+
<a href="#fuga">fuga</a>
|
40
|
+
</li>
|
41
|
+
</ul>
|
42
|
+
</li>
|
43
|
+
</ul>
|
44
|
+
</li>
|
45
|
+
</ul>
|
46
|
+
</li>
|
47
|
+
</ul>
|
48
|
+
</li>
|
49
|
+
</ul>
|
50
|
+
</li>
|
51
|
+
</ul>
|
52
|
+
HTML
|
53
|
+
end
|
54
|
+
|
55
|
+
it "renders nested toc" do
|
56
|
+
expect(filter.call).to eq(result)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context "headings are same rank" do
|
61
|
+
let(:html) do
|
62
|
+
<<~HTML
|
63
|
+
<h1 id="foo">foo</h1>
|
64
|
+
<h1 id="bar">bar</h1>
|
65
|
+
<h1 id="fizz">fizz</h1>
|
66
|
+
HTML
|
67
|
+
end
|
68
|
+
|
69
|
+
let(:result) do
|
70
|
+
<<~HTML
|
71
|
+
<ul>
|
72
|
+
<li>
|
73
|
+
<a href="#foo">foo</a>
|
74
|
+
</li>
|
75
|
+
<li>
|
76
|
+
<a href="#bar">bar</a>
|
77
|
+
</li>
|
78
|
+
<li>
|
79
|
+
<a href="#fizz">fizz</a>
|
80
|
+
</li>
|
81
|
+
</ul>
|
82
|
+
HTML
|
83
|
+
end
|
84
|
+
|
85
|
+
it "renders toc of same level" do
|
86
|
+
expect(filter.call).to eq(result)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context "with heading rank going up" do
|
91
|
+
let(:html) do
|
92
|
+
<<~HTML
|
93
|
+
<h1 id="foo">foo</h1>
|
94
|
+
<h3 id="bar">bar</h3>
|
95
|
+
<h1 id="bazz">bazz</h1>
|
96
|
+
HTML
|
97
|
+
end
|
98
|
+
|
99
|
+
let(:result) do
|
100
|
+
<<~HTML
|
101
|
+
<ul>
|
102
|
+
<li>
|
103
|
+
<a href="#foo">foo</a>
|
104
|
+
<ul>
|
105
|
+
<li>
|
106
|
+
<ul>
|
107
|
+
<li>
|
108
|
+
<a href="#bar">bar</a>
|
109
|
+
</li>
|
110
|
+
</ul>
|
111
|
+
</li>
|
112
|
+
</ul>
|
113
|
+
</li>
|
114
|
+
<li>
|
115
|
+
<a href="#bazz">bazz</a>
|
116
|
+
</li>
|
117
|
+
</ul>
|
118
|
+
HTML
|
119
|
+
end
|
120
|
+
|
121
|
+
it "renders toc that the depth goes up" do
|
122
|
+
expect(filter.call).to eq(result)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
context "with starting from h2" do
|
127
|
+
let(:html) do
|
128
|
+
<<~HTML
|
129
|
+
<h2 id="bar">bar</h2>
|
130
|
+
<h3 id="fizz">fizz</h3>
|
131
|
+
HTML
|
132
|
+
end
|
133
|
+
|
134
|
+
let(:result) do
|
135
|
+
<<~HTML
|
136
|
+
<ul>
|
137
|
+
<li>
|
138
|
+
<a href="#bar">bar</a>
|
139
|
+
<ul>
|
140
|
+
<li>
|
141
|
+
<a href="#fizz">fizz</a>
|
142
|
+
</li>
|
143
|
+
</ul>
|
144
|
+
</li>
|
145
|
+
</ul>
|
146
|
+
HTML
|
147
|
+
end
|
148
|
+
|
149
|
+
it "renders h2 as top level" do
|
150
|
+
expect(filter.call).to eq(result)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
context "with some heading rank is higher than first heading" do
|
155
|
+
let(:html) do
|
156
|
+
<<~HTML
|
157
|
+
<h2 id="foo">foo</h2>
|
158
|
+
<h3 id="bar">bar</h3>
|
159
|
+
<h1 id="fizz">fizz</h1>
|
160
|
+
<h2 id="bazz">bazz</h2>
|
161
|
+
HTML
|
162
|
+
end
|
163
|
+
|
164
|
+
let(:result) do
|
165
|
+
<<~HTML
|
166
|
+
<ul>
|
167
|
+
<li>
|
168
|
+
<a href="#foo">foo</a>
|
169
|
+
<ul>
|
170
|
+
<li>
|
171
|
+
<a href="#bar">bar</a>
|
172
|
+
</li>
|
173
|
+
</ul>
|
174
|
+
</li>
|
175
|
+
<li>
|
176
|
+
<a href="#fizz">fizz</a>
|
177
|
+
</li>
|
178
|
+
<li>
|
179
|
+
<a href="#bazz">bazz</a>
|
180
|
+
</li>
|
181
|
+
</ul>
|
182
|
+
HTML
|
183
|
+
end
|
184
|
+
|
185
|
+
it "renders higher rank headings at the same level as the first heading" do
|
186
|
+
expect(filter.call).to eq(result)
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
context "with include html tag" do
|
191
|
+
let(:html) do
|
192
|
+
<<~HTML
|
193
|
+
<h2 id="foo"><strong>foo</strong></h2>
|
194
|
+
HTML
|
195
|
+
end
|
196
|
+
|
197
|
+
let(:result) do
|
198
|
+
<<~HTML
|
199
|
+
<ul>
|
200
|
+
<li>
|
201
|
+
<a href="#foo">foo</a>
|
202
|
+
</li>
|
203
|
+
</ul>
|
204
|
+
HTML
|
205
|
+
end
|
206
|
+
|
207
|
+
it "anchor text does not include html tag" do
|
208
|
+
expect(filter.call).to eq(result)
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
context "without headings" do
|
213
|
+
let(:html) do
|
214
|
+
<<~HTML
|
215
|
+
<p>paragraph</p>
|
216
|
+
HTML
|
217
|
+
end
|
218
|
+
|
219
|
+
it "renders empty string" do
|
220
|
+
expect(filter.call.to_s).to eq("")
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe Qiita::Markdown::Filters::QiitaMarker do
|
4
|
+
subject(:filter) { described_class.new(markdown, context) }
|
5
|
+
|
6
|
+
let(:context) { nil }
|
7
|
+
|
8
|
+
context "with footnotes" do
|
9
|
+
let(:markdown) do
|
10
|
+
<<~MD
|
11
|
+
foo [^1]
|
12
|
+
[^1]: bar
|
13
|
+
MD
|
14
|
+
end
|
15
|
+
|
16
|
+
it "renders footnotes" do
|
17
|
+
expect(filter.call.to_s).to include('class="footnotes"')
|
18
|
+
end
|
19
|
+
|
20
|
+
context "and disable footnotes option" do
|
21
|
+
let(:context) do
|
22
|
+
{
|
23
|
+
markdown: {
|
24
|
+
footnotes: false,
|
25
|
+
},
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
it "does not render footnotes" do
|
30
|
+
expect(filter.call.to_s).not_to include('class="footnotes"')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "with sourcepos" do
|
36
|
+
let(:markdown) do
|
37
|
+
<<~MD
|
38
|
+
foo bar
|
39
|
+
MD
|
40
|
+
end
|
41
|
+
|
42
|
+
it "does not render HTML containing data-sourcepos" do
|
43
|
+
expect(filter.call.to_s).not_to include("data-sourcepos")
|
44
|
+
end
|
45
|
+
|
46
|
+
context "and enable sourcepos option" do
|
47
|
+
let(:context) do
|
48
|
+
{
|
49
|
+
markdown: {
|
50
|
+
sourcepos: true,
|
51
|
+
},
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
it "renders HTML containing data-sourcepos" do
|
56
|
+
expect(filter.call.to_s).to include("data-sourcepos")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|