Low commit activity in last 3 years
No release in over a year
Transform HTML into Slack-ready mrkdwn and back
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 3.7.0

Runtime

 Project Readme

Gem Version

SlackTransformer

Tools for working with HTML, mrkdwn, and Slack commands in Ruby

See Basic message formatting for Slack's message formatting guidelines.

Installation

RubyGems

gem install slack_transformer

Bundler

gem 'slack_transformer'

HTML to Slack

SlackTransformer::Html.new('<b><i>important stuff</i></b>').to_slack
# => "*_important stuff_*"

SlackTransformer::Html applies the following transformations in the order listed:

  • bold
  • italics
  • strikethrough
  • code
  • preformatted
  • lists

Note: Slack doesn't support underline.

Each transformation can also be applied individually.

Bold

SlackTransformer::Html::Bold.new('<b>bold</b>').to_slack
# => "*bold*"

Italics

SlackTransformer::Html::Italics.new('<i>italics</i>').to_slack
# => "_italics_"

Strikethrough

SlackTransformer::Html::Strikethrough.new('<s>strikethrough</s>').to_slack
# => "~strikethrough~"

Code

SlackTransformer::Html::Code.new('<code>code</code>').to_slack
# => "`code`"

Preformatted

SlackTransformer::Html::Preformatted.new('<pre>preformatted</pre>').to_slack
# => "```preformatted```"

Lists

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"

Entities

SlackTransformer::Entities.new('&<>').to_slack
# => "&amp;&lt;&gt;"

Date

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>"

Slack to HTML

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:

  • bold
  • italics
  • strikethrough
  • code
  • preformatted
  • quote*
  • blockquote*

* Adjacent or nested quotes and blockquotes may not behave as expected.

Each transformation can also be applied individually.

Bold

SlackTransformer::Slack::Bold.new('*bold*').to_html
# => "<b>bold</b>"

Italics

SlackTransformer::Slack::Italics.new('_italics_').to_html
# => "<i>italics</i>"

Strikethrough

SlackTransformer::Slack::Strikethrough.new('~strikethrough~').to_html
# => "<s>strikethrough</s>"

Code

SlackTransformer::Slack::Code.new('`code`').to_html
# => "<code>code</code>"

Preformatted

SlackTransformer::Slack::Preformatted.new('```preformatted```').to_html
# => "<pre>preformatted</pre>"

Quote

SlackTransformer::Slack::Quote.new('>quote').to_html
# => "<blockquote>quote</blockquote>"

Blockquote

SlackTransformer::Slack::Blockquote.new(">>>blockquote\nblockquote").to_html
# => "<blockquote>blockquote<br>blockquote</blockquote>"

Contributing

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.

License

MIT License

Copyright © 2018 Everwise