qiita-markdown 1.5.0 → 1.6.1
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 -0
- data/.github/workflows/test.yml +15 -0
- data/CHANGELOG.md +8 -0
- data/Gemfile +1 -0
- data/README.md +2 -0
- data/lib/qiita/markdown/filters/inline_math.rb +43 -0
- data/lib/qiita/markdown/processor.rb +1 -0
- data/lib/qiita/markdown/version.rb +1 -1
- data/lib/qiita/markdown.rb +1 -0
- data/qiita-markdown.gemspec +1 -0
- data/spec/qiita/markdown/filters/inline_math_spec.rb +77 -0
- data/spec/spec_helper.rb +9 -1
- metadata +17 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82135467b0d5d3bf73ec7e94d45f1cb48507eab15bcf0624f14d6cd33ee7b3df
|
4
|
+
data.tar.gz: 31ebd2cb70c3f3c9e632c49ea3baeb8dff5d869e9ecb3aac8051158054bccef7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce417c195faa1b52f8cb70f81a654efc5bacda6338aedff1e3a9601cb4b210280a25aa7a763a3fb59f229ac767659b5fcc31b8673e2199a35fbad583cfab69eb
|
7
|
+
data.tar.gz: bc58fbba5f0e8a56ebeed5b97b4f1c97f5fe6c91526aeccdd104b43cc02e7f0d850a4a26ce2b7b558382f4910da5a1da2e139d13f2c9a09ad32a38fdc940764e
|
data/.github/dependabot.yml
CHANGED
@@ -10,6 +10,8 @@ updates:
|
|
10
10
|
timezone: "Asia/Tokyo"
|
11
11
|
open-pull-requests-limit: 5
|
12
12
|
rebase-strategy: "disabled"
|
13
|
+
cooldown:
|
14
|
+
default-days: 7
|
13
15
|
|
14
16
|
- package-ecosystem: "github-actions"
|
15
17
|
directories:
|
@@ -20,3 +22,5 @@ updates:
|
|
20
22
|
timezone: "Asia/Tokyo"
|
21
23
|
open-pull-requests-limit: 5
|
22
24
|
rebase-strategy: "disabled"
|
25
|
+
cooldown:
|
26
|
+
default-days: 7
|
data/.github/workflows/test.yml
CHANGED
@@ -32,3 +32,18 @@ jobs:
|
|
32
32
|
bundler-cache: true
|
33
33
|
- name: Test
|
34
34
|
run: bundle exec rake
|
35
|
+
|
36
|
+
qlty:
|
37
|
+
runs-on: ubuntu-latest
|
38
|
+
steps:
|
39
|
+
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
|
40
|
+
- uses: ruby/setup-ruby@13e7a03dc3ac6c3798f4570bfead2aed4d96abfb # v1.244.0
|
41
|
+
with:
|
42
|
+
ruby-version: '3.2'
|
43
|
+
bundler-cache: true
|
44
|
+
- name: Test
|
45
|
+
run: bundle exec rake
|
46
|
+
- uses: qltysh/qlty-action/coverage@a19242102d17e497f437d7466aa01b528537e899 # v2.2.0
|
47
|
+
with:
|
48
|
+
token: ${{secrets.QLTY_COVERAGE_TOKEN}}
|
49
|
+
files: ./coverage/coverage.json
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
[](https://badge.fury.io/rb/qiita-markdown)
|
4
4
|
[](https://travis-ci.org/increments/qiita-markdown)
|
5
|
+
[](https://qlty.sh/gh/increments/projects/qiita-markdown)
|
6
|
+
[](https://qlty.sh/gh/increments/projects/qiita-markdown)
|
5
7
|
|
6
8
|
Qiita-specified markdown processor.
|
7
9
|
|
@@ -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
|
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"
|
data/qiita-markdown.gemspec
CHANGED
@@ -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
|
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
if ENV["CI"]
|
2
2
|
require "simplecov"
|
3
|
-
|
3
|
+
require "simplecov_json_formatter"
|
4
|
+
SimpleCov.start do
|
5
|
+
SimpleCov.formatters = [
|
6
|
+
SimpleCov::Formatter::JSONFormatter,
|
7
|
+
SimpleCov::Formatter::HTMLFormatter,
|
8
|
+
]
|
9
|
+
|
10
|
+
add_filter "/spec/"
|
11
|
+
end
|
4
12
|
end
|
5
13
|
|
6
14
|
require "qiita-markdown"
|
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryo Nakamura
|
@@ -121,6 +121,20 @@ dependencies:
|
|
121
121
|
- - ">="
|
122
122
|
- !ruby/object:Gem::Version
|
123
123
|
version: '0'
|
124
|
+
- !ruby/object:Gem::Dependency
|
125
|
+
name: uri
|
126
|
+
requirement: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: 1.0.4
|
131
|
+
type: :runtime
|
132
|
+
prerelease: false
|
133
|
+
version_requirements: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: 1.0.4
|
124
138
|
email:
|
125
139
|
- r7kamura@gmail.com
|
126
140
|
executables: []
|
@@ -167,6 +181,7 @@ files:
|
|
167
181
|
- lib/qiita/markdown/filters/html_toc.rb
|
168
182
|
- lib/qiita/markdown/filters/image_link.rb
|
169
183
|
- lib/qiita/markdown/filters/inline_code_color.rb
|
184
|
+
- lib/qiita/markdown/filters/inline_math.rb
|
170
185
|
- lib/qiita/markdown/filters/mention.rb
|
171
186
|
- lib/qiita/markdown/filters/qiita_marker.rb
|
172
187
|
- lib/qiita/markdown/filters/simplify.rb
|
@@ -187,6 +202,7 @@ files:
|
|
187
202
|
- spec/qiita/markdown/filters/heading_anchor_spec.rb
|
188
203
|
- spec/qiita/markdown/filters/html_toc_spec.rb
|
189
204
|
- spec/qiita/markdown/filters/inline_code_color_spec.rb
|
205
|
+
- spec/qiita/markdown/filters/inline_math_spec.rb
|
190
206
|
- spec/qiita/markdown/filters/qiita_marker_spec.rb
|
191
207
|
- spec/qiita/markdown/processor_spec.rb
|
192
208
|
- spec/qiita/markdown/summary_processor_spec.rb
|