Skip to content

Instantly share code, notes, and snippets.

@matthughes
Forked from h6y3/md_slack.rb
Last active March 6, 2024 21:21
Show Gist options
  • Save matthughes/349f9ca2449a529e276d05f3877df1a9 to your computer and use it in GitHub Desktop.
Save matthughes/349f9ca2449a529e276d05f3877df1a9 to your computer and use it in GitHub Desktop.
Obsidian Markdown to Slack
#!/usr/bin/env ruby
# Read from stdin rather than file.
file_data = $stdin.read
# Upper case title
re = /^#* .+/
file_data.gsub!(re) { |match| "*#{match.upcase}*"}
# Mutate todos
file_data.gsub!("- [ ]","*ACTION ITEM:* ")
# Substitute ** for *
file_data.gsub!("**","*")
# Remove #
file_data.gsub!("\#\#\# ","")
file_data.gsub!("\#\# ","")
file_data.gsub!("\# ","")
# Add bullets since Slack doesn't support bullets and add indentation because gsub doesn't support capture groups
re = /^ - /
file_data.gsub!(re," • ")
re = /^ - /
file_data.gsub!(re," • ")
re = /^- /
file_data.gsub!(re,"• ")
# Remove mentions
file_data.gsub!("[[","")
file_data.gsub!("]]","")
# Remove highlights
file_data.gsub!("==","")
# Reformat URLs
file_data.gsub!("[","")
file_data.gsub!("]",": ")
# File.write(File.basename(file) + "_slack.txt", file_data)
puts file_data
@matthughes
Copy link
Author

On Mac, put this in your ~/bin directory and then add this alias:

alias mdslack='pbpaste | ~/bin/md_slack.rb | pbcopy'

Now just copy whatever Obsidian note you want to clipboard and run mdslack. It will paste the translated version to your clipboard from which you can paste into Slack.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment