slackdown 0.1.0 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +13 -15
- data/lib/kramdown/converter/slack.rb +179 -0
- data/lib/slackdown.rb +8 -1
- data/lib/slackdown/version.rb +1 -1
- data/slackdown.gemspec +9 -2
- metadata +102 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e9e099967cc2006352701a7a1f8178c937cc20cd84ca3ff7e88ea1a8a4ca7435
|
4
|
+
data.tar.gz: 80159b922c0c1e9f680da8e4174a8a1ef340a9c9d25774525c6a129a5611c0e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6fa59b7d48bbf98603395a2ff3730e1f59544e2ab1fa227dad02042f0b83f480005836db2782753a42bbb9e1bf214adde9bbc1a097f052dc55f82a6ac1a95f92
|
7
|
+
data.tar.gz: 4a434d128ccbb7d88a31fba18f083e3310f4193a772b35824bd4fcd409b01c8171d45f59496def5c8bd3b1e1c3c21e462312ceee9368d6829fc2212a50266ce2
|
data/README.md
CHANGED
@@ -1,28 +1,26 @@
|
|
1
1
|
# Slackdown
|
2
2
|
|
3
|
-
|
3
|
+
Slackdown converts Markdown to [Slack's simpler markup syntax](https://get.slack.help/hc/en-us/articles/202288908-How-can-I-add-formatting-to-my-messages-).
|
4
4
|
|
5
|
-
|
5
|
+
Slackdown implements a converter for [kramdown](https://github.com/gettalong/kramdown).
|
6
6
|
|
7
|
-
## Installation
|
8
7
|
|
9
|
-
|
8
|
+
## Usage
|
10
9
|
|
11
10
|
```ruby
|
12
|
-
|
13
|
-
```
|
14
|
-
|
15
|
-
And then execute:
|
11
|
+
require "slackdown"
|
16
12
|
|
17
|
-
|
13
|
+
Slackdown.convert(markdown_text)
|
14
|
+
```
|
18
15
|
|
19
|
-
|
16
|
+
If you're familiar with Kramdown, you can also do:
|
20
17
|
|
21
|
-
|
18
|
+
```ruby
|
19
|
+
require "kramdown/converter/slack"
|
22
20
|
|
23
|
-
|
21
|
+
Kramdown::Document.new(markdown_text, options).to_slack
|
22
|
+
```
|
24
23
|
|
25
|
-
TODO: Write usage instructions here
|
26
24
|
|
27
25
|
## Development
|
28
26
|
|
@@ -30,12 +28,12 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
30
28
|
|
31
29
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
30
|
|
31
|
+
|
33
32
|
## Contributing
|
34
33
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
34
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/houston/slackdown.
|
36
35
|
|
37
36
|
|
38
37
|
## License
|
39
38
|
|
40
39
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
-
|
@@ -0,0 +1,179 @@
|
|
1
|
+
module Kramdown
|
2
|
+
module Converter
|
3
|
+
|
4
|
+
# Converts a Kramdown::Document to Slack.
|
5
|
+
# https://api.slack.com/docs/message-formatting
|
6
|
+
class Slack < Base
|
7
|
+
|
8
|
+
def convert(el)
|
9
|
+
if el.type == :html_element
|
10
|
+
converter = :"convert_html_#{el.value}"
|
11
|
+
converter = :convert_html_element unless respond_to? converter
|
12
|
+
else
|
13
|
+
converter = :"convert_#{el.type}"
|
14
|
+
end
|
15
|
+
send(converter, el)
|
16
|
+
end
|
17
|
+
|
18
|
+
def inner(el)
|
19
|
+
el.children.map { |el| convert(el) }.join
|
20
|
+
end
|
21
|
+
alias :convert_root :inner
|
22
|
+
|
23
|
+
def convert_p(el)
|
24
|
+
"#{inner(el).strip.gsub(/\n/, " ")}\n\n"
|
25
|
+
end
|
26
|
+
|
27
|
+
def convert_text(el)
|
28
|
+
el.value
|
29
|
+
end
|
30
|
+
alias :convert_abbreviation :convert_text
|
31
|
+
|
32
|
+
def convert_blank(el)
|
33
|
+
""
|
34
|
+
end
|
35
|
+
alias :convert_br :convert_blank
|
36
|
+
alias :convert_comment :convert_blank
|
37
|
+
|
38
|
+
def convert_html_br(el)
|
39
|
+
"\n"
|
40
|
+
end
|
41
|
+
|
42
|
+
def convert_strong(el)
|
43
|
+
"*#{inner(el)}*"
|
44
|
+
end
|
45
|
+
alias :convert_html_b :convert_strong
|
46
|
+
alias :convert_html_strong :convert_strong
|
47
|
+
|
48
|
+
def convert_em(el)
|
49
|
+
"_#{inner(el)}_"
|
50
|
+
end
|
51
|
+
alias :convert_html_i :convert_em
|
52
|
+
alias :convert_html_em :convert_em
|
53
|
+
|
54
|
+
def convert_del(el)
|
55
|
+
"~#{inner(el)}~"
|
56
|
+
end
|
57
|
+
alias :convert_html_del :convert_del
|
58
|
+
|
59
|
+
def convert_codespan(el)
|
60
|
+
"`#{el.value}`"
|
61
|
+
end
|
62
|
+
alias :convert_html_code :convert_codespan
|
63
|
+
|
64
|
+
def convert_blockquote(el)
|
65
|
+
"> #{inner(el)}"
|
66
|
+
end
|
67
|
+
|
68
|
+
def convert_codeblock(el)
|
69
|
+
"```\n#{el.value}```\n\n"
|
70
|
+
end
|
71
|
+
|
72
|
+
def convert_a(el)
|
73
|
+
content = inner(el)
|
74
|
+
return el.attr["href"] if content.nil? || content == ""
|
75
|
+
"<#{el.attr["href"]}|#{content}>"
|
76
|
+
end
|
77
|
+
alias :convert_html_a :convert_a
|
78
|
+
|
79
|
+
def convert_img(el)
|
80
|
+
el.attr["src"]
|
81
|
+
end
|
82
|
+
alias :convert_html_img :convert_img
|
83
|
+
|
84
|
+
def convert_ul(el)
|
85
|
+
@bullet = UlBulletGenerator.new
|
86
|
+
"#{inner(el)}\n"
|
87
|
+
end
|
88
|
+
alias :convert_html_ul :convert_ul
|
89
|
+
|
90
|
+
def convert_ol(el)
|
91
|
+
@bullet = OlBulletGenerator.new
|
92
|
+
"#{inner(el)}\n"
|
93
|
+
end
|
94
|
+
alias :convert_html_ol :convert_ol
|
95
|
+
|
96
|
+
def convert_li(el)
|
97
|
+
" #{bullet.next} #{inner(el).strip}\n"
|
98
|
+
end
|
99
|
+
alias :convert_html_li :convert_li
|
100
|
+
|
101
|
+
def convert_header(el)
|
102
|
+
"\n\n#{convert_strong(el)}\n"
|
103
|
+
end
|
104
|
+
alias :convert_html_h1 :convert_header
|
105
|
+
alias :convert_html_h2 :convert_header
|
106
|
+
alias :convert_html_h3 :convert_header
|
107
|
+
alias :convert_html_h4 :convert_header
|
108
|
+
alias :convert_html_h5 :convert_header
|
109
|
+
alias :convert_html_h6 :convert_header
|
110
|
+
|
111
|
+
def convert_hr(el)
|
112
|
+
"----------------------------------------------\n\n"
|
113
|
+
end
|
114
|
+
|
115
|
+
def convert_smart_quote(el)
|
116
|
+
SMART_QUOTES.fetch(el.value)
|
117
|
+
end
|
118
|
+
|
119
|
+
def convert_typographic_sym(el)
|
120
|
+
TYPOGRAPHIC_SYMBOLS.fetch(el.value)
|
121
|
+
end
|
122
|
+
|
123
|
+
def convert_entity(el)
|
124
|
+
el.value.char
|
125
|
+
end
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
def __convert_todo(el)
|
130
|
+
inner(el)
|
131
|
+
end
|
132
|
+
alias :convert_html_element :__convert_todo
|
133
|
+
|
134
|
+
# The following are all tags converted by Kramdown::Converter::Html
|
135
|
+
alias :convert_dd :__convert_todo
|
136
|
+
alias :convert_dl :__convert_todo
|
137
|
+
alias :convert_dt :__convert_todo
|
138
|
+
alias :convert_footnote :__convert_todo
|
139
|
+
alias :convert_math :__convert_todo
|
140
|
+
alias :convert_raw :__convert_todo
|
141
|
+
alias :convert_table :__convert_todo
|
142
|
+
alias :convert_tbody :__convert_todo
|
143
|
+
alias :convert_td :__convert_todo
|
144
|
+
alias :convert_tfoot :__convert_todo
|
145
|
+
alias :convert_thead :__convert_todo
|
146
|
+
alias :convert_tr :__convert_todo
|
147
|
+
alias :convert_xml_comment :__convert_todo
|
148
|
+
alias :convert_xml_pi :__convert_todo
|
149
|
+
|
150
|
+
private
|
151
|
+
attr_reader :bullet
|
152
|
+
|
153
|
+
class UlBulletGenerator
|
154
|
+
def next; "• "; end
|
155
|
+
end
|
156
|
+
|
157
|
+
class OlBulletGenerator
|
158
|
+
def initialize; @i = 0; end
|
159
|
+
def next; "#{@i += 1}."; end
|
160
|
+
end
|
161
|
+
|
162
|
+
SMART_QUOTES = {
|
163
|
+
lsquo: "‘",
|
164
|
+
rsquo: "’",
|
165
|
+
ldquo: "“",
|
166
|
+
rdquo: "”" }.freeze
|
167
|
+
|
168
|
+
TYPOGRAPHIC_SYMBOLS = {
|
169
|
+
mdash: "—",
|
170
|
+
ndash: "–",
|
171
|
+
hellip: "...",
|
172
|
+
laquo_space: "« ",
|
173
|
+
raquo_space: " »",
|
174
|
+
laquo: "«",
|
175
|
+
raquo: "»" }.freeze
|
176
|
+
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
data/lib/slackdown.rb
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
require "slackdown/version"
|
2
|
+
require "kramdown"
|
3
|
+
require "kramdown/converter/slack"
|
4
|
+
require "kramdown-parser-gfm"
|
2
5
|
|
3
6
|
module Slackdown
|
4
|
-
|
7
|
+
|
8
|
+
def self.convert(markdown, options={})
|
9
|
+
Kramdown::Document.new(markdown.to_s, options.merge(input: "GFM")).to_slack
|
10
|
+
end
|
11
|
+
|
5
12
|
end
|
data/lib/slackdown/version.rb
CHANGED
data/slackdown.gemspec
CHANGED
@@ -19,7 +19,14 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
-
spec.
|
23
|
-
spec.
|
22
|
+
spec.add_dependency "kramdown", "~> 2.3"
|
23
|
+
spec.add_dependency "kramdown-parser-gfm", "~> 1.0", ">= 1.0.1"
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler"
|
26
|
+
spec.add_development_dependency "rake"
|
24
27
|
spec.add_development_dependency "minitest", "~> 5.0"
|
28
|
+
spec.add_development_dependency "minitest-reporters"
|
29
|
+
spec.add_development_dependency "minitest-reporters-turn_reporter"
|
30
|
+
spec.add_development_dependency "shoulda-context"
|
31
|
+
spec.add_development_dependency "pry"
|
25
32
|
end
|
metadata
CHANGED
@@ -1,43 +1,77 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slackdown
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bob Lail
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: kramdown
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
20
|
-
type: :
|
19
|
+
version: '2.3'
|
20
|
+
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '2.3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: kramdown-parser-gfm
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
34
|
-
|
33
|
+
version: '1.0'
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 1.0.1
|
37
|
+
type: :runtime
|
35
38
|
prerelease: false
|
36
39
|
version_requirements: !ruby/object:Gem::Requirement
|
37
40
|
requirements:
|
38
41
|
- - "~>"
|
39
42
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
43
|
+
version: '1.0'
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 1.0.1
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: bundler
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rake
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
41
75
|
- !ruby/object:Gem::Dependency
|
42
76
|
name: minitest
|
43
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,6 +86,62 @@ dependencies:
|
|
52
86
|
- - "~>"
|
53
87
|
- !ruby/object:Gem::Version
|
54
88
|
version: '5.0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: minitest-reporters
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: minitest-reporters-turn_reporter
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: shoulda-context
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
type: :development
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: pry
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
type: :development
|
139
|
+
prerelease: false
|
140
|
+
version_requirements: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
55
145
|
description: A converter for Kramdown that converts GitHub-Flavored Markdown to Slack's
|
56
146
|
simplified Markdown
|
57
147
|
email:
|
@@ -68,6 +158,7 @@ files:
|
|
68
158
|
- Rakefile
|
69
159
|
- bin/console
|
70
160
|
- bin/setup
|
161
|
+
- lib/kramdown/converter/slack.rb
|
71
162
|
- lib/slackdown.rb
|
72
163
|
- lib/slackdown/version.rb
|
73
164
|
- slackdown.gemspec
|
@@ -90,8 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
181
|
- !ruby/object:Gem::Version
|
91
182
|
version: '0'
|
92
183
|
requirements: []
|
93
|
-
|
94
|
-
rubygems_version: 2.5.1
|
184
|
+
rubygems_version: 3.1.4
|
95
185
|
signing_key:
|
96
186
|
specification_version: 4
|
97
187
|
summary: Converts Markdown text to Slack's simplified markdown
|