markdown_to_mrkdwn
Convert Markdown to Slack mrkdwn (lightweight, no dependencies).
Installation
Install the gem:
gem install markdown_to_mrkdwnOr add to your Gemfile:
gem "markdown_to_mrkdwn"For development, clone and setup:
git clone https://github.com/emp823/markdown_to_mrkdwn.git
cd markdown_to_mrkdwn
bin/setupUsage
Ruby API
require "markdown_to_mrkdwn"
mrkdwn = MarkdownToMrkdwn.convert(<<~MARKDOWN)
# Heading
**Bold** and *italic* and ~~strike~~ and `code`.
```ruby
puts "hello"
puts mrkdwn
### Command Line
```bash
# Convert from stdin
echo "# Title\n**bold** and _italic_." | markdown_to_mrkdwn
# Convert a file
markdown_to_mrkdwn README.md
# Use options
markdown_to_mrkdwn --plain-headings README.md
What’s converted
- Headings
#..######→ bold line (or plain with--plain-headings). - Bold
**text**or__text__→*text*. - Italic
*text*or_text_→_text_. - Strikethrough
~~text~~→~text~. - Inline code
`code`→`code`(unchanged). - Fenced code blocks
lang ...→...(language hint removed). - Links
[label](url)→<url|label>. - Images
→<url|alt>. - Horizontal rules → em dash line (or keep with
--keep-hr).
Notes:
- Lists, blockquotes, and paragraphs are mostly compatible with Slack already and are left as-is.
- Code (inline and blocks) is protected from other conversions.
- This is a pragmatic converter; edge cases of Markdown are not fully supported.
Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/my-new-feature) - Make your changes and add tests
- Run the test suite (
bundle exec rake test) - Ensure code style passes (
bundle exec rubocop) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin feature/my-new-feature) - Create a Pull Request
See CONTRIBUTING.md for detailed guidelines.
License
MIT - See LICENSE file for details.