slackmd

package
v1.15.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 7, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package slackmd decides when outbound Slack text should travel as a Block Kit `markdown` block instead of plain mrkdwn, and prepares it for that.

Slack's mrkdwn cannot render pipe tables, `#` headings, `**bold**`, `[label](url)` links, nested lists or fenced code the way markdown does. The `markdown` block can — Slack renders real tables (with copy/download) from it. Text that uses none of those constructs keeps the plain path, so ordinary replies look exactly as before.

Main functions:

  • NeedsBlock — true when text carries markdown mrkdwn would garble
  • Chunks — split text under the block limit without cutting a table row or a fenced block in half
  • Fallback — short plain version for the message's top-level `text` (notifications, clients that cannot render blocks)

Pure and dependency-free so both the Slack channel and the Slack connector can share it.

Index

Constants

View Source
const MaxBlockChars = 12000

MaxBlockChars is Slack's cumulative limit for markdown block text in one message. Counted in bytes here, which is never more than the character count Slack enforces, so a chunk that fits by bytes always fits.

Variables

This section is empty.

Functions

func Chunks

func Chunks(text string, max int) []string

Chunks splits text into pieces of at most max bytes. Cuts fall between paragraphs, tables and fenced blocks first. A single table larger than max is split between rows with its header repeated, a fenced block is closed and reopened, and only a single line longer than max is cut mid-line.

func Fallback

func Fallback(text string) string

Fallback returns a short plain version of markdown text for the message's top-level `text` field: table separators and fences dropped, heading and bold markers removed, links reduced to their label, whitespace collapsed and the result clipped to a preview length.

func NeedsBlock

func NeedsBlock(text string) bool

NeedsBlock reports whether text uses markdown that Slack mrkdwn cannot render: a pipe table, a heading, **bold**, a [label](url) link, a nested list or a fenced code block.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL