Tools for working with HTML, mrkdwn, and Slack commands in Ruby
See Basic message formatting for Slack's message formatting guidelines.
gem install slack_transformer
gem 'slack_transformer'
SlackTransformer::Html.new('<b><i>important stuff</i></b>').to_slack
# => "*_important stuff_*"
SlackTransformer::Html
applies the following transformations in the order listed:
Note: Slack doesn't support underline.
Each transformation can also be applied individually.
SlackTransformer::Html::Bold.new('<b>bold</b>').to_slack
# => "*bold*"
SlackTransformer::Html::Italics.new('<i>italics</i>').to_slack
# => "_italics_"
SlackTransformer::Html::Strikethrough.new('<s>strikethrough</s>').to_slack
# => "~strikethrough~"
SlackTransformer::Html::Code.new('<code>code</code>').to_slack
# => "`code`"
SlackTransformer::Html::Preformatted.new('<pre>preformatted</pre>').to_slack
# => "```preformatted```"
SlackTransformer::Html::Lists.new('<ul><li>foo</li><li>bar</li><li>baz</li></ul>').to_slack
# => "• foo\n• bar\n• baz"
SlackTransformer::Html::Lists.new('<ol><li>foo</li><li>bar</li><li>baz</li></ol>').to_slack
# => "1. foo\n2. bar\n3. baz"
SlackTransformer::Entities.new('&<>').to_slack
# => "&<>"
SlackTransformer::Date
understands anything that Time::parse
understands.
SlackTransformer::Date.new('2018-05-04T00:00:00Z', format: '{date_pretty}', fallback: 'May 4, 2018').to_slack
# => "<!date^1525392000^{date_pretty}|May 4, 2018>"
SlackTransformer::Slack.new('*_important stuff_*').to_html
# => "<p><b><i>important stuff</i></b></p>"
SlackTransformer::Slack
applies the following transformations in the order listed:
* Adjacent or nested quotes and blockquotes may not behave as expected.
Each transformation can also be applied individually.
SlackTransformer::Slack::Bold.new('*bold*').to_html
# => "<b>bold</b>"
SlackTransformer::Slack::Italics.new('_italics_').to_html
# => "<i>italics</i>"
SlackTransformer::Slack::Strikethrough.new('~strikethrough~').to_html
# => "<s>strikethrough</s>"
SlackTransformer::Slack::Code.new('`code`').to_html
# => "<code>code</code>"
SlackTransformer::Slack::Preformatted.new('```preformatted```').to_html
# => "<pre>preformatted</pre>"
SlackTransformer::Slack::Quote.new('>quote').to_html
# => "<blockquote>quote</blockquote>"
SlackTransformer::Slack::Blockquote.new(">>>blockquote\nblockquote").to_html
# => "<blockquote>blockquote<br>blockquote</blockquote>"
The following transformations are either not yet supported or partially supported:
HTML to Slack
- blockquote
Slack to HTML
- quote*
- blockquote*
- lists
* Adjacent or nested quotes and blockquotes may not behave as expected.
MIT License
Copyright © 2018 Everwise