feat: add Slack mrkdwn converter (to_slack/2)#366
Open
mvanhorn wants to merge 1 commit into
Open
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
MDEx.SlackConverter, a new converter that transforms a parsedMDEx.DocumentAST into Slack mrkdwn format. ExposesMDEx.to_slack/2andMDEx.to_slack!/2as 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— newMDEx.SlackConvertermodule modeled exactly onMDEx.DeltaConverter: a single publicconvert/2function acceptingMDEx.Document+ options, withconvert_node/2helpers 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_convertersescape hatch matching the Delta API.lib/mdex.ex— addsto_slack/2andto_slack!/2following the identical shape asto_delta/2/to_delta!/2: parse string, apply document pipeline, call converter, wrap errors inDecodeError.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:skipreturn value.Fixes #333