qiita-markdown 0.17.0 → 0.18.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of qiita-markdown might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fbb2dac9b43b2643084e6d84a2d551f820e27a89
4
- data.tar.gz: dd080b685abeea4511ec66d89d7455f7b9465492
3
+ metadata.gz: 142f1f300d42442f62e84b3ffe54321caa229b2b
4
+ data.tar.gz: 8029e1417074df1acc82af5cfd075efebe87c959
5
5
  SHA512:
6
- metadata.gz: 2326ffc02dafe386118f18416e1c0159a002714cb3a860547c74de0ee4e45983e90c1ef33903260215380a66f1d99ce8334dc893da99138e7f697c37f464af82
7
- data.tar.gz: '01952a9b9e370f624b7b5b3806903cdb5d21b18eef87092cf585e88c64e6e526b41d3e1dc18e8336e082e27891c6b93067b4be653f9cb84c9727a3f5153b2242'
6
+ metadata.gz: db7ea2bc3c6e992848e569c695dddb5923d8aeba7f289eb845c6feea58b7150152317df655540350db6967d0871b93ebaa6e7fc82c475742b6ad95f98c779cb1
7
+ data.tar.gz: c98d93c9fd42393475a09560131d125eafe6d5f43ac429b333a2b2dfecfacf4c9fb8035c5a1cc3234c1209417591ba86aaac409501750a5c1b1c013198904b23
data/.rubocop.yml CHANGED
@@ -34,3 +34,8 @@ Style/UnneededPercentQ:
34
34
 
35
35
  Metrics/LineLength:
36
36
  Enabled: false
37
+
38
+ Metrics/BlockLength:
39
+ Exclude:
40
+ - qiita-markdown.gemspec
41
+ - spec/**/*
data/.travis.yml CHANGED
@@ -7,10 +7,11 @@ before_install:
7
7
  - gem update bundler
8
8
  language: ruby
9
9
  rvm:
10
- - 2.0.0
10
+ - 2.0
11
11
  - 2.1
12
12
  - 2.2
13
- - 2.3.0
13
+ - 2.3
14
+ - 2.4
14
15
  env:
15
16
  global:
16
17
  secure: n8eyxYYfxLApgR4YGKqbrOgGlraIyLyoql4K4DvLZV4kqfGf9LLsPdP7Shudqrv5k2h8xIwnJVnwcPZx9YCu5WWYrJd7vmivpU2j52LwFPYRM+GFNcu7TXmzcNSPG8agnc5We9amF5zJY6XSTpzWpxyqfIwEZM75iR6XXuHuLFk=
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## Unreleased
2
+
3
+ ## 0.18.0
4
+
5
+ - Extract heading decoration logic from Greenmat renderer to `Toc` filter
6
+ - Use greenmat 3.2.2.3
7
+
1
8
  ## 0.17.0
2
9
 
3
10
  - Require pygments.rb 1.0 or later
data/Rakefile CHANGED
@@ -4,4 +4,4 @@ require "rubocop/rake_task"
4
4
 
5
5
  RSpec::Core::RakeTask.new(:spec)
6
6
  RuboCop::RakeTask.new(:style)
7
- task default: [:spec, :style]
7
+ task default: %i[spec style]
@@ -171,7 +171,7 @@ module Rendering
171
171
  # no-op
172
172
  end
173
173
 
174
- private # rubocop:disable Lint/UselessAccessModifier
174
+ private
175
175
 
176
176
  def content
177
177
  body
@@ -19,6 +19,7 @@ require "qiita/markdown/filters/mention"
19
19
  require "qiita/markdown/filters/sanitize"
20
20
  require "qiita/markdown/filters/simplify"
21
21
  require "qiita/markdown/filters/syntax_highlight"
22
+ require "qiita/markdown/filters/toc"
22
23
  require "qiita/markdown/filters/truncate"
23
24
  require "qiita/markdown/greenmat/heading_rendering"
24
25
  require "qiita/markdown/greenmat/html_renderer"
@@ -17,9 +17,9 @@ module Qiita
17
17
  result[:codes] ||= []
18
18
  doc.search("pre").each do |pre|
19
19
  if (code = pre.at("code"))
20
- label = Label.new(code["class"])
21
- filename = label.filename
22
- language = label.language
20
+ metadata = Metadata.new(code["data-metadata"])
21
+ filename = metadata.filename
22
+ language = metadata.language
23
23
  language = language_aliases[language] || language
24
24
  pre["filename"] = filename if filename
25
25
  pre["lang"] = language if language
@@ -39,8 +39,8 @@ module Qiita
39
39
  context[:language_aliases] || DEFAULT_LANGUAGE_ALIASES
40
40
  end
41
41
 
42
- # Detects language from code block label.
43
- class Label
42
+ # Detects language from code block metadata.
43
+ class Metadata
44
44
  # @param text [String, nil]
45
45
  def initialize(text)
46
46
  @text = text
@@ -59,10 +59,10 @@ module Qiita
59
59
  end
60
60
 
61
61
  # @example
62
- # Label.new(nil).language #=> nil
63
- # Label.new("ruby").language #=> "ruby"
64
- # Label.new("ruby:foo.rb").language #=> "ruby"
65
- # Label.new("foo.rb").language #=> "ruby"
62
+ # Metadata.new(nil).language #=> nil
63
+ # Metadata.new("ruby").language #=> "ruby"
64
+ # Metadata.new("ruby:foo.rb").language #=> "ruby"
65
+ # Metadata.new("foo.rb").language #=> "ruby"
66
66
  # @return [String, nil]
67
67
  def language
68
68
  case
@@ -32,13 +32,13 @@ module Qiita
32
32
  )
33
33
  }x
34
34
 
35
- IGNORED_ANCESTOR_ELEMENT_NAMES = %w(
35
+ IGNORED_ANCESTOR_ELEMENT_NAMES = %w[
36
36
  a
37
37
  blockquote
38
38
  code
39
39
  pre
40
40
  style
41
- ).freeze
41
+ ].freeze
42
42
 
43
43
  # @param node [Nokogiri::XML::Node]
44
44
  # @param group_mention_url_generator [Proc]
@@ -23,13 +23,13 @@ module Qiita
23
23
  private
24
24
 
25
25
  def has_invalid_list_node?
26
- name == "li" && !node.ancestors.any? do |ancestor|
26
+ name == "li" && node.ancestors.none? do |ancestor|
27
27
  %w[ol ul].include?(ancestor.name)
28
28
  end
29
29
  end
30
30
 
31
31
  def has_invalid_table_node?
32
- %w[thead tbody tfoot tr td th].include?(name) && !node.ancestors.any? do |ancestor|
32
+ %w[thead tbody tfoot tr td th].include?(name) && node.ancestors.none? do |ancestor|
33
33
  ancestor.name == "table"
34
34
  end
35
35
  end
@@ -213,7 +213,7 @@ module Qiita
213
213
  "script",
214
214
  ],
215
215
  transformers: TransformableNode,
216
- }
216
+ }.freeze
217
217
 
218
218
  SCRIPTABLE_RULE = RULE.dup.tap do |rule|
219
219
  rule[:attributes] = RULE[:attributes].dup
@@ -15,9 +15,9 @@ module Qiita
15
15
  # `Sanitize` filter later.
16
16
  # https://github.com/rgrove/sanitize/blob/v3.1.2/lib/sanitize.rb#L77-L100
17
17
  class Simplify < HTML::Pipeline::Filter
18
- SIMPLE_ELEMENTS = %w(a b code em i ins q s samp span strike strong sub sup var)
18
+ SIMPLE_ELEMENTS = %w[a b code em i ins q s samp span strike strong sub sup var]
19
19
 
20
- COMPLEX_CONTENT_ELEMENTS = %w(table)
20
+ COMPLEX_CONTENT_ELEMENTS = %w[table]
21
21
 
22
22
  def call
23
23
  remove_complex_contents
@@ -0,0 +1,39 @@
1
+ module Qiita
2
+ module Markdown
3
+ module Filters
4
+ class Toc < HTML::Pipeline::Filter
5
+ def call
6
+ doc.css("h1[id], h2[id], h3[id], h4[id], h5[id], h6[id]").each do |node|
7
+ Heading.new(node).decorate
8
+ end
9
+ doc
10
+ end
11
+
12
+ class Heading
13
+ def initialize(node)
14
+ @node = node
15
+ @id = node.attr("id")
16
+ raise unless @id
17
+ end
18
+
19
+ def decorate
20
+ remove_heading_id
21
+ first_child.add_previous_sibling(anchor_element) if first_child
22
+ end
23
+
24
+ def remove_heading_id
25
+ @node.remove_attribute("id")
26
+ end
27
+
28
+ def anchor_element
29
+ %(<span id="#{@id}" class="fragment"></span><a href="##{@id}"><i class="fa fa-link"></i></a>)
30
+ end
31
+
32
+ def first_child
33
+ @first_child ||= @node.children.first
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -47,18 +47,12 @@ module Qiita
47
47
 
48
48
  class HeadingWithAnchor < AbstractHeading
49
49
  def to_s
50
- "\n<h#{level}>#{anchor_element}#{body}</h#{level}>\n"
50
+ %(\n<h#{level} id="#{suffixed_id}">#{body}</h#{level}>\n)
51
51
  end
52
52
 
53
53
  def increment
54
54
  counter[id] += 1
55
55
  end
56
-
57
- private
58
-
59
- def anchor_element
60
- %(<span id="#{suffixed_id}" class="fragment"></span><a href="##{suffixed_id}"><i class="fa fa-link"></i></a>)
61
- end
62
56
  end
63
57
  end
64
58
  end
@@ -14,6 +14,7 @@ module Qiita
14
14
  Filters::Footnote,
15
15
  Filters::Code,
16
16
  Filters::Checkbox,
17
+ Filters::Toc,
17
18
  Filters::Emoji,
18
19
  Filters::SyntaxHighlight,
19
20
  Filters::Mention,
@@ -1,5 +1,5 @@
1
1
  module Qiita
2
2
  module Markdown
3
- VERSION = "0.17.0"
3
+ VERSION = "0.18.0"
4
4
  end
5
5
  end
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.add_dependency "html-pipeline", "~> 2.0"
24
24
  spec.add_dependency "mem"
25
25
  spec.add_dependency "pygments.rb", "~> 1.0"
26
- spec.add_dependency "greenmat", ">= 3.2.0.2", "< 4"
26
+ spec.add_dependency "greenmat", "3.2.2.3"
27
27
  spec.add_dependency "sanitize"
28
28
  spec.add_dependency "addressable"
29
29
  spec.add_development_dependency "activesupport", "4.2.6"
@@ -33,5 +33,5 @@ Gem::Specification.new do |spec|
33
33
  spec.add_development_dependency "pry"
34
34
  spec.add_development_dependency "rake", "~> 10.0"
35
35
  spec.add_development_dependency "rspec", "~> 3.1"
36
- spec.add_development_dependency "rubocop", "0.40.0"
36
+ spec.add_development_dependency "rubocop", "0.49.1"
37
37
  end
@@ -0,0 +1,15 @@
1
+ describe Qiita::Markdown::Filters::Greenmat do
2
+ subject(:filter) do
3
+ described_class.new(markdown)
4
+ end
5
+
6
+ context "with headings" do
7
+ let(:markdown) do
8
+ "# foo"
9
+ end
10
+
11
+ it "does not generate FontAwesome classes so that we can say that they're inputted by user" do
12
+ expect(filter.call.to_s).to eq(%(\n<h1 id="foo">foo</h1>\n))
13
+ end
14
+ end
15
+ end
@@ -84,6 +84,37 @@ describe Qiita::Markdown::Processor do
84
84
  end
85
85
  end
86
86
 
87
+ context "with heading whose title includes special HTML characters" do
88
+ let(:markdown) do
89
+ <<-EOS.strip_heredoc
90
+ # <b>R&amp;B</b>
91
+ EOS
92
+ end
93
+
94
+ it "generates fragment identifier by sanitizing the special characters in the title" do
95
+ should eq <<-EOS.strip_heredoc
96
+
97
+ <h1>
98
+ <span id="rb" class="fragment"></span><a href="#rb"><i class="fa fa-link"></i></a><b>R&amp;B</b>
99
+ </h1>
100
+ EOS
101
+ end
102
+ end
103
+
104
+ context "with manually inputted heading HTML tags without id attribute" do
105
+ let(:markdown) do
106
+ <<-EOS.strip_heredoc
107
+ <h1>foo</h1>
108
+ EOS
109
+ end
110
+
111
+ it "does nothing" do
112
+ should eq <<-EOS.strip_heredoc
113
+ <h1>foo</h1>
114
+ EOS
115
+ end
116
+ end
117
+
87
118
  context "with code" do
88
119
  let(:markdown) do
89
120
  <<-EOS.strip_heredoc
@@ -55,7 +55,7 @@ describe Qiita::Markdown::SummaryProcessor do
55
55
 
56
56
  it "returns simple code element" do
57
57
  should eq <<-EOS.strip_heredoc
58
- <code class="ruby">puts 'hello world'
58
+ <code>puts 'hello world'
59
59
  </code>
60
60
  EOS
61
61
  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: 0.17.0
4
+ version: 0.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-30 00:00:00.000000000 Z
11
+ date: 2017-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gemoji
@@ -84,22 +84,16 @@ dependencies:
84
84
  name: greenmat
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: 3.2.0.2
90
- - - "<"
87
+ - - '='
91
88
  - !ruby/object:Gem::Version
92
- version: '4'
89
+ version: 3.2.2.3
93
90
  type: :runtime
94
91
  prerelease: false
95
92
  version_requirements: !ruby/object:Gem::Requirement
96
93
  requirements:
97
- - - ">="
98
- - !ruby/object:Gem::Version
99
- version: 3.2.0.2
100
- - - "<"
94
+ - - '='
101
95
  - !ruby/object:Gem::Version
102
- version: '4'
96
+ version: 3.2.2.3
103
97
  - !ruby/object:Gem::Dependency
104
98
  name: sanitize
105
99
  requirement: !ruby/object:Gem::Requirement
@@ -232,14 +226,14 @@ dependencies:
232
226
  requirements:
233
227
  - - '='
234
228
  - !ruby/object:Gem::Version
235
- version: 0.40.0
229
+ version: 0.49.1
236
230
  type: :development
237
231
  prerelease: false
238
232
  version_requirements: !ruby/object:Gem::Requirement
239
233
  requirements:
240
234
  - - '='
241
235
  - !ruby/object:Gem::Version
242
- version: 0.40.0
236
+ version: 0.49.1
243
237
  description:
244
238
  email:
245
239
  - r7kamura@gmail.com
@@ -274,6 +268,7 @@ files:
274
268
  - lib/qiita/markdown/filters/sanitize.rb
275
269
  - lib/qiita/markdown/filters/simplify.rb
276
270
  - lib/qiita/markdown/filters/syntax_highlight.rb
271
+ - lib/qiita/markdown/filters/toc.rb
277
272
  - lib/qiita/markdown/filters/truncate.rb
278
273
  - lib/qiita/markdown/greenmat/heading_rendering.rb
279
274
  - lib/qiita/markdown/greenmat/html_renderer.rb
@@ -282,7 +277,7 @@ files:
282
277
  - lib/qiita/markdown/summary_processor.rb
283
278
  - lib/qiita/markdown/version.rb
284
279
  - qiita-markdown.gemspec
285
- - spec/qiita/markdown/greenmat/html_renderer_spec.rb
280
+ - spec/qiita/markdown/filters/greenmat_spec.rb
286
281
  - spec/qiita/markdown/greenmat/html_toc_renderer_spec.rb
287
282
  - spec/qiita/markdown/processor_spec.rb
288
283
  - spec/qiita/markdown/summary_processor_spec.rb
@@ -312,7 +307,7 @@ signing_key:
312
307
  specification_version: 4
313
308
  summary: Qiita-specified markdown processor.
314
309
  test_files:
315
- - spec/qiita/markdown/greenmat/html_renderer_spec.rb
310
+ - spec/qiita/markdown/filters/greenmat_spec.rb
316
311
  - spec/qiita/markdown/greenmat/html_toc_renderer_spec.rb
317
312
  - spec/qiita/markdown/processor_spec.rb
318
313
  - spec/qiita/markdown/summary_processor_spec.rb
@@ -1,68 +0,0 @@
1
- require "active_support/core_ext/string/strip"
2
-
3
- describe Qiita::Markdown::Greenmat::HTMLRenderer do
4
- let(:renderer) { described_class.new(extension) }
5
- let(:extension) { {} }
6
- let(:greenmat) { ::Greenmat::Markdown.new(renderer) }
7
- subject(:rendered_html) { greenmat.render(markdown) }
8
-
9
- describe "headings" do
10
- let(:markdown) do
11
- <<-EOS.strip_heredoc
12
- # a
13
- ## a
14
- ### a
15
- ### a
16
- EOS
17
- end
18
-
19
- context "with :with_toc_data extension" do
20
- let(:extension) { { with_toc_data: true } }
21
-
22
- it "renders headings with ToC anchor" do
23
- should eq <<-EOS.strip_heredoc
24
-
25
- <h1><span id="a" class="fragment"></span><a href="#a"><i class="fa fa-link"></i></a>a</h1>
26
-
27
- <h2><span id="a-1" class="fragment"></span><a href="#a-1"><i class="fa fa-link"></i></a>a</h2>
28
-
29
- <h3><span id="a-2" class="fragment"></span><a href="#a-2"><i class="fa fa-link"></i></a>a</h3>
30
-
31
- <h3><span id="a-3" class="fragment"></span><a href="#a-3"><i class="fa fa-link"></i></a>a</h3>
32
- EOS
33
- end
34
-
35
- context "and heading title including special HTML characters" do
36
- let(:markdown) do
37
- <<-EOS.strip_heredoc
38
- # <b>R&amp;B</b>
39
- EOS
40
- end
41
-
42
- it "generates fragment identifier by sanitizing the characters in the title" do
43
- should eq <<-EOS.strip_heredoc
44
-
45
- <h1><span id="rb" class="fragment"></span><a href="#rb"><i class="fa fa-link"></i></a><b>R&amp;B</b></h1>
46
- EOS
47
- end
48
- end
49
- end
50
-
51
- context "without :with_toc_data extension" do
52
- let(:extension) { { with_toc_data: false } }
53
-
54
- it "renders headings without ToC anchor" do
55
- should eq <<-EOS.strip_heredoc
56
-
57
- <h1>a</h1>
58
-
59
- <h2>a</h2>
60
-
61
- <h3>a</h3>
62
-
63
- <h3>a</h3>
64
- EOS
65
- end
66
- end
67
- end
68
- end