html-pipeline-mrkdwn 0.1.1 → 0.1.2
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/CHANGELOG.md +11 -0
- data/Gemfile.lock +5 -3
- data/bin/mrkdwn +7 -0
- data/lib/html/pipeline/mrkdwn/mrkdwn_filter.rb +43 -30
- data/lib/html/pipeline/mrkdwn/version.rb +1 -1
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0eb17fa9037f2b2f46094838495825879431ed801420ba13e955e2bf4e90cbd6
|
4
|
+
data.tar.gz: 46d2ac462fe75c75c1c0713173f2cb5f5c37867765297ea83b027dd01d4e9229
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 319aa1921131f6809f05c1e3f2c7cb99f9cea546ff55f9d271ff29e154efa2830dce043599f8baad59f967f1ab19d3dc142fc811c5c735c2f0b00374ebf05afb
|
7
|
+
data.tar.gz: 6abbef7d6514383fc052009c0b29831b8fb054478790a16ed047375fe1a24acd012501538c689775f5933bbf39953cb515b15e7573b4384faa5c0540235057e2
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## [0.1.2] - 2022-12-26
|
4
|
+
|
5
|
+
- Split out code filter and apply after multiline code filter
|
6
|
+
- Add a command line interface as bin/mrkdwn
|
7
|
+
|
8
|
+
## [0.1.1] - 2022-12-25
|
9
|
+
|
10
|
+
- Move mention and link filters before line break filter
|
11
|
+
|
1
12
|
## [0.1.0] - 2022-12-24
|
2
13
|
|
3
14
|
- Initial release
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
html-pipeline-mrkdwn (0.1.
|
4
|
+
html-pipeline-mrkdwn (0.1.2)
|
5
5
|
escape_utils (~> 1.3.0)
|
6
6
|
gemoji (~> 4.0.1)
|
7
7
|
html-pipeline (~> 2.14.3)
|
@@ -25,8 +25,10 @@ GEM
|
|
25
25
|
i18n (1.12.0)
|
26
26
|
concurrent-ruby (~> 1.0)
|
27
27
|
json (2.6.3)
|
28
|
+
mini_portile2 (2.8.1)
|
28
29
|
minitest (5.16.3)
|
29
|
-
nokogiri (1.13.10
|
30
|
+
nokogiri (1.13.10)
|
31
|
+
mini_portile2 (~> 2.8.0)
|
30
32
|
racc (~> 1.4)
|
31
33
|
parallel (1.22.1)
|
32
34
|
parser (3.1.3.0)
|
@@ -76,4 +78,4 @@ DEPENDENCIES
|
|
76
78
|
rubocop (~> 1.21)
|
77
79
|
|
78
80
|
BUNDLED WITH
|
79
|
-
2.
|
81
|
+
2.4.1
|
data/bin/mrkdwn
ADDED
@@ -15,11 +15,9 @@ module HTML
|
|
15
15
|
class Mrkdwn < Filter
|
16
16
|
MULTILINE_CODE_PATTERN = /```(.+?)```/m.freeze
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
LINE_BREAK_PATTERN = /\n/.freeze
|
18
|
+
CODE_PATTERN = /`(?=\S)(.+?)(?<=\S)`/.freeze
|
21
19
|
|
22
|
-
|
20
|
+
BLOCKQUOTE_PATTERN = /(^>[^\n]*\n?)+/.freeze
|
23
21
|
|
24
22
|
MENTION_PATTERN = /
|
25
23
|
<
|
@@ -34,6 +32,10 @@ module HTML
|
|
34
32
|
>
|
35
33
|
/x.freeze
|
36
34
|
|
35
|
+
LINE_BREAK_PATTERN = /\n/.freeze
|
36
|
+
|
37
|
+
EMOJI_PATTERN = /:([\w+-]+):/.freeze
|
38
|
+
|
37
39
|
STYLE_PATTERN = /
|
38
40
|
([`*_~])
|
39
41
|
(?=\S)(.+?)(?<=\S)
|
@@ -44,18 +46,19 @@ module HTML
|
|
44
46
|
|
45
47
|
ELEMENTS = {
|
46
48
|
multiline_code: %w[```],
|
49
|
+
code: %w[`],
|
47
50
|
blockquote: %w[>],
|
48
51
|
mention: %w[@ # !],
|
49
52
|
link: %w[<],
|
50
53
|
line_break: %W[\n \r\n],
|
51
54
|
emoji: %w[:],
|
52
|
-
style: %w[
|
55
|
+
style: %w[* _ ~]
|
53
56
|
}.freeze
|
54
57
|
|
55
58
|
def initialize(doc, context = nil, result = nil)
|
56
59
|
super(doc, context, result)
|
57
60
|
|
58
|
-
@emoji_image_tag = ->(emoji) { emoji }
|
61
|
+
@emoji_image_tag = ->(emoji) { "<img src=\"#{emoji.image_filename}\" alt=\"#{emoji.name}\" class=\"emoji\">" }
|
59
62
|
@slack_channels = {}
|
60
63
|
@slack_users = {}
|
61
64
|
|
@@ -104,8 +107,8 @@ module HTML
|
|
104
107
|
end
|
105
108
|
end
|
106
109
|
|
107
|
-
def call_filter(
|
108
|
-
method = "#{
|
110
|
+
def call_filter(filter_name, content)
|
111
|
+
method = "#{filter_name}_filter".to_sym
|
109
112
|
send method, content
|
110
113
|
end
|
111
114
|
|
@@ -117,6 +120,18 @@ module HTML
|
|
117
120
|
end
|
118
121
|
end
|
119
122
|
|
123
|
+
def code_filter(content)
|
124
|
+
content.gsub CODE_PATTERN do |match|
|
125
|
+
text = Regexp.last_match[1]
|
126
|
+
|
127
|
+
if text&.match(/\A[`]+\Z/) # ignore runs of backquotes
|
128
|
+
match
|
129
|
+
else
|
130
|
+
"<code>#{text}</code>"
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
120
135
|
def blockquote_filter(content)
|
121
136
|
content.gsub BLOCKQUOTE_PATTERN do
|
122
137
|
text = Regexp.last_match[0].chomp
|
@@ -126,35 +141,19 @@ module HTML
|
|
126
141
|
end
|
127
142
|
end
|
128
143
|
|
129
|
-
def line_break_filter(content)
|
130
|
-
content.gsub(LINE_BREAK_PATTERN, "<br>")
|
131
|
-
end
|
132
|
-
|
133
|
-
def emoji_filter(content)
|
134
|
-
content.gsub(EMOJI_PATTERN) do |match|
|
135
|
-
emoji = Emoji.find_by_alias(Regexp.last_match[1])
|
136
|
-
|
137
|
-
if emoji
|
138
|
-
emoji.raw || context.dig(:emoji_image_tag)&.call(emoji) || match
|
139
|
-
else
|
140
|
-
match
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
144
|
def mention_filter(content)
|
146
145
|
content.gsub MENTION_PATTERN do |match|
|
147
146
|
mention = Regexp.last_match[1]
|
148
147
|
|
149
148
|
(text, klass, prefix) =
|
150
149
|
case mention
|
151
|
-
when /\A#(C.+)\Z/ # slack
|
150
|
+
when /\A#(C.+)\Z/ # slack channels
|
152
151
|
[context.dig(:slack_channels, Regexp.last_match[1]) || Regexp.last_match[1], "channel", "#"]
|
153
152
|
|
154
|
-
when /\A@([UB].+)\Z/ # slack
|
153
|
+
when /\A@([UB].+)\Z/ # slack users or bots
|
155
154
|
[context.dig(:slack_users, Regexp.last_match[1]) || Regexp.last_match[1], "user", "@"]
|
156
155
|
|
157
|
-
when /\A!(here|channel|everyone)\Z/ # special
|
156
|
+
when /\A!(here|channel|everyone)\Z/ # special mentions
|
158
157
|
[Regexp.last_match[1], "mention", "@"]
|
159
158
|
else
|
160
159
|
nil
|
@@ -177,17 +176,31 @@ module HTML
|
|
177
176
|
end
|
178
177
|
end
|
179
178
|
|
179
|
+
def line_break_filter(content)
|
180
|
+
content.gsub(LINE_BREAK_PATTERN, "<br>")
|
181
|
+
end
|
182
|
+
|
183
|
+
def emoji_filter(content)
|
184
|
+
content.gsub(EMOJI_PATTERN) do |match|
|
185
|
+
emoji = Emoji.find_by_alias(Regexp.last_match[1])
|
186
|
+
|
187
|
+
if emoji
|
188
|
+
emoji.raw || context.dig(:emoji_image_tag)&.call(emoji) || match
|
189
|
+
else
|
190
|
+
match
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
180
195
|
def style_filter(content)
|
181
196
|
content.gsub STYLE_PATTERN do |match|
|
182
197
|
style = Regexp.last_match[1]
|
183
198
|
text = Regexp.last_match[2]
|
184
199
|
|
185
|
-
if text&.match(/\A[#{style}]+\Z/) # ignore runs of
|
200
|
+
if text&.match(/\A[#{style}]+\Z/) # ignore runs of style delimiters
|
186
201
|
match
|
187
202
|
else
|
188
203
|
case style
|
189
|
-
when "`"
|
190
|
-
"<code>#{text}</code>"
|
191
204
|
when "*"
|
192
205
|
"<strong>#{style_filter(text)}</strong>"
|
193
206
|
when "_"
|
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.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Gorst
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-12-
|
11
|
+
date: 2022-12-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: escape_utils
|
@@ -68,7 +68,8 @@ dependencies:
|
|
68
68
|
version: 3.12.0
|
69
69
|
description: An HTML::Pipeline filter for Slack's mrkdwn markup language.
|
70
70
|
email: jason.gorst@me.com
|
71
|
-
executables:
|
71
|
+
executables:
|
72
|
+
- mrkdwn
|
72
73
|
extensions: []
|
73
74
|
extra_rdoc_files: []
|
74
75
|
files:
|
@@ -81,6 +82,7 @@ files:
|
|
81
82
|
- LICENSE.txt
|
82
83
|
- README.md
|
83
84
|
- Rakefile
|
85
|
+
- bin/mrkdwn
|
84
86
|
- lib/html/pipeline/mrkdwn.rb
|
85
87
|
- lib/html/pipeline/mrkdwn/mrkdwn_filter.rb
|
86
88
|
- lib/html/pipeline/mrkdwn/version.rb
|
@@ -107,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
109
|
- !ruby/object:Gem::Version
|
108
110
|
version: '0'
|
109
111
|
requirements: []
|
110
|
-
rubygems_version: 3.
|
112
|
+
rubygems_version: 3.4.1
|
111
113
|
signing_key:
|
112
114
|
specification_version: 4
|
113
115
|
summary: An HTML::Pipeline filter for Slack's mrkdwn markup language.
|