slack_mrkdwn 1.1.0 → 2.0.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/lib/slack_mrkdwn.rb +130 -19
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b38208ce080dffeea4bbdacfcc5b455b78b91d872391cb96a0127d52feb98be7
|
4
|
+
data.tar.gz: aea90c46698e27b6b5d2290352773bd60b6e5446cdfe3932babdab647038c027
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ce667a87b45df0569e24ee3af209ceae51b2ef7108d95ed211c521ed6fa1e6a836f10bc0bcbd1c54474f68363665f14a50a824bdde6807a188c5a6139db3523
|
7
|
+
data.tar.gz: b2f82329e82c219743f6cdf418eb0ed00310988424e0b5b10b1014044c124abb8289c9f26b6ad84ab8e9e5a1d656b9a48e7f094bd64a501fcea0880ce2303460
|
data/lib/slack_mrkdwn.rb
CHANGED
@@ -1,19 +1,130 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'redcarpet'
|
3
|
+
|
4
|
+
class SlackMrkdwn < Redcarpet::Render::Base
|
5
|
+
# Methods where the first argument is the text content
|
6
|
+
[
|
7
|
+
# block-level calls
|
8
|
+
:block_html,
|
9
|
+
|
10
|
+
:autolink,
|
11
|
+
:raw_html,
|
12
|
+
|
13
|
+
:table, :table_row, :table_cell,
|
14
|
+
|
15
|
+
:superscript, :highlight,
|
16
|
+
|
17
|
+
# footnotes
|
18
|
+
:footnotes, :footnote_def, :footnote_ref,
|
19
|
+
|
20
|
+
:hrule,
|
21
|
+
|
22
|
+
# low level rendering
|
23
|
+
:entity, :normal_text,
|
24
|
+
|
25
|
+
:doc_header, :doc_footer,
|
26
|
+
].each do |method|
|
27
|
+
define_method method do |*args|
|
28
|
+
args.first
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Encode Slack restricted characters
|
33
|
+
def preprocess(content)
|
34
|
+
content.gsub('&', '&').gsub('<', '<').gsub('>', '>')
|
35
|
+
end
|
36
|
+
|
37
|
+
def postprocess(content)
|
38
|
+
content.rstrip
|
39
|
+
end
|
40
|
+
|
41
|
+
# ~~strikethrough~~
|
42
|
+
def strikethrough(content)
|
43
|
+
"~#{content}~"
|
44
|
+
end
|
45
|
+
|
46
|
+
# _italic_
|
47
|
+
def underline(content)
|
48
|
+
"_#{content}_"
|
49
|
+
end
|
50
|
+
|
51
|
+
# *italic*
|
52
|
+
def emphasis(content)
|
53
|
+
"_#{content}_"
|
54
|
+
end
|
55
|
+
|
56
|
+
# **bold**
|
57
|
+
def double_emphasis(content)
|
58
|
+
"*#{content}*"
|
59
|
+
end
|
60
|
+
|
61
|
+
# ***bold and italic***
|
62
|
+
def triple_emphasis(content)
|
63
|
+
"*_#{content}_*"
|
64
|
+
end
|
65
|
+
|
66
|
+
# ``` code block ```
|
67
|
+
def block_code(content, _language)
|
68
|
+
"```\n#{content}```\n"
|
69
|
+
end
|
70
|
+
|
71
|
+
# > quote
|
72
|
+
def block_quote(content)
|
73
|
+
"> #{content}"
|
74
|
+
end
|
75
|
+
|
76
|
+
# `code`
|
77
|
+
def codespan(content)
|
78
|
+
"`#{content}`"
|
79
|
+
end
|
80
|
+
|
81
|
+
# links
|
82
|
+
def link(link, _title, content)
|
83
|
+
"<#{link}|#{content}>"
|
84
|
+
end
|
85
|
+
|
86
|
+
# lists
|
87
|
+
def list(entries, list_type)
|
88
|
+
reset_list(list_type)
|
89
|
+
entries
|
90
|
+
end
|
91
|
+
|
92
|
+
def reset_list(list_type)
|
93
|
+
@list_item_count = 0 if list_type == :ordered
|
94
|
+
end
|
95
|
+
|
96
|
+
def list_prefix(list_type)
|
97
|
+
return "-" if list_type == :unordered
|
98
|
+
@list_item_count = 0 unless @list_item_count
|
99
|
+
@list_item_count += 1
|
100
|
+
"#{@list_item_count}."
|
101
|
+
end
|
102
|
+
|
103
|
+
def list_item(entry, list_type)
|
104
|
+
"#{list_prefix(list_type)} #{entry}"
|
105
|
+
end
|
106
|
+
|
107
|
+
# 
|
108
|
+
def image(link, _title, _alt_text)
|
109
|
+
link
|
110
|
+
end
|
111
|
+
|
112
|
+
def linebreak()
|
113
|
+
"\n"
|
114
|
+
end
|
115
|
+
|
116
|
+
def paragraph(text)
|
117
|
+
"#{text}\n"
|
118
|
+
end
|
119
|
+
|
120
|
+
def header(text, _header_level)
|
121
|
+
"*#{text}*\n"
|
122
|
+
end
|
123
|
+
|
124
|
+
class << self
|
125
|
+
def from(markdown)
|
126
|
+
renderer = SlackMrkdwn.new
|
127
|
+
Redcarpet::Markdown.new(renderer, strikethrough: true, underline: true, fenced_code_blocks: true).render(markdown)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slack_mrkdwn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simon Cousineau
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-08-
|
11
|
+
date: 2019-08-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: redcarpet
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -71,7 +85,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
71
85
|
requirements:
|
72
86
|
- - ">="
|
73
87
|
- !ruby/object:Gem::Version
|
74
|
-
version:
|
88
|
+
version: 1.9.2
|
75
89
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
90
|
requirements:
|
77
91
|
- - ">="
|