html-pipeline-mrkdwn 0.1.9 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9547e478a23018b8b15dce6d5c1546172c1fc1c69dd42935e40c32d528c5cf4a
|
4
|
+
data.tar.gz: 4e8d92217071e0c78c2426ca887f7f6522e4c25f72afeb0c5689fbc340f28ae8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 286afc3419b578befe9da101d992acc0f63b32b3e7169f7a3ba687a6a28cba4e39adf7650e692c696238f95d457d36e7a20f224a4dfcd69066fcd9b355b00574
|
7
|
+
data.tar.gz: bcd82b1de9518d162aa088ecbf8f89266d2ef3124ebe98d14a8de4c85a759549ca2fc864f6df11c2c4675d9123afa9e0cd26dd2c1b7cafe68a595ece70e535c1
|
@@ -12,6 +12,8 @@ module HTML
|
|
12
12
|
# :slack_channels - a hash of Slack channel ids and channel names
|
13
13
|
# :slack_users - a hash of Slack user or bot ids and display names
|
14
14
|
class Mrkdwn < Filter
|
15
|
+
attr_reader :large_emoji
|
16
|
+
|
15
17
|
MULTILINE_CODE_PATTERN = /```(.+?)```/m.freeze
|
16
18
|
|
17
19
|
CODE_PATTERN = /`(?=\S)(.+?)(?<=\S)`/.freeze
|
@@ -33,7 +35,11 @@ module HTML
|
|
33
35
|
|
34
36
|
LINE_BREAK_PATTERN = /\n/.freeze
|
35
37
|
|
36
|
-
EMOJI_PATTERN = /:([\w+-]
|
38
|
+
EMOJI_PATTERN = /:([\w+-_]+?):/.freeze
|
39
|
+
|
40
|
+
EMOJI_AND_WHITESPACE_PATTERN = /(?::[\w+-_]+?:|\s)+/.freeze
|
41
|
+
|
42
|
+
NON_CAPTURING_EMOJI_PATTERN = /:[\w+-_]+?:/.freeze
|
37
43
|
|
38
44
|
STYLE_PATTERN = /
|
39
45
|
([`*_~])
|
@@ -55,18 +61,25 @@ module HTML
|
|
55
61
|
}.freeze
|
56
62
|
|
57
63
|
def initialize(doc, context = nil, result = nil)
|
58
|
-
super
|
64
|
+
super
|
59
65
|
|
60
|
-
|
61
|
-
@slack_channels = {}
|
62
|
-
@slack_users = {}
|
66
|
+
default_emoji_image_tag = ->(emoji) { "<img src=\"#{emoji.image_filename}\" alt=\"#{emoji.name}\" class=\"emoji\">" }
|
63
67
|
|
64
|
-
@emoji_image_tag = @context[:emoji_image_tag]
|
65
|
-
@
|
66
|
-
@
|
68
|
+
@emoji_image_tag = @context[:emoji_image_tag] || default_emoji_image_tag
|
69
|
+
@large_emoji_image_tag = @context[:large_emoji_image_tag] || @emoji_image_tag
|
70
|
+
@large_emoji_class = @context[:large_emoji_class] || "emoji-lg"
|
71
|
+
@slack_channels = @context[:slack_channels] || {}
|
72
|
+
@slack_users = @context[:slack_users] || {}
|
67
73
|
end
|
68
74
|
|
69
75
|
def call
|
76
|
+
div = doc.at_css("div")
|
77
|
+
|
78
|
+
if wants_large_emoji?(div.content)
|
79
|
+
@large_emoji = true
|
80
|
+
div.add_class(@large_emoji_class)
|
81
|
+
end
|
82
|
+
|
70
83
|
ELEMENTS.each do |element, includes|
|
71
84
|
process_text_nodes(includes) { |content| call_filter(element, content) }
|
72
85
|
end
|
@@ -80,6 +93,11 @@ module HTML
|
|
80
93
|
"context[:emoji_image_tag] should return a Proc that takes an Emoji object as in the 'gemoji' gem."
|
81
94
|
end
|
82
95
|
|
96
|
+
if context[:large_emoji_image_tag] && !context[:large_emoji_image_tag].is_a?(Proc)
|
97
|
+
raise ArgumentError,
|
98
|
+
"context[:large_emoji_image_tag] should return a Proc that takes an Emoji object as in the 'gemoji' gem."
|
99
|
+
end
|
100
|
+
|
83
101
|
if context[:slack_channels] && !context[:slack_channels].is_a?(Hash)
|
84
102
|
raise ArgumentError,
|
85
103
|
"context[:slack_channels] should return a Hash whose keys are Slack channel ids and values are their names."
|
@@ -107,7 +125,7 @@ module HTML
|
|
107
125
|
end
|
108
126
|
|
109
127
|
def call_filter(filter_name, content)
|
110
|
-
method = "#{filter_name}_filter"
|
128
|
+
method = :"#{filter_name}_filter"
|
111
129
|
send method, content
|
112
130
|
end
|
113
131
|
|
@@ -147,10 +165,10 @@ module HTML
|
|
147
165
|
(text, klass, prefix) =
|
148
166
|
case mention
|
149
167
|
when /\A#(C.+)\Z/ # slack channels
|
150
|
-
[@slack_channels
|
168
|
+
[@slack_channels[Regexp.last_match[1]] || Regexp.last_match[1], "channel", "#"]
|
151
169
|
|
152
170
|
when /\A@([UB].+)\Z/ # slack users or bots
|
153
|
-
[@slack_users
|
171
|
+
[@slack_users[Regexp.last_match[1]] || Regexp.last_match[1], "user", "@"]
|
154
172
|
|
155
173
|
when /\A!(here|channel|everyone)\Z/ # special mentions
|
156
174
|
[Regexp.last_match[1], "mention", "@"]
|
@@ -184,7 +202,15 @@ module HTML
|
|
184
202
|
emoji = Emoji.find_by_alias(Regexp.last_match[1])
|
185
203
|
|
186
204
|
if emoji
|
187
|
-
emoji.
|
205
|
+
if emoji.custom?
|
206
|
+
if @large_emoji
|
207
|
+
@large_emoji_image_tag.call(emoji)
|
208
|
+
else
|
209
|
+
@emoji_image_tag.call(emoji)
|
210
|
+
end
|
211
|
+
else
|
212
|
+
emoji.raw
|
213
|
+
end
|
188
214
|
else
|
189
215
|
match
|
190
216
|
end
|
@@ -212,6 +238,22 @@ module HTML
|
|
212
238
|
end
|
213
239
|
end
|
214
240
|
end
|
241
|
+
|
242
|
+
private
|
243
|
+
|
244
|
+
def only_emoji_and_whitespace?(string)
|
245
|
+
matchdata = EMOJI_AND_WHITESPACE_PATTERN.match(string)
|
246
|
+
|
247
|
+
matchdata && matchdata[0] == string
|
248
|
+
end
|
249
|
+
|
250
|
+
def emoji_count(string)
|
251
|
+
string.scan(NON_CAPTURING_EMOJI_PATTERN).size
|
252
|
+
end
|
253
|
+
|
254
|
+
def wants_large_emoji?(string)
|
255
|
+
only_emoji_and_whitespace?(string) && emoji_count(string).between?(1, 23)
|
256
|
+
end
|
215
257
|
end
|
216
258
|
end
|
217
259
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: html-pipeline-mrkdwn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Gorst
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-10-
|
11
|
+
date: 2024-10-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: escape_utils
|
@@ -138,6 +138,7 @@ files:
|
|
138
138
|
- Rakefile
|
139
139
|
- bin/mrkdwn
|
140
140
|
- lib/html/pipeline/mrkdwn.rb
|
141
|
+
- lib/html/pipeline/mrkdwn/helpers/pipeline.rb
|
141
142
|
- lib/html/pipeline/mrkdwn/mrkdwn_filter.rb
|
142
143
|
- lib/html/pipeline/mrkdwn/version.rb
|
143
144
|
homepage: https://github.com/jasongorst/html-pipeline-mrkdwn
|