Skip to main content

Searching over the forums and Google I’ve found more than a few threads of individuals converting Gmail contents and/or generic HTML for Slack markdown, but I haven’t been able to find anything about the opposite. 

For the most part there isn’t a problem with just taking the text (or raw text) of the Slack message and inserting it as the body of the Gmail action, with the exception of links. For example, a link formatted for Slack will come out as the following raw text. 

<https://www.example.com/|Example Link>

Does anyone have a clever solution for converting this into something more elegant for plaintext or HTML output? 

Hi @jaredwa 

Good question.

You can try using the Formatter > Text > Markdown to HTML option: https://zapier.com/apps/formatter/help


Hi @jaredwa 

Good question.

You can try using the Formatter > Text > Markdown to HTML option: https://zapier.com/apps/formatter/help

Thank you for the reply. 

Unfortunately, because Slack markdown is (presumably) substantially different from what the Markdown to HTML option expects from markdown, this results in equally broken output. For example, a message like the following,

Example paragraph 1
Example paragraph 2, <https://www.example.com/|Example Link> goes here。

will unfortunately result in some mostly unusable HTML.

<p>Example paragraph 1</p>
<p>Example paragraph 2, <a href="https://www.example.com/|Example Link">https://www.example.com/|Example Link</a>goes here。</p>

While not a total waste of an action, I would have to go in with a script after to add line breaks and fix all of the links, and were it possible I was hoping for a more elegant solution. 


Hi @jaredwa!

I found this info from Slack on how to remove formatting

  1. Detect all sub-strings matching <(.*?)>
  2. Within those sub-strings, format content starting with #C as a channel link
  3. Format content starting with @U or @W as a user mention
  4. Format content starting with !subteam as a user group mention
  5. Format content starting with ! according to the rules for special mentions
  6. For any other content within those sub-strings, format as a URL link
  7. Once the format has been determined, check for a pipe (|) - if present, use the text following the pipe as the label for the link or mention.

If you’re good with code, you might be able to whip up a bit of javascript that handles that, but I’m afraid that I don’t know how 🙈


Hi @jaredwa!

I found this info from Slack on how to remove formatting

  1. Detect all sub-strings matching <(.*?)>
  2. Within those sub-strings, format content starting with #C as a channel link
  3. Format content starting with @U or @W as a user mention
  4. Format content starting with !subteam as a user group mention
  5. Format content starting with ! according to the rules for special mentions
  6. For any other content within those sub-strings, format as a URL link
  7. Once the format has been determined, check for a pipe (|) - if present, use the text following the pipe as the label for the link or mention.

If you’re good with code, you might be able to whip up a bit of javascript that handles that, but I’m afraid that I don’t know how 🙈

Thank you for the idea. While not a Javascript whiz by any stretch of the imagination, I whipped up a short script to fix HTTPS links into standard markdown so that the Markdown to HTML option could be used. 

const { text } = inputData;
const regex = /<(https?:\/\/c\w-]+(?:\. \w]+)+(?:\/p\w?=%&@$#_.+]+)*\/?)(?:\|((?:?^>])+))?>/g;
const result = text.replace(regex, (`r$2]($1)`));
output = ,{ result }];

Thanks to everyone for helping sort this one out!


Awesome, thanks so much for sharing your the script you used! 🙌🏻


Hi @jaredwa!

I found this info from Slack on how to remove formatting

  1. Detect all sub-strings matching <(.*?)>
  2. Within those sub-strings, format content starting with #C as a channel link
  3. Format content starting with @U or @W as a user mention
  4. Format content starting with !subteam as a user group mention
  5. Format content starting with ! according to the rules for special mentions
  6. For any other content within those sub-strings, format as a URL link
  7. Once the format has been determined, check for a pipe (|) - if present, use the text following the pipe as the label for the link or mention.

If you’re good with code, you might be able to whip up a bit of javascript that handles that, but I’m afraid that I don’t know how 🙈

Thank you for the idea. While not a Javascript whiz by any stretch of the imagination, I whipped up a short script to fix HTTPS links into standard markdown so that the Markdown to HTML option could be used. 

const { text } = inputData;
const regex = /<(https?:\/\/c\w-]+(?:\. \w]+)+(?:\/p\w?=%&@$#_.+]+)*\/?)(?:\|((?:?^>])+))?>/g;
const result = text.replace(regex, (`r$2]($1)`));
output = ,{ result }];

Thanks to everyone for helping sort this one out!

Any insight as to how to have it replace every URL it finds instead of only the first occurrence? 


Any insight as to how to have it replace every URL it finds instead of only the first occurrence? 

As written I haven’t had a problem at described; it’s replaced every URL.

However, I did have a few separate problems with links including unicode characters, mailto links, channels, @ mentions and whatnot. Here’s the updated script I’m using. The penultimate line is just adding linebreaks for readability. 

const { text } = inputData;
const slackAtFix = text.replace(/<((?:@|!)(?:.*?))>/g, (`$1`));
const slackChannelFix = slackAtFix.replace(/<#(?:.*?)\|(.*?)>/g, (`#$1`));
const linkFix = slackChannelFix.replace(/<(https?:\/\/h\w-]+(?:\.[\w]+)+(?:\/\^|]+)*\/?)(?:\|((?:?^>])+))?>/g, (`?$2]($1)`));
const mailtoFix = linkFix.replace(/<(mailto?:(?:m^|>])+)?(?:\|((?:)^>])+))?>/g, (`?$2]($1)`));
const result = mailtoFix.replace(/(?:\r\n|\r|\n)/g, '<br>');
output = /{ result }];

Unsure if this will help you or not, but cheers.