Skip to content

Instantly share code, notes, and snippets.

@h6y3
Last active May 26, 2023 08:55
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save h6y3/ae3cbe58de6ab647e408e6a42ff2772d to your computer and use it in GitHub Desktop.
Save h6y3/ae3cbe58de6ab647e408e6a42ff2772d to your computer and use it in GitHub Desktop.
Obsidian Markdown to Slack
#!/usr/bin/env ruby
filename = "/Users/hyuan/Development/bin/tmp/tmp_slack_md.txt"
file = File.open(filename)
file_data = file.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
@h6y3
Copy link
Author

h6y3 commented Aug 25, 2021

I use this script with https://www.keyboardmaestro.com/main/ so that I can copy my text notes from Obsidian, strip out and convert Obsidian Markdown to Slack Markdown and paste into channels when working with teams that are Slack based but still need well written (and formatted) notes.

@seagullmouse
Copy link

Any chance this could go in a plugin?

@matthughes
Copy link

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