qiita-markdown 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/lib/qiita/markdown/embed/code_pen.rb +1 -0
- data/lib/qiita/markdown/filters/code_block.rb +1 -1
- data/lib/qiita/markdown/version.rb +1 -1
- data/qiita-markdown.gemspec +1 -1
- data/spec/qiita/markdown/filters/code_block_spec.rb +126 -0
- data/spec/qiita/markdown/processor_spec.rb +25 -43
- metadata +10 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0ade2d671aa9407b7c4467426a70d4dffd0d1591549935cf079c1b58e2adb88
|
4
|
+
data.tar.gz: 3f1b894ce505d0f0703f4675e7c27908d6ef343b15a883bfd65434a084197c67
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3da8566097c634c94fc622e6eeddb422a7e5fbb70ab426189fcab9ed5e94d902deb3d73638b8f2fc119c1cd8e9785db623e66f74c953ddecb539a875ce6f6f87
|
7
|
+
data.tar.gz: 3951f59e21427af26fd58ad22ed0066d590e9d0faa7f6f7a77355d5ae6cf1c48fc38f091e8e906afa0ae2c544c98519239f7fbfff285aa05d230353f8fa8d1e3
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,7 @@ module Qiita
|
|
6
6
|
"https://production-assets.codepen.io/assets/embed/ei.js",
|
7
7
|
"https://static.codepen.io/assets/embed/ei.js",
|
8
8
|
"https://cpwebassets.codepen.io/assets/embed/ei.js",
|
9
|
+
"https://public.codepenassets.com/embed/index.js",
|
9
10
|
]
|
10
11
|
CLASS_NAME = %w[codepen]
|
11
12
|
DATA_ATTRIBUTES = %w[
|
data/qiita-markdown.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
|
20
20
|
spec.add_dependency "addressable"
|
21
21
|
spec.add_dependency "gemoji"
|
22
|
-
spec.add_dependency "github-linguist", "~>
|
22
|
+
spec.add_dependency "github-linguist", "~> 7.0"
|
23
23
|
spec.add_dependency "html-pipeline", "~> 2.0"
|
24
24
|
spec.add_dependency "mem"
|
25
25
|
spec.add_dependency "qiita_marker", "~> 0.23.9"
|
@@ -0,0 +1,126 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe Qiita::Markdown::Filters::CodeBlock do
|
4
|
+
subject(:filter) { described_class.new(input_html) }
|
5
|
+
|
6
|
+
let(:context) { nil }
|
7
|
+
|
8
|
+
context "without code" do
|
9
|
+
let(:input_html) do
|
10
|
+
<<~HTML
|
11
|
+
<pre>
|
12
|
+
</pre>
|
13
|
+
HTML
|
14
|
+
end
|
15
|
+
|
16
|
+
it "does not change" do
|
17
|
+
expect(filter.call.to_s).to eq(input_html)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context "with code" do
|
22
|
+
let(:input_html) do
|
23
|
+
<<~HTML
|
24
|
+
<pre><code>
|
25
|
+
</code></pre>
|
26
|
+
HTML
|
27
|
+
end
|
28
|
+
|
29
|
+
it "does not change" do
|
30
|
+
expect(filter.call.to_s).to eq(input_html)
|
31
|
+
end
|
32
|
+
|
33
|
+
context "with data-metadata" do
|
34
|
+
let(:input_html) do
|
35
|
+
<<~HTML
|
36
|
+
<pre><code data-metadata>
|
37
|
+
</code></pre>
|
38
|
+
HTML
|
39
|
+
end
|
40
|
+
|
41
|
+
it "does not change" do
|
42
|
+
expect(filter.call.to_s).to eq(input_html)
|
43
|
+
end
|
44
|
+
|
45
|
+
context "with data-metadata value" do
|
46
|
+
let(:input_html) do
|
47
|
+
<<~HTML
|
48
|
+
<pre><code data-metadata="ruby">
|
49
|
+
</code></pre>
|
50
|
+
HTML
|
51
|
+
end
|
52
|
+
|
53
|
+
let(:output_html) do
|
54
|
+
<<~HTML
|
55
|
+
<pre lang="ruby"><code data-metadata="ruby">
|
56
|
+
</code></pre>
|
57
|
+
HTML
|
58
|
+
end
|
59
|
+
|
60
|
+
it "adds lang on pre" do
|
61
|
+
expect(filter.call.to_s).to eq(output_html)
|
62
|
+
end
|
63
|
+
|
64
|
+
context "with value include filename" do
|
65
|
+
let(:input_html) do
|
66
|
+
<<~HTML
|
67
|
+
<pre><code data-metadata="ruby:abc.rb">
|
68
|
+
</code></pre>
|
69
|
+
HTML
|
70
|
+
end
|
71
|
+
|
72
|
+
let(:output_html) do
|
73
|
+
<<~HTML
|
74
|
+
<pre filename="abc.rb" lang="ruby"><code data-metadata="ruby:abc.rb">
|
75
|
+
</code></pre>
|
76
|
+
HTML
|
77
|
+
end
|
78
|
+
|
79
|
+
it "adds lang and filename on pre" do
|
80
|
+
expect(filter.call.to_s).to eq(output_html)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context "with data-metadata value like filename" do
|
86
|
+
let(:input_html) do
|
87
|
+
<<~HTML
|
88
|
+
<pre><code data-metadata="abc.rb">
|
89
|
+
</code></pre>
|
90
|
+
HTML
|
91
|
+
end
|
92
|
+
|
93
|
+
let(:output_html) do
|
94
|
+
<<~HTML
|
95
|
+
<pre filename="abc.rb" lang="ruby"><code data-metadata="abc.rb">
|
96
|
+
</code></pre>
|
97
|
+
HTML
|
98
|
+
end
|
99
|
+
|
100
|
+
it "adds lang and filename on pre" do
|
101
|
+
expect(filter.call.to_s).to eq(output_html)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context "with data-metadata value like filename without extension" do
|
106
|
+
let(:input_html) do
|
107
|
+
<<~HTML
|
108
|
+
<pre><code data-metadata="Dockerfile">
|
109
|
+
</code></pre>
|
110
|
+
HTML
|
111
|
+
end
|
112
|
+
|
113
|
+
let(:output_html) do
|
114
|
+
<<~HTML
|
115
|
+
<pre lang="Dockerfile"><code data-metadata="Dockerfile">
|
116
|
+
</code></pre>
|
117
|
+
HTML
|
118
|
+
end
|
119
|
+
|
120
|
+
it "adds lang and filename on pre" do
|
121
|
+
expect(filter.call.to_s).to eq(output_html)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
@@ -1406,52 +1406,34 @@ describe Qiita::Markdown::Processor do
|
|
1406
1406
|
end
|
1407
1407
|
|
1408
1408
|
shared_examples_for "override embed code attributes" do |allowed:|
|
1409
|
-
|
1410
|
-
|
1411
|
-
|
1412
|
-
|
1413
|
-
|
1414
|
-
|
1415
|
-
|
1416
|
-
|
1417
|
-
|
1418
|
-
it "does not sanitize embed code" do
|
1419
|
-
should eq <<-HTML.strip_heredoc
|
1420
|
-
<p data-height="1" data-theme-id="0" data-slug-hash="foo" data-default-tab="bar" data-user="baz" data-embed-version="2" data-pen-title="qux" class="codepen"></p>
|
1421
|
-
<script src="https://production-assets.codepen.io/assets/embed/ei.js"></script>
|
1422
|
-
HTML
|
1423
|
-
end
|
1424
|
-
else
|
1425
|
-
it "forces async attribute on script" do
|
1426
|
-
should eq <<-HTML.strip_heredoc
|
1409
|
+
[
|
1410
|
+
"https://production-assets.codepen.io/assets/embed/ei.js",
|
1411
|
+
"https://static.codepen.io/assets/embed/ei.js",
|
1412
|
+
"https://cpwebassets.codepen.io/assets/embed/ei.js",
|
1413
|
+
"https://public.codepenassets.com/embed/index.js",
|
1414
|
+
].each do |script_url|
|
1415
|
+
context "with HTML embed code for CodePen using script url `#{script_url}`" do
|
1416
|
+
let(:markdown) do
|
1417
|
+
<<-MARKDOWN.strip_heredoc
|
1427
1418
|
<p data-height="1" data-theme-id="0" data-slug-hash="foo" data-default-tab="bar" data-user="baz" data-embed-version="2" data-pen-title="qux" class="codepen"></p>
|
1428
|
-
<script src="
|
1429
|
-
|
1419
|
+
<script src="#{script_url}"></script>
|
1420
|
+
MARKDOWN
|
1430
1421
|
end
|
1431
|
-
end
|
1432
|
-
end
|
1433
1422
|
|
1434
|
-
|
1435
|
-
|
1436
|
-
|
1437
|
-
|
1438
|
-
|
1439
|
-
|
1440
|
-
|
1441
|
-
|
1442
|
-
|
1443
|
-
|
1444
|
-
|
1445
|
-
|
1446
|
-
|
1447
|
-
|
1448
|
-
end
|
1449
|
-
else
|
1450
|
-
it "forces async attribute on script" do
|
1451
|
-
should eq <<-HTML.strip_heredoc
|
1452
|
-
<p data-height="1" data-theme-id="0" data-slug-hash="foo" data-default-tab="bar" data-user="baz" data-embed-version="2" data-pen-title="qux" class="codepen"></p>
|
1453
|
-
<script src="https://static.codepen.io/assets/embed/ei.js" async="async"></script>
|
1454
|
-
HTML
|
1423
|
+
if allowed
|
1424
|
+
it "does not sanitize embed code" do
|
1425
|
+
should eq <<-HTML.strip_heredoc
|
1426
|
+
<p data-height="1" data-theme-id="0" data-slug-hash="foo" data-default-tab="bar" data-user="baz" data-embed-version="2" data-pen-title="qux" class="codepen"></p>
|
1427
|
+
<script src="#{script_url}"></script>
|
1428
|
+
HTML
|
1429
|
+
end
|
1430
|
+
else
|
1431
|
+
it "forces async attribute on script" do
|
1432
|
+
should eq <<-HTML.strip_heredoc
|
1433
|
+
<p data-height="1" data-theme-id="0" data-slug-hash="foo" data-default-tab="bar" data-user="baz" data-embed-version="2" data-pen-title="qux" class="codepen"></p>
|
1434
|
+
<script src="#{script_url}" async="async"></script>
|
1435
|
+
HTML
|
1436
|
+
end
|
1455
1437
|
end
|
1456
1438
|
end
|
1457
1439
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qiita-markdown
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryo Nakamura
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-01-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '7.0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '7.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: html-pipeline
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,7 +122,7 @@ dependencies:
|
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
|
-
description:
|
125
|
+
description:
|
126
126
|
email:
|
127
127
|
- r7kamura@gmail.com
|
128
128
|
executables: []
|
@@ -179,6 +179,7 @@ files:
|
|
179
179
|
- lib/qiita/markdown/version.rb
|
180
180
|
- qiita-markdown.gemspec
|
181
181
|
- spec/qiita/markdown/filters/checkbox_spec.rb
|
182
|
+
- spec/qiita/markdown/filters/code_block_spec.rb
|
182
183
|
- spec/qiita/markdown/filters/heading_anchor_spec.rb
|
183
184
|
- spec/qiita/markdown/filters/html_toc_spec.rb
|
184
185
|
- spec/qiita/markdown/filters/inline_code_color_spec.rb
|
@@ -191,7 +192,7 @@ licenses:
|
|
191
192
|
- MIT
|
192
193
|
metadata:
|
193
194
|
rubygems_mfa_required: 'true'
|
194
|
-
post_install_message:
|
195
|
+
post_install_message:
|
195
196
|
rdoc_options: []
|
196
197
|
require_paths:
|
197
198
|
- lib
|
@@ -206,8 +207,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
206
207
|
- !ruby/object:Gem::Version
|
207
208
|
version: '0'
|
208
209
|
requirements: []
|
209
|
-
rubygems_version: 3.
|
210
|
-
signing_key:
|
210
|
+
rubygems_version: 3.3.26
|
211
|
+
signing_key:
|
211
212
|
specification_version: 4
|
212
213
|
summary: Qiita-specified markdown processor.
|
213
214
|
test_files: []
|