qiita-markdown 1.4.0 → 1.6.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/dependabot.yml +4 -4
- data/.github/workflows/release.yml +1 -1
- data/.github/workflows/test.yml +1 -22
- data/CHANGELOG.md +8 -0
- data/Gemfile +0 -1
- data/README.md +0 -2
- data/lib/qiita/markdown/embed/figma.rb +4 -1
- data/lib/qiita/markdown/filters/inline_math.rb +43 -0
- data/lib/qiita/markdown/processor.rb +1 -0
- data/lib/qiita/markdown/transformers/filter_iframe.rb +1 -1
- data/lib/qiita/markdown/version.rb +1 -1
- data/lib/qiita/markdown.rb +1 -0
- data/spec/qiita/markdown/filters/inline_math_spec.rb +77 -0
- data/spec/qiita/markdown/processor_spec.rb +26 -18
- data/spec/spec_helper.rb +2 -7
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a030fef1d6e7c96945f3f3f32039906074ed0d7ca7773b857939740c2bbe2c1
|
4
|
+
data.tar.gz: 1fb0ec10eb4849a69f49942565b6fd2250c1548244267f3a29643f8a3558a3b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7955e98dd0f03db994cd7e04060269aed6763bb17bf1742064098f193b53f22d0866a36cc1d18ac95502c667f807e7966a29144035e254d45578ca374a63cc6d
|
7
|
+
data.tar.gz: 7ef8f9c22b7159da5e02cf9366584d39cd375dafb6666dc364de22f204b724f391fecd3f16793388f2c090354204ef8cb6d6fc1f37282cf3abb4b11baa67b378
|
data/.github/dependabot.yml
CHANGED
@@ -5,8 +5,8 @@ updates:
|
|
5
5
|
directories:
|
6
6
|
- "/"
|
7
7
|
schedule:
|
8
|
-
interval: "
|
9
|
-
|
8
|
+
interval: "weekly"
|
9
|
+
day: "sunday"
|
10
10
|
timezone: "Asia/Tokyo"
|
11
11
|
open-pull-requests-limit: 5
|
12
12
|
rebase-strategy: "disabled"
|
@@ -15,8 +15,8 @@ updates:
|
|
15
15
|
directories:
|
16
16
|
- "/"
|
17
17
|
schedule:
|
18
|
-
interval: "
|
19
|
-
|
18
|
+
interval: "weekly"
|
19
|
+
day: "sunday"
|
20
20
|
timezone: "Asia/Tokyo"
|
21
21
|
open-pull-requests-limit: 5
|
22
22
|
rebase-strategy: "disabled"
|
@@ -15,7 +15,7 @@ jobs:
|
|
15
15
|
|
16
16
|
steps:
|
17
17
|
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
18
|
-
- uses: ruby/setup-ruby@
|
18
|
+
- uses: ruby/setup-ruby@efbf473cab83af4468e8606cc33eca9281bb213f # v1.256.0
|
19
19
|
with:
|
20
20
|
ruby-version: 3.4.4 # Latest stable Ruby for release builds
|
21
21
|
bundler-cache: true
|
data/.github/workflows/test.yml
CHANGED
@@ -11,27 +11,6 @@ permissions:
|
|
11
11
|
contents: read
|
12
12
|
|
13
13
|
jobs:
|
14
|
-
codeclimate:
|
15
|
-
runs-on: ubuntu-latest
|
16
|
-
steps:
|
17
|
-
- name: Get branch names
|
18
|
-
id: branch-name
|
19
|
-
uses: tj-actions/branch-names@dde14ac574a8b9b1cedc59a1cf312788af43d8d8 # v8.2.1
|
20
|
-
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
|
21
|
-
- uses: ruby/setup-ruby@13e7a03dc3ac6c3798f4570bfead2aed4d96abfb # v1.244.0
|
22
|
-
with:
|
23
|
-
ruby-version: '3.2'
|
24
|
-
bundler-cache: true
|
25
|
-
- name: Test & publish code coverage
|
26
|
-
if: "${{ env.CC_TEST_REPORTER_ID != '' }}"
|
27
|
-
uses: paambaati/codeclimate-action@7bcf9e73c0ee77d178e72c0ec69f1a99c1afc1f3 # v2.7.5
|
28
|
-
env:
|
29
|
-
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
|
30
|
-
GIT_BRANCH: ${{ steps.branch-name.outputs.current_branch }}
|
31
|
-
GIT_COMMIT_SHA: ${{ github.sha }}
|
32
|
-
with:
|
33
|
-
coverageCommand: bundle exec rake
|
34
|
-
|
35
14
|
test:
|
36
15
|
strategy:
|
37
16
|
fail-fast: false
|
@@ -47,7 +26,7 @@ jobs:
|
|
47
26
|
continue-on-error: ${{ matrix.experimental }}
|
48
27
|
steps:
|
49
28
|
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
|
50
|
-
- uses: ruby/setup-ruby@
|
29
|
+
- uses: ruby/setup-ruby@efbf473cab83af4468e8606cc33eca9281bb213f # v1.256.0
|
51
30
|
with:
|
52
31
|
ruby-version: ${{ matrix.ruby }}
|
53
32
|
bundler-cache: true
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -2,8 +2,6 @@
|
|
2
2
|
|
3
3
|
[](https://badge.fury.io/rb/qiita-markdown)
|
4
4
|
[](https://travis-ci.org/increments/qiita-markdown)
|
5
|
-
[](https://codeclimate.com/github/increments/qiita-markdown)
|
6
|
-
[](https://codeclimate.com/github/increments/qiita-markdown)
|
7
5
|
|
8
6
|
Qiita-specified markdown processor.
|
9
7
|
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Qiita
|
4
|
+
module Markdown
|
5
|
+
module Filters
|
6
|
+
class InlineMath < HTML::Pipeline::Filter
|
7
|
+
def call
|
8
|
+
doc.search(".//code").each do |code|
|
9
|
+
opening = code.previous
|
10
|
+
closing = code.next
|
11
|
+
replace_with_math_span(code, opening, closing) if inline_math_code?(opening, closing)
|
12
|
+
end
|
13
|
+
|
14
|
+
doc
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def inline_math_code?(opening, closing)
|
20
|
+
opening.present? && closing.present? && valid_opening?(opening) && valid_closing?(closing)
|
21
|
+
end
|
22
|
+
|
23
|
+
def valid_opening?(opening)
|
24
|
+
opening.text? && opening.content.end_with?("$") && !opening.content.end_with?("$$")
|
25
|
+
end
|
26
|
+
|
27
|
+
def valid_closing?(closing)
|
28
|
+
closing.text? && closing.content.start_with?("$") && !closing.content.start_with?("$$")
|
29
|
+
end
|
30
|
+
|
31
|
+
def replace_with_math_span(code, opening, closing)
|
32
|
+
span = Nokogiri::XML::Node.new("span", doc)
|
33
|
+
span.add_child(Nokogiri::XML::Text.new("$#{code.text}$", doc))
|
34
|
+
code.replace(span)
|
35
|
+
opening.content = opening.content.delete_suffix("$")
|
36
|
+
opening.remove if opening.content.empty?
|
37
|
+
closing.content = closing.content.delete_prefix("$")
|
38
|
+
closing.remove if closing.content.empty?
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -9,7 +9,7 @@ module Qiita
|
|
9
9
|
Embed::SlideShare::SCRIPT_HOST,
|
10
10
|
Embed::GoogleSlide::SCRIPT_HOST,
|
11
11
|
Embed::Docswell::SCRIPT_HOSTS,
|
12
|
-
Embed::Figma::
|
12
|
+
Embed::Figma::SCRIPT_HOSTS,
|
13
13
|
Embed::GoogleDrive::SCRIPT_HOST,
|
14
14
|
Embed::StackBlitz::SCRIPT_HOST,
|
15
15
|
Embed::BlueprintUe::SCRIPT_HOST,
|
data/lib/qiita/markdown.rb
CHANGED
@@ -36,6 +36,7 @@ require "qiita/markdown/filters/heading_anchor"
|
|
36
36
|
require "qiita/markdown/filters/html_toc"
|
37
37
|
require "qiita/markdown/filters/image_link"
|
38
38
|
require "qiita/markdown/filters/inline_code_color"
|
39
|
+
require "qiita/markdown/filters/inline_math"
|
39
40
|
require "qiita/markdown/filters/mention"
|
40
41
|
require "qiita/markdown/filters/qiita_marker"
|
41
42
|
require "qiita/markdown/filters/simplify"
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe Qiita::Markdown::Filters::InlineMath do
|
4
|
+
subject(:filter) do
|
5
|
+
described_class.new(html)
|
6
|
+
end
|
7
|
+
|
8
|
+
context "with dollar signs" do
|
9
|
+
let(:html) do
|
10
|
+
<<~HTML
|
11
|
+
<div>
|
12
|
+
$<code>A = B</code>$
|
13
|
+
</div>
|
14
|
+
HTML
|
15
|
+
end
|
16
|
+
|
17
|
+
it "replaces <code> to <span> with dollars" do
|
18
|
+
expect(filter.call.to_html).to eq(
|
19
|
+
<<~HTML,
|
20
|
+
<div>
|
21
|
+
<span>$A = B$</span>
|
22
|
+
</div>
|
23
|
+
HTML
|
24
|
+
)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "with dollar signs with surrounding text" do
|
29
|
+
let(:html) do
|
30
|
+
<<~HTML
|
31
|
+
<div>
|
32
|
+
Some text before$<code>A = B</code>$Some text after
|
33
|
+
</div>
|
34
|
+
HTML
|
35
|
+
end
|
36
|
+
|
37
|
+
it "replaces <code> to <span> with dollars" do
|
38
|
+
expect(filter.call.to_html).to eq(
|
39
|
+
<<~HTML,
|
40
|
+
<div>
|
41
|
+
Some text before<span>$A = B$</span>Some text after
|
42
|
+
</div>
|
43
|
+
HTML
|
44
|
+
)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "with double dollar signs" do
|
49
|
+
let(:html) do
|
50
|
+
<<~HTML
|
51
|
+
<div>
|
52
|
+
$$
|
53
|
+
<code>A = B</code>
|
54
|
+
$$
|
55
|
+
</div>
|
56
|
+
HTML
|
57
|
+
end
|
58
|
+
|
59
|
+
it "does not replace <code>" do
|
60
|
+
expect(filter.call.to_html).to eq(html)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context "without dollar signs" do
|
65
|
+
let(:html) do
|
66
|
+
<<~HTML
|
67
|
+
<div>
|
68
|
+
<code>A = B</code>
|
69
|
+
</div>
|
70
|
+
HTML
|
71
|
+
end
|
72
|
+
|
73
|
+
it "does not replace <code>" do
|
74
|
+
expect(filter.call.to_html).to eq(html)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -1632,25 +1632,33 @@ describe Qiita::Markdown::Processor do
|
|
1632
1632
|
|
1633
1633
|
context "with HTML embed code for Figma" do
|
1634
1634
|
shared_examples "embed code figma example" do
|
1635
|
-
|
1636
|
-
|
1637
|
-
|
1638
|
-
|
1639
|
-
|
1640
|
-
|
1641
|
-
|
1635
|
+
[
|
1636
|
+
"www.figma.com/embed?embed_host=share&url=https%3A%2F%2Fwww.figma.com",
|
1637
|
+
"embed.figma.com/design/nrPSsILSYjesyc5UHjYYa4?embed_host=share",
|
1638
|
+
].each do |script_url|
|
1639
|
+
context "with HTML embed code for Figma using script url `#{script_url}`" do
|
1640
|
+
let(:markdown) do
|
1641
|
+
<<-MARKDOWN.strip_heredoc
|
1642
|
+
<iframe style="border: 1px solid rgba(0, 0, 0, 0.1);" width="100" height="100" src="#{url}"></iframe>
|
1643
|
+
MARKDOWN
|
1644
|
+
end
|
1642
1645
|
|
1643
|
-
|
1644
|
-
|
1645
|
-
|
1646
|
-
|
1647
|
-
|
1648
|
-
|
1649
|
-
|
1650
|
-
|
1651
|
-
|
1652
|
-
|
1653
|
-
|
1646
|
+
let(:url) { "#{scheme}//#{script_url}" }
|
1647
|
+
let(:encoded_url) { CGI.escapeHTML(url) }
|
1648
|
+
|
1649
|
+
if allowed
|
1650
|
+
it "does not sanitize embed code" do
|
1651
|
+
should eq <<-HTML.strip_heredoc
|
1652
|
+
<iframe style="border: 1px solid rgba(0, 0, 0, 0.1);" width="100" height="100" src="#{encoded_url}"></iframe>
|
1653
|
+
HTML
|
1654
|
+
end
|
1655
|
+
else
|
1656
|
+
it "forces width attribute on iframe" do
|
1657
|
+
should eq <<-HTML.strip_heredoc
|
1658
|
+
<iframe style="border: 1px solid rgba(0, 0, 0, 0.1);" width="100%" height="100" src="#{encoded_url}"></iframe>
|
1659
|
+
HTML
|
1660
|
+
end
|
1661
|
+
end
|
1654
1662
|
end
|
1655
1663
|
end
|
1656
1664
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qiita-markdown
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryo Nakamura
|
@@ -167,6 +167,7 @@ files:
|
|
167
167
|
- lib/qiita/markdown/filters/html_toc.rb
|
168
168
|
- lib/qiita/markdown/filters/image_link.rb
|
169
169
|
- lib/qiita/markdown/filters/inline_code_color.rb
|
170
|
+
- lib/qiita/markdown/filters/inline_math.rb
|
170
171
|
- lib/qiita/markdown/filters/mention.rb
|
171
172
|
- lib/qiita/markdown/filters/qiita_marker.rb
|
172
173
|
- lib/qiita/markdown/filters/simplify.rb
|
@@ -187,6 +188,7 @@ files:
|
|
187
188
|
- spec/qiita/markdown/filters/heading_anchor_spec.rb
|
188
189
|
- spec/qiita/markdown/filters/html_toc_spec.rb
|
189
190
|
- spec/qiita/markdown/filters/inline_code_color_spec.rb
|
191
|
+
- spec/qiita/markdown/filters/inline_math_spec.rb
|
190
192
|
- spec/qiita/markdown/filters/qiita_marker_spec.rb
|
191
193
|
- spec/qiita/markdown/processor_spec.rb
|
192
194
|
- spec/qiita/markdown/summary_processor_spec.rb
|