jekyll-mentioji 0.1.0 → 0.2.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 +5 -5
- data/lib/jekyll-mentioji.rb +14 -23
- metadata +20 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5780653cb3ca8ff53c97caf8eb1762091ca4291189e635f385f35aae494cf559
|
4
|
+
data.tar.gz: 221017e768a7e8915fcb5a1f82637aa873374bf2e3a36a2b91ceafcbe05c74ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d74d26dc66052032c755fbfe1063b2f7342058cc90a59af7783cf7cb3c5ce316cf096365838b6a43bf7896754ce8422ce92aed40d1cfcbc70489baa6c6c6687e
|
7
|
+
data.tar.gz: 16d73e11136508ed7fe4a70f1528b1911531c9ee4f32df07bc38da8183fd0a1a97adb6605ab1ba6f7a388975cf4fa15743e955a9d00424f0137ccd36d777837b
|
data/lib/jekyll-mentioji.rb
CHANGED
@@ -5,9 +5,9 @@ require "nokogiri"
|
|
5
5
|
|
6
6
|
module Jekyll
|
7
7
|
class Mentioji
|
8
|
-
MENTIONPATTERNS = %r~(?:^|\B)@((?>[\w][\w-]*))(?!/)(?=\.+[ \t\W]|\.+$|[^\w.]|$)~i
|
8
|
+
MENTIONPATTERNS = %r~(?:^|\B)@((?>[\w][\w-]*))(?!/)(?=\.+[ \t\W]|\.+$|[^\w.]|$)~i.freeze
|
9
9
|
|
10
|
-
OPENING_BODY_TAG_REGEX = %r!<body(.*?)>\s
|
10
|
+
OPENING_BODY_TAG_REGEX = %r!<body(.*?)>\s*!.freeze
|
11
11
|
|
12
12
|
IGNORE_MENTION_PARENTS = %w(pre code a script style).freeze
|
13
13
|
IGNORE_EMOJI_PARENTS = %w(pre code tt).freeze
|
@@ -15,7 +15,8 @@ module Jekyll
|
|
15
15
|
class << self
|
16
16
|
def transform(doc)
|
17
17
|
content = doc.output
|
18
|
-
return unless
|
18
|
+
return unless prelim_check_regex.match?(content)
|
19
|
+
|
19
20
|
setup_transformer(doc.site.config)
|
20
21
|
doc.output = if content.include?("<body")
|
21
22
|
process_html_body(content)
|
@@ -39,11 +40,13 @@ module Jekyll
|
|
39
40
|
end
|
40
41
|
|
41
42
|
def process(body_content)
|
42
|
-
return body_content unless body_content
|
43
|
+
return body_content unless prelim_check_regex.match?(body_content)
|
44
|
+
|
43
45
|
parsed_body = Nokogiri::HTML::DocumentFragment.parse(body_content)
|
44
46
|
parsed_body.search(".//text()").each do |node|
|
45
47
|
content = node.text
|
46
|
-
next
|
48
|
+
next unless prelim_check_regex.match?(content)
|
49
|
+
|
47
50
|
node.replace(
|
48
51
|
mention_renderer(
|
49
52
|
node, emoji_renderer(node, content)
|
@@ -92,7 +95,7 @@ module Jekyll
|
|
92
95
|
|
93
96
|
def default_asset_root
|
94
97
|
if ENV["ASSET_HOST_URL"].to_s.empty?
|
95
|
-
File.join("https://
|
98
|
+
File.join("https://github.githubassets.com", "/images/icons")
|
96
99
|
else
|
97
100
|
File.join(ENV["ASSET_HOST_URL"], "/images/icons")
|
98
101
|
end
|
@@ -108,12 +111,14 @@ module Jekyll
|
|
108
111
|
def mention_renderer(node, text)
|
109
112
|
return text unless text.include?("@")
|
110
113
|
return text if has_ancestor?(node, IGNORE_MENTION_PARENTS)
|
114
|
+
|
111
115
|
text.gsub(MENTIONPATTERNS) { mention_markup(Regexp.last_match(1)) }
|
112
116
|
end
|
113
117
|
|
114
118
|
def emoji_renderer(node, text)
|
115
119
|
return text unless text.include?(":")
|
116
120
|
return text if has_ancestor?(node, IGNORE_EMOJI_PARENTS)
|
121
|
+
|
117
122
|
text.gsub(emoji_pattern) { emoji_markup(Regexp.last_match(1)) }
|
118
123
|
end
|
119
124
|
|
@@ -126,25 +131,11 @@ module Jekyll
|
|
126
131
|
|
127
132
|
def emoji_markup(name)
|
128
133
|
emoji_stash[name] ||= begin
|
129
|
-
|
130
|
-
|
131
|
-
attrs << "#{key}='#{value}'"
|
132
|
-
end
|
133
|
-
"<img #{attrs.join(" ")}>"
|
134
|
+
"<img class='emoji' title=':#{name}:' alt=':#{name}:' " \
|
135
|
+
"src='#{emoji_url(name)}' height='20' width='20'>"
|
134
136
|
end
|
135
137
|
end
|
136
138
|
|
137
|
-
def img_attrs(name)
|
138
|
-
{
|
139
|
-
"class" => "emoji",
|
140
|
-
"title" => ":#{name}:",
|
141
|
-
"alt" => ":#{name}:",
|
142
|
-
"src" => emoji_url(name).to_s,
|
143
|
-
"height" => "20",
|
144
|
-
"width" => "20",
|
145
|
-
}
|
146
|
-
end
|
147
|
-
|
148
139
|
def mention_stash
|
149
140
|
@mention_stash ||= {}
|
150
141
|
end
|
@@ -154,7 +145,7 @@ module Jekyll
|
|
154
145
|
end
|
155
146
|
|
156
147
|
def emoji_names
|
157
|
-
::Emoji.all.flat_map(&:aliases).
|
148
|
+
::Emoji.all.flat_map(&:aliases).map! { |name| Regexp.escape(name) }
|
158
149
|
end
|
159
150
|
|
160
151
|
def emoji_pattern
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-mentioji
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ashwin Maroli
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gemoji
|
@@ -28,14 +28,14 @@ dependencies:
|
|
28
28
|
name: jekyll
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '3.5'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '3.5'
|
41
41
|
- !ruby/object:Gem::Dependency
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0.9'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.0'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: rubocop-jekyll
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -131,7 +145,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
131
145
|
requirements:
|
132
146
|
- - ">="
|
133
147
|
- !ruby/object:Gem::Version
|
134
|
-
version: 2.
|
148
|
+
version: 2.4.0
|
135
149
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
150
|
requirements:
|
137
151
|
- - ">="
|
@@ -139,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
153
|
version: '0'
|
140
154
|
requirements: []
|
141
155
|
rubyforge_project:
|
142
|
-
rubygems_version: 2.
|
156
|
+
rubygems_version: 2.7.9
|
143
157
|
signing_key:
|
144
158
|
specification_version: 4
|
145
159
|
summary: Faster version of the 'Jekyll::Mentions + Jekyll::Emoji' combo
|