Skip to content

feat: add Slack mrkdwn converter (to_slack/2)#366

Open
mvanhorn wants to merge 1 commit into
leandrocp:mainfrom
mvanhorn:feat/333-slack-converter
Open

feat: add Slack mrkdwn converter (to_slack/2)#366
mvanhorn wants to merge 1 commit into
leandrocp:mainfrom
mvanhorn:feat/333-slack-converter

Conversation

@mvanhorn

Copy link
Copy Markdown

Summary

Adds MDEx.SlackConverter, a new converter that transforms a parsed MDEx.Document AST into Slack mrkdwn format. Exposes MDEx.to_slack/2 and MDEx.to_slack!/2 as the public API entry points.

Why this matters

Closes #333 — Elixir applications that pipe LLM-generated Markdown to Slack's API need a safe conversion layer. CommonMark doesn't map directly to Slack mrkdwn: bold is *text*, italic is _text_, links are <url|label>, headings become bold text, and code blocks must drop the language tag. Without this converter, apps either strip all formatting or send raw Markdown that Slack renders incorrectly or rejects.

Changes

  • lib/mdex/slack_converter.ex — new MDEx.SlackConverter module modeled exactly on MDEx.DeltaConverter: a single public convert/2 function accepting MDEx.Document + options, with convert_node/2 helpers covering bold (*), italic (_), inline code (`), fenced code blocks (triple backtick, no language tag), links (<url|label>), strikethrough (~), headings as bold, blockquotes (> ), bullet lists (- ), ordered lists (1. ), and a :custom_converters escape hatch matching the Delta API.
  • lib/mdex.ex — adds to_slack/2 and to_slack!/2 following the identical shape as to_delta/2/to_delta!/2: parse string, apply document pipeline, call converter, wrap errors in DecodeError.
  • test/mdex/slack_converter_test.exs — ExUnit tests covering each node type, nested formatting, both public API functions (to_slack/2, to_slack!/2), custom converter override, and :skip return value.

Fixes #333

Adds MDEx.SlackConverter which converts an MDEx.Document AST to Slack
mrkdwn format, following the DeltaConverter pattern. Wires to_slack/2
and to_slack!/2 into MDEx, with support for custom_converters.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement markdown -> slack mkdwn translation

1 participant