Action

Copy Slack-Style Markdown

Posted by jcoleman3307, Last update 19 days ago

Convert Github style-markdown to Slack markdown and put it on the clipboard (does not draft contents)

Steps

  • script

    function convertMarkdownToSlack(md) {
      return (
        md
          // Convert headings (#, ##, ###) to bold
          .replace(/^#{1,6}\s+(.*)/gm, "*$1*")
    
          // Convert horizontal rules (---, ***) to a line of dashes
          .replace(/^(\s*-{3,}\s*|\s*\*{3,}\s*)$/gm, "-----------")
    
          // Remove tables (keep only the raw text)
          .replace(/\|(.+?)\|/g, "$1") // Remove table borders
          .replace(/\|[\s-]+\|/g, "") // Remove table separators
    
          // Convert italics (*text* or _text_) to Slack-style _
          .replace(/\*(.*?)\*/g, "_$1_")
          .replace(/_(.*?)_/g, "_$1_")
    
          // Convert bold (**text** or __text__) to Slack-style *
          .replace(/\*\*(.*?)\*\*/g, "*$1*")
          .replace(/__(.*?)__/g, "*$1*")
    
          // Convert strikethrough (~~text~~) to Slack-style ~
          .replace(/~~(.*?)~~/g, "~$1~")
    
          // Normalize multiple spaces in list items
          .replace(/(^[*\d.]+)  +/gm, "$1 ")
      );
    }
    
    
    let slackMarkdown = convertMarkdownToSlack(draft.content)
    
    app.setClipboard(slackMarkdown)

Options

  • After Success Default
    Notification Info
    Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.