Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slack flavored Markdown #90

Open
RummanSadiq opened this issue Aug 7, 2020 · 6 comments
Open

Slack flavored Markdown #90

RummanSadiq opened this issue Aug 7, 2020 · 6 comments

Comments

@RummanSadiq
Copy link

Hi, I was recently working with slack integration and had to convert HTML into Slack Flavored Markdown, which is a bit different than GitHub Flavored.

For the urgent need, I forked this project and made the required changes to make it work with Slack. I thought this might be good starting point for me to contribute to open source. If you guys think that there is a use for Slack Flavored Markdown, then I'll be more than happy to open a PR for it.

Slack only allows a small subset of Markdown features. It includes things like Bold, Italic, Ordered List, Unordered List, Quote, Code Block.

@RummanSadiq
Copy link
Author

@xijo thoughts?

@xijo
Copy link
Owner

xijo commented Aug 11, 2020

Hi @RummanSadiq,

I'd say it depends on how big the differences between "normal" markdown and slack-flavored are.
Do they ignore other markdown or do we really have to unregister existing converters? Are there any other differences in the handling of the nodes itself?

Anyway it would be great to get you started on open source, so please feel free to submit a PR, we can discuss implementation detail there, right?

@gabrieldeal
Copy link

I also need to conver HTML to Slack's "mrkdwn". I was just trying to figure out whether I should roll my own, improve https://github.com/everwise/slack_transformer or add a Slack flavor to reverse_markdown.

I would be very curious to see what you did, @RummanSadiq.

@xijo, Slack's markup is quite different from Markdown, although they look very similar at first glance. For example:

  • **bold** in markdown is *bold* in Slack
  • Slack does not support headers
  • Slack does not support lists
  • [name](https://google.com) in markdown is <https://google.com|name> in Slack

Some markup works the same, like `code`, ~strike~, _italic_ and > blockquote.

https://api.slack.com/reference/surfaces/formatting

@jaredplanter
Copy link

Hey @gabrielmdeal,

Did you ever get anywhere with your need to convert HTML to Mrkdwn?

I have the same need now and the only libraries available (like slack_transformer) haven't been touched in 3+ years.

Thanks!

@gabrieldeal
Copy link

I ended up rolling my own. But I do not own the code, so there is nothing I can share. 😞

@JeremiahChurch
Copy link

a quick monkey patch covers the two really different slack mrkdown changes - bold & links

# slackify! # https://github.com/xijo/reverse_markdown/issues/90
module ReverseMarkdown
  module Converters
    class Strong < Base
      def convert(node, state = {})
        content = treat_children(node, state.merge(already_strong: true))
        if content.strip.empty? || state[:already_strong]
          content
        else
          "#{content[/^\s*/]}*#{content.strip}*#{content[/\s*$/]}"
        end
      end
    end

    class A < Base
      def convert(node, state = {})
        name  = treat_children(node, state)
        href  = node['href']
        title = extract_title(node)

        if href.to_s.empty? || name.empty?
          name
        else
          link = "<#{href}#{title}|#{name}>"
          link.prepend(' ') if prepend_space?(node)
          link
        end
      end
    end
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants