mixmark-io / turndown

🛏 An HTML to Markdown converter written in JavaScript
https://mixmark-io.github.io/turndown
MIT License
8.62k stars 870 forks source link

Support for Slack markdown #420

Closed aiavci closed 1 year ago

aiavci commented 1 year ago

Slack's markdown format is a bit different. Would this project have support for it?

domchristie commented 1 year ago

Hi @aiavci, turndown doesn't support Slack Markdown by default, but you can extend it to add support with rules: https://github.com/mixmark-io/turndown#extending-with-rules.

joshkadis commented 1 year ago

In case anyone else is searching for it, here's what I did to use Slack's link format instead of regular Markdown

// Markdown [text](href)
// Slack    <href|text>

turndownService.addRule('slackLinks', {
  filter: ['a'],
  replacement(text, { href }) {
    return `<${href}|${text}>`;
  },
});

Also, Slack requires absolute URLs. Relative links are not allowed.