qiita-markdown 0.11.5 → 0.12.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: ec6145ad1c4a81c4e3cb46c2d3e6c86e8051ff7b
4
- data.tar.gz: 0ac6fc03d26838c7c80ca7a347c17002b33d634d
3
+ metadata.gz: ff7146b861299953ada5127646c21a9cffb3b2ed
4
+ data.tar.gz: 1efaba3aa4ded077adec7894e0fc6b22c7377c06
5
5
  SHA512:
6
- metadata.gz: f81cedd31daa8953dc2514511660f8f55af54acd1ffefefd306a211d4dc102b260f04c9371de7df1a3c6939281efc9fbadbd78308489474ce770ed54ed2d248d
7
- data.tar.gz: 3a31ff0761eb73c05b9c5be2951265d91790989a9ac3b3033a4321a7cdcf980d0e1df954e65268a1bdcdd4e21bbad8bf61849b082a030787dce31a136f12e0bb
6
+ metadata.gz: d0d94503283fe41276b338bab864bd0f449adbf1d93417d46ae4187754197e957319bb551e6122a562972545d5313104cb753646239ff2aac9c953f6aae974c0
7
+ data.tar.gz: 4c67bdc61902c94a21ef233d1725e7e14b4cbac14cf8cbdb24f6700ebaf80449228c7215ee8c2375382459f2be1aa3dcccc938cbd4b41a853c7389fc4d51da1a
@@ -3,10 +3,26 @@ inherit_from: .rubocop_todo.yml
3
3
  Metrics/ClassLength:
4
4
  Enabled: false
5
5
 
6
+ Style/AsciiComments:
7
+ Exclude:
8
+ - benchmark/**/*
9
+
10
+ Style/Documentation:
11
+ Enabled: false
12
+
13
+ Style/EmptyCaseCondition:
14
+ Enabled: false
15
+
16
+ Style/GuardClause:
17
+ Enabled: false
18
+
6
19
  Style/StringLiterals:
7
20
  EnforcedStyle: double_quotes
8
21
 
9
- Style/TrailingComma:
22
+ Style/TrailingCommaInArguments:
23
+ EnforcedStyleForMultiline: comma
24
+
25
+ Style/TrailingCommaInLiteral:
10
26
  EnforcedStyleForMultiline: comma
11
27
 
12
28
  Style/UnneededPercentQ:
@@ -1,20 +1,22 @@
1
- # This configuration was generated by `rubocop --auto-gen-config`
2
- # on 2015-03-12 12:56:25 +0900 using RuboCop version 0.29.1.
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2016-05-25 17:29:05 +0900 using RuboCop version 0.40.0.
3
4
  # The point is for the user to remove these configuration records
4
5
  # one by one as the offenses are removed from the code base.
5
6
  # Note that changes in the inspected code, or installation of new
6
7
  # versions of RuboCop, may require this file to be generated again.
7
8
 
8
- # Offense count: 1
9
+ # Offense count: 4
9
10
  Metrics/AbcSize:
10
11
  Max: 21
11
12
 
12
- # Offense count: 27
13
- # Configuration parameters: AllowURI, URISchemes.
13
+ # Offense count: 37
14
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
15
+ # URISchemes: http, https
14
16
  Metrics/LineLength:
15
- Max: 122
17
+ Max: 121
16
18
 
17
- # Offense count: 3
19
+ # Offense count: 4
18
20
  # Configuration parameters: CountComments.
19
21
  Metrics/MethodLength:
20
22
  Max: 20
@@ -22,77 +24,121 @@ Metrics/MethodLength:
22
24
  # Offense count: 1
23
25
  # Cop supports --auto-correct.
24
26
  # Configuration parameters: EnforcedStyle, SupportedStyles.
27
+ # SupportedStyles: always, conditionals
25
28
  Style/AndOr:
26
- Enabled: false
29
+ Exclude:
30
+ - 'lib/qiita/markdown/filters/syntax_highlight.rb'
27
31
 
28
32
  # Offense count: 3
29
33
  # Cop supports --auto-correct.
30
34
  # Configuration parameters: EnforcedStyle, SupportedStyles.
35
+ # SupportedStyles: percent_q, bare_percent
31
36
  Style/BarePercentLiterals:
32
- Enabled: false
37
+ Exclude:
38
+ - 'lib/qiita/markdown/filters/syntax_highlight.rb'
33
39
 
34
40
  # Offense count: 1
35
41
  Style/ConstantName:
36
- Enabled: false
37
-
38
- # Offense count: 10
39
- Style/Documentation:
40
- Enabled: false
42
+ Exclude:
43
+ - 'lib/qiita/markdown/filters/mention.rb'
41
44
 
42
45
  # Offense count: 3
43
46
  Style/DoubleNegation:
44
- Enabled: false
47
+ Exclude:
48
+ - 'benchmark/heading_anchor_rendering.rb'
49
+ - 'lib/qiita/markdown/filters/checkbox.rb'
45
50
 
46
51
  # Offense count: 1
47
- # Configuration parameters: Exclude.
52
+ # Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts.
48
53
  Style/FileName:
49
- Enabled: false
54
+ Exclude:
55
+ - 'lib/qiita-markdown.rb'
50
56
 
51
- # Offense count: 1
52
- # Configuration parameters: MinBodyLength.
53
- Style/GuardClause:
54
- Enabled: false
57
+ # Offense count: 11
58
+ # Cop supports --auto-correct.
59
+ Style/MutableConstant:
60
+ Exclude:
61
+ - 'lib/qiita/markdown/filters/checkbox.rb'
62
+ - 'lib/qiita/markdown/filters/code.rb'
63
+ - 'lib/qiita/markdown/filters/sanitize.rb'
64
+ - 'lib/qiita/markdown/filters/simplify.rb'
65
+ - 'lib/qiita/markdown/filters/syntax_highlight.rb'
66
+ - 'lib/qiita/markdown/processor.rb'
67
+ - 'lib/qiita/markdown/summary_processor.rb'
68
+ - 'lib/qiita/markdown/version.rb'
55
69
 
56
- # Offense count: 1
70
+ # Offense count: 2
71
+ # Cop supports --auto-correct.
57
72
  # Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles.
73
+ # SupportedStyles: skip_modifier_ifs, always
58
74
  Style/Next:
59
- Enabled: false
75
+ Exclude:
76
+ - 'lib/qiita/markdown/filters/code.rb'
77
+ - 'lib/qiita/markdown/filters/image_link.rb'
60
78
 
61
- # Offense count: 9
79
+ # Offense count: 11
62
80
  # Cop supports --auto-correct.
63
81
  # Configuration parameters: PreferredDelimiters.
64
82
  Style/PercentLiteralDelimiters:
65
- Enabled: false
83
+ Exclude:
84
+ - 'benchmark/heading_anchor_rendering.rb'
85
+ - 'lib/qiita/markdown/filters/mention.rb'
86
+ - 'lib/qiita/markdown/filters/sanitize.rb'
87
+ - 'lib/qiita/markdown/filters/syntax_highlight.rb'
88
+ - 'spec/qiita/markdown/processor_spec.rb'
89
+ - 'spec/qiita/markdown/summary_processor_spec.rb'
66
90
 
67
91
  # Offense count: 1
68
92
  # Cop supports --auto-correct.
69
93
  Style/PerlBackrefs:
70
- Enabled: false
71
-
72
- # Offense count: 10
73
- # Configuration parameters: NamePrefix, NamePrefixBlacklist.
94
+ Exclude:
95
+ - 'lib/qiita/markdown/filters/mention.rb'
96
+
97
+ # Offense count: 13
98
+ # Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist.
99
+ # NamePrefix: is_, has_, have_
100
+ # NamePrefixBlacklist: is_, has_, have_
101
+ # NameWhitelist: is_a?
74
102
  Style/PredicateName:
75
- Enabled: false
103
+ Exclude:
104
+ - 'spec/**/*'
105
+ - 'benchmark/heading_anchor_rendering.rb'
106
+ - 'lib/qiita/markdown/filters/checkbox.rb'
107
+ - 'lib/qiita/markdown/filters/code.rb'
108
+ - 'lib/qiita/markdown/filters/mention.rb'
109
+ - 'lib/qiita/markdown/filters/sanitize.rb'
110
+ - 'lib/qiita/markdown/filters/syntax_highlight.rb'
111
+ - 'lib/qiita/markdown/greenmat/heading_rendering.rb'
76
112
 
77
- # Offense count: 2
78
- # Configuration parameters: MaxSlashes.
113
+ # Offense count: 1
114
+ # Cop supports --auto-correct.
115
+ # Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes.
116
+ # SupportedStyles: slashes, percent_r, mixed
79
117
  Style/RegexpLiteral:
80
- Enabled: false
118
+ Exclude:
119
+ - 'lib/qiita/markdown/filters/mention.rb'
81
120
 
82
- # Offense count: 2
121
+ # Offense count: 3
83
122
  # Cop supports --auto-correct.
84
123
  # Configuration parameters: EnforcedStyle, SupportedStyles.
124
+ # SupportedStyles: only_raise, only_fail, semantic
85
125
  Style/SignalException:
86
- Enabled: false
126
+ Exclude:
127
+ - 'lib/qiita/markdown/greenmat/heading_rendering.rb'
128
+ - 'spec/qiita/markdown/summary_processor_spec.rb'
87
129
 
88
- # Offense count: 2
130
+ # Offense count: 3
89
131
  # Cop supports --auto-correct.
90
132
  # Configuration parameters: EnforcedStyleForMultiline, SupportedStyles.
91
- Style/TrailingComma:
92
- Enabled: false
133
+ # SupportedStyles: comma, consistent_comma, no_comma
134
+ Style/TrailingCommaInArguments:
135
+ Exclude:
136
+ - 'lib/qiita/markdown/filters/mention.rb'
137
+ - 'spec/qiita/markdown/processor_spec.rb'
93
138
 
94
- # Offense count: 6
139
+ # Offense count: 9
95
140
  # Cop supports --auto-correct.
96
- # Configuration parameters: WordRegex.
141
+ # Configuration parameters: EnforcedStyle, SupportedStyles, MinSize, WordRegex.
142
+ # SupportedStyles: percent, brackets
97
143
  Style/WordArray:
98
144
  Enabled: false
@@ -1,3 +1,6 @@
1
+ ## 0.12.0
2
+ - Add custom emoji support via `:emoji_names` and `:emoji_url_generator` contexts
3
+
1
4
  ## 0.11.5
2
5
  - Add a leading newline to `<pre>` elements so that leading newlines inputted by user are properly rendered on browsers
3
6
 
data/README.md CHANGED
@@ -47,14 +47,17 @@ processor.call(text)
47
47
  `.new` and `#call` can take optional context as a Hash with following keys:
48
48
 
49
49
  ```
50
- :allowed_usernames - A list of usernames allowed to be username. (Array<String>)
51
- :asset_path - URL path to link to emoji sprite. (String)
52
- :asset_root - Base URL to link to emoji sprite. (String)
53
- :base_url - Used to construct links to user profile pages for each. (String)
54
- :default_language - Default language used if no language detected from code. (String)
55
- :language_aliases - Alias table for some language names. (Hash)
56
- :rule - Sanitization rule table. (Hash)
57
- :script - A flag to allow to embed script element. (Boolean)
50
+ :allowed_usernames - A list of usernames allowed to be username. (Array<String>)
51
+ :asset_path - URL path to link to emoji sprite. (String)
52
+ :asset_root - Base URL to link to emoji sprite. (String)
53
+ :base_url - Used to construct links to user profile pages for each. (String)
54
+ :default_language - Default language used if no language detected from code. (String)
55
+ :emoji_names - A list of allowed emoji names. (Array<String>)
56
+ :emoji_url_generator - #call'able object that accepts emoji name as argument and returns emoji image URL. (#call)
57
+ The original implementation is used when the generator returned a falsey value.
58
+ :language_aliases - Alias table for some language names. (Hash)
59
+ :rule - Sanitization rule table. (Hash)
60
+ :script - A flag to allow to embed script element. (Boolean)
58
61
  ```
59
62
 
60
63
  ```ruby
@@ -171,7 +171,7 @@ module Rendering
171
171
  # no-op
172
172
  end
173
173
 
174
- private
174
+ private # rubocop:disable Lint/UselessAccessModifier
175
175
 
176
176
  def content
177
177
  body
@@ -9,6 +9,7 @@ require "sanitize"
9
9
 
10
10
  require "qiita/markdown/filters/checkbox"
11
11
  require "qiita/markdown/filters/code"
12
+ require "qiita/markdown/filters/emoji"
12
13
  require "qiita/markdown/filters/footnote"
13
14
  require "qiita/markdown/filters/greenmat"
14
15
  require "qiita/markdown/filters/image_link"
@@ -0,0 +1,33 @@
1
+ module Qiita
2
+ module Markdown
3
+ module Filters
4
+ class Emoji < HTML::Pipeline::EmojiFilter
5
+ # @note Override
6
+ def validate
7
+ needs :asset_root unless emoji_url_generator
8
+ end
9
+
10
+ private
11
+
12
+ # @note Override
13
+ def emoji_url(name)
14
+ url = emoji_url_generator.call(name) if emoji_url_generator
15
+ url || super
16
+ end
17
+
18
+ def emoji_url_generator
19
+ context[:emoji_url_generator]
20
+ end
21
+
22
+ # @note Override
23
+ def emoji_pattern
24
+ @emoji_pattern ||= /:(#{Regexp.union(emoji_names).source}):/
25
+ end
26
+
27
+ def emoji_names
28
+ context[:emoji_names] || self.class.emoji_names
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -74,7 +74,7 @@ module Qiita
74
74
  "script" => [
75
75
  "async",
76
76
  "src",
77
- "type"
77
+ "type",
78
78
  ],
79
79
  "td" => [
80
80
  "style",
@@ -11,7 +11,7 @@ module Qiita
11
11
  class Truncate < HTML::Pipeline::Filter
12
12
  DEFAULT_OPTIONS = {
13
13
  length: 100,
14
- omission: "…".freeze
14
+ omission: "…".freeze,
15
15
  }.freeze
16
16
 
17
17
  def call
@@ -36,7 +36,7 @@ module Qiita
36
36
  # since it traverses the node's descendants _before_ the node itself.
37
37
  # https://github.com/sparklemotion/nokogiri/blob/v1.6.6.2/lib/nokogiri/xml/node.rb#L571-L574
38
38
  def traverse(node, &block)
39
- block.call(node)
39
+ yield(node)
40
40
 
41
41
  node.children.each do |child_node|
42
42
  traverse(child_node, &block)
@@ -8,7 +8,7 @@ module Qiita
8
8
 
9
9
  class AbstractHeading
10
10
  attr_reader :raw_body, :level, :counter, :escape_html
11
- alias_method :escape_html?, :escape_html
11
+ alias escape_html? escape_html
12
12
 
13
13
  def initialize(raw_body, level, counter, escape_html = false)
14
14
  @raw_body = raw_body
@@ -11,7 +11,7 @@ module Qiita
11
11
  Filters::Footnote,
12
12
  Filters::Code,
13
13
  Filters::Checkbox,
14
- HTML::Pipeline::EmojiFilter,
14
+ Filters::Emoji,
15
15
  Filters::SyntaxHighlight,
16
16
  Filters::Mention,
17
17
  Filters::Sanitize,
@@ -7,10 +7,10 @@ module Qiita
7
7
  DEFAULT_FILTERS = [
8
8
  Filters::Greenmat,
9
9
  Filters::Simplify,
10
- HTML::Pipeline::EmojiFilter,
10
+ Filters::Emoji,
11
11
  Filters::Mention,
12
12
  Filters::Sanitize,
13
- Filters::Truncate
13
+ Filters::Truncate,
14
14
  ]
15
15
 
16
16
  # @note Modify filters if you want.
@@ -1,5 +1,5 @@
1
1
  module Qiita
2
2
  module Markdown
3
- VERSION = "0.11.5"
3
+ VERSION = "0.12.0"
4
4
  end
5
5
  end
@@ -537,7 +537,7 @@ describe Qiita::Markdown::Processor do
537
537
 
538
538
  it "wraps it in a element" do
539
539
  should eq '<p><a href="http://example.com/b.png" target="_blank">' +
540
- %(<img src="http://example.com/b.png" alt="a"></a></p>\n)
540
+ %(<img src="http://example.com/b.png" alt="a"></a></p>\n)
541
541
  end
542
542
  end
543
543
 
@@ -786,5 +786,32 @@ describe Qiita::Markdown::Processor do
786
786
  EOS
787
787
  end
788
788
  end
789
+
790
+ context "with emoji_names and emoji_url_generator context" do
791
+ before do
792
+ context[:emoji_names] = %w(foo o)
793
+
794
+ context[:emoji_url_generator] = proc do |emoji_name|
795
+ "https://example.com/foo.png" if emoji_name == "foo"
796
+ end
797
+ end
798
+
799
+ let(:markdown) do
800
+ <<-EOS.strip_heredoc
801
+ :foo: :o: :x:
802
+ EOS
803
+ end
804
+
805
+ it "replaces only the specified emoji names with img elements with custom URL" do
806
+ should include(
807
+ '<img class="emoji" title=":foo:" alt=":foo:" src="https://example.com/foo.png"',
808
+ '<img class="emoji" title=":o:" alt=":o:" src="/images/emoji/unicode/2b55.png"'
809
+ )
810
+
811
+ should_not include(
812
+ '<img class="emoji" title=":x:" alt=":x:"'
813
+ )
814
+ end
815
+ end
789
816
  end
790
817
  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.11.5
4
+ version: 0.12.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: 2016-01-14 00:00:00.000000000 Z
11
+ date: 2016-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gemoji
@@ -243,13 +243,13 @@ files:
243
243
  - LICENSE.txt
244
244
  - README.md
245
245
  - Rakefile
246
- - benchmark/.rubocop.yml
247
246
  - benchmark/heading_anchor_rendering.rb
248
247
  - benchmark/sample.md
249
248
  - lib/qiita-markdown.rb
250
249
  - lib/qiita/markdown.rb
251
250
  - lib/qiita/markdown/filters/checkbox.rb
252
251
  - lib/qiita/markdown/filters/code.rb
252
+ - lib/qiita/markdown/filters/emoji.rb
253
253
  - lib/qiita/markdown/filters/footnote.rb
254
254
  - lib/qiita/markdown/filters/greenmat.rb
255
255
  - lib/qiita/markdown/filters/image_link.rb
@@ -1,4 +0,0 @@
1
- inherit_from: ../.rubocop.yml
2
-
3
- Style/AsciiComments:
4
- Enabled: false