qiita-markdown 0.11.5 → 0.12.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/.rubocop.yml +17 -1
- data/.rubocop_todo.yml +86 -40
- data/CHANGELOG.md +3 -0
- data/README.md +11 -8
- data/benchmark/heading_anchor_rendering.rb +1 -1
- data/lib/qiita/markdown.rb +1 -0
- data/lib/qiita/markdown/filters/emoji.rb +33 -0
- data/lib/qiita/markdown/filters/sanitize.rb +1 -1
- data/lib/qiita/markdown/filters/truncate.rb +2 -2
- data/lib/qiita/markdown/greenmat/heading_rendering.rb +1 -1
- data/lib/qiita/markdown/processor.rb +1 -1
- data/lib/qiita/markdown/summary_processor.rb +2 -2
- data/lib/qiita/markdown/version.rb +1 -1
- data/spec/qiita/markdown/processor_spec.rb +28 -1
- metadata +3 -3
- data/benchmark/.rubocop.yml +0 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ff7146b861299953ada5127646c21a9cffb3b2ed
|
|
4
|
+
data.tar.gz: 1efaba3aa4ded077adec7894e0fc6b22c7377c06
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d0d94503283fe41276b338bab864bd0f449adbf1d93417d46ae4187754197e957319bb551e6122a562972545d5313104cb753646239ff2aac9c953f6aae974c0
|
|
7
|
+
data.tar.gz: 4c67bdc61902c94a21ef233d1725e7e14b4cbac14cf8cbdb24f6700ebaf80449228c7215ee8c2375382459f2be1aa3dcccc938cbd4b41a853c7389fc4d51da1a
|
data/.rubocop.yml
CHANGED
|
@@ -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/
|
|
22
|
+
Style/TrailingCommaInArguments:
|
|
23
|
+
EnforcedStyleForMultiline: comma
|
|
24
|
+
|
|
25
|
+
Style/TrailingCommaInLiteral:
|
|
10
26
|
EnforcedStyleForMultiline: comma
|
|
11
27
|
|
|
12
28
|
Style/UnneededPercentQ:
|
data/.rubocop_todo.yml
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
|
-
# This configuration was generated by
|
|
2
|
-
#
|
|
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:
|
|
9
|
+
# Offense count: 4
|
|
9
10
|
Metrics/AbcSize:
|
|
10
11
|
Max: 21
|
|
11
12
|
|
|
12
|
-
# Offense count:
|
|
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:
|
|
17
|
+
Max: 121
|
|
16
18
|
|
|
17
|
-
# Offense count:
|
|
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
|
-
|
|
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
|
-
|
|
37
|
+
Exclude:
|
|
38
|
+
- 'lib/qiita/markdown/filters/syntax_highlight.rb'
|
|
33
39
|
|
|
34
40
|
# Offense count: 1
|
|
35
41
|
Style/ConstantName:
|
|
36
|
-
|
|
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
|
-
|
|
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:
|
|
52
|
+
# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts.
|
|
48
53
|
Style/FileName:
|
|
49
|
-
|
|
54
|
+
Exclude:
|
|
55
|
+
- 'lib/qiita-markdown.rb'
|
|
50
56
|
|
|
51
|
-
# Offense count:
|
|
52
|
-
#
|
|
53
|
-
Style/
|
|
54
|
-
|
|
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:
|
|
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
|
-
|
|
75
|
+
Exclude:
|
|
76
|
+
- 'lib/qiita/markdown/filters/code.rb'
|
|
77
|
+
- 'lib/qiita/markdown/filters/image_link.rb'
|
|
60
78
|
|
|
61
|
-
# Offense count:
|
|
79
|
+
# Offense count: 11
|
|
62
80
|
# Cop supports --auto-correct.
|
|
63
81
|
# Configuration parameters: PreferredDelimiters.
|
|
64
82
|
Style/PercentLiteralDelimiters:
|
|
65
|
-
|
|
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
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
#
|
|
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
|
-
|
|
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:
|
|
78
|
-
#
|
|
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
|
-
|
|
118
|
+
Exclude:
|
|
119
|
+
- 'lib/qiita/markdown/filters/mention.rb'
|
|
81
120
|
|
|
82
|
-
# Offense count:
|
|
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
|
-
|
|
126
|
+
Exclude:
|
|
127
|
+
- 'lib/qiita/markdown/greenmat/heading_rendering.rb'
|
|
128
|
+
- 'spec/qiita/markdown/summary_processor_spec.rb'
|
|
87
129
|
|
|
88
|
-
# Offense count:
|
|
130
|
+
# Offense count: 3
|
|
89
131
|
# Cop supports --auto-correct.
|
|
90
132
|
# Configuration parameters: EnforcedStyleForMultiline, SupportedStyles.
|
|
91
|
-
|
|
92
|
-
|
|
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:
|
|
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
|
data/CHANGELOG.md
CHANGED
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
|
|
51
|
-
:asset_path
|
|
52
|
-
:asset_root
|
|
53
|
-
:base_url
|
|
54
|
-
:default_language
|
|
55
|
-
:
|
|
56
|
-
:
|
|
57
|
-
|
|
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
|
data/lib/qiita/markdown.rb
CHANGED
|
@@ -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
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
|
@@ -7,10 +7,10 @@ module Qiita
|
|
|
7
7
|
DEFAULT_FILTERS = [
|
|
8
8
|
Filters::Greenmat,
|
|
9
9
|
Filters::Simplify,
|
|
10
|
-
|
|
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.
|
|
@@ -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
|
-
|
|
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.
|
|
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-
|
|
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
|
data/benchmark/.rubocop.yml
DELETED