GFM -> Discord markdown conversion and 2000-character message chunking.
Discord renders a subset of markdown: #/##/### headings, **bold**,
*italic*, __underline__, ~~strike~~, `code`, fenced code blocks,
> quotes and lists — but no tables, HTML or deeper headings. In message
content, masked links unfurl previews, so links are rewritten to
text (<url>) (angle brackets suppress the embed preview).
from_markdown/2 rules
- Fenced code blocks and inline code are passed through untouched.
#,##,###kept;####+ become a**bold**line.- GFM
__bold__becomes**bold**(Discord's__is underline). - Links: target
:content(default) ->text (<url>)(or<url>when the text is the url); withunfurl: true->text (url). Target:embedkeeps[text](url)(embeds render masked links without previews). - Images
are treated as links (alt text, or the url). - Tables are wrapped in a fenced code block.
- HTML tags and comments are stripped (
<br>-> newline);<https://…>autolinks survive;& < > " ' are decoded. - Task list items become
☐/☑; thematic breaks (---) become───. - Runs of 3+ newlines collapse to a blank line.
Opts: :target (:content | :embed), :unfurl (boolean).
Summary
Functions
Splits text into chunks of at most limit characters (default 2000, Discord's
message content limit), preferring paragraph boundaries, then line breaks, then
spaces. Fenced code blocks that must be split are closed and re-opened (with the
same info string) in each chunk.
Converts GitHub-flavoured markdown to Discord's markdown subset. See module doc.
Functions
@spec chunk(String.t(), pos_integer()) :: [String.t()]
Splits text into chunks of at most limit characters (default 2000, Discord's
message content limit), preferring paragraph boundaries, then line breaks, then
spaces. Fenced code blocks that must be split are closed and re-opened (with the
same info string) in each chunk.
Converts GitHub-flavoured markdown to Discord's markdown subset. See module doc.