Skip to content

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

License

Notifications You must be signed in to change notification settings

affinity/slack_transformer

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

74 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:

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:

* 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

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 100.0%