Sha256: 2c6ce9d2ba6aa95c252d193bf6942334a0ccece3cd5bb7353d1c39949d72ac88

Contents?: true

Size: 671 Bytes

Versions: 1

Compression:

Stored size: 671 Bytes

Contents

# Converts GitHub-flavored Markdown to Slack-flavored Markdown
class Slackdown
  attr_reader :markdown

  def initialize(markdown)
    @markdown = markdown
  end

  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
  alias :to_s :convert

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
houston-core-0.6.3 app/models/slackdown.rb