Class: Slackdown
- Inherits:
-
Object
- Object
- Slackdown
- Defined in:
- app/models/slackdown.rb
Overview
Converts GitHub-flavored Markdown to Slack-flavored Markdown
Instance Attribute Summary collapse
-
#markdown ⇒ Object
readonly
Returns the value of attribute markdown.
Instance Method Summary collapse
- #convert ⇒ Object (also: #to_s)
-
#initialize(markdown) ⇒ Slackdown
constructor
A new instance of Slackdown.
Constructor Details
#initialize(markdown) ⇒ Slackdown
Returns a new instance of Slackdown.
5 6 7 |
# File 'app/models/slackdown.rb', line 5 def initialize(markdown) @markdown = markdown.to_s end |
Instance Attribute Details
#markdown ⇒ Object (readonly)
Returns the value of attribute markdown.
3 4 5 |
# File 'app/models/slackdown.rb', line 3 def markdown @markdown end |
Instance Method Details
#convert ⇒ Object Also known as: to_s
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/models/slackdown.rb', line 9 def convert # Remove the source name from fenced code blocks slackdown = markdown.gsub(/^```(ruby|diff|css|json|sql|html|xml|coffee(?:script)?|javascript|js|bash)/, "```") # Convert `__` and `**` to `*` slackdown = slackdown.gsub(/(?<!_)__(?!_)/, "*") .gsub(/(?<!\*)\*\*(?!\*)/, "*") # Replace images with their URLs: Slack will unfurl them slackdown = slackdown.gsub(/<img[^>]*src="([^"]+)"[^>]*>/, "\\1") slackdown end |