Go — github.com/minjun0219/mdwire/go
A port of the Rust core, standard library only. It passes the same corpus and is checked against the Rust core on random inputs and real documents. Full reference: pkg.go.dev.
go get github.com/minjun0219/mdwire/go@latest
Render
import "github.com/minjun0219/mdwire/go"
parts := mdwire.Render(input, mdwire.TelegramHTML) // []string
Converts a finished document; over the limit it splits where no markup is open.
RenderWith
out := mdwire.RenderWith(input, mdwire.SlackMarkdown, mdwire.Options{From: mdwire.SlackMrkdwn})
out.Parts // []string
out.Repairs.ClosedEmphasis // see Repairs below
Options
The zero value is the default.
type Options struct {
From Dialect // Markdown (zero) | SlackMrkdwn
Limit int // 0 = the channel's Limit(); below MinLimit (256) is raised
HTML HTMLOptions // the HTML channel only
}
type HTMLOptions struct {
LineBreaks LineBreaks // LineBreaksBR (zero) | LineBreaksSpace
Images Images // ImagesLink (zero) | ImagesLoad
Schemes []string // nil = http, https, mailto; a list replaces the default; empty (non-nil) allows none
}
Streamer
s := mdwire.NewStreamer(mdwire.SlackMarkdown)
var out []byte
for _, chunk := range chunks {
s.PushTo(chunk, &out) // no allocation per chunk
}
s.FinishTo(&out)
NewStreamer(ch) · NewStreamerWith(ch, opts) |
One streamer per document. |
PushTo(chunk, *[]byte) · Push(chunk) string |
What is safe to send now. PushTo is the allocation-free form. |
FinishTo(*[]byte) · Finish() string |
The rest, with open markup closed. |
PreviewTo(*[]byte) · Preview() string |
The tail to append when redrawing the whole message. |
CloseOpenTo(*[]byte) · CloseOpen() string |
The tail that only closes block markup already sent. |
Revised() bool |
After Finish: does the result differ from the last preview? |
Repairs() Repairs |
What was repaired so far. |
The contract is on Concepts.
Channel and Dialect
const ( TelegramHTML Channel = iota; SlackMarkdown; Plain; GithubMarkdown; HTML; NotionMarkdown )
const ( Markdown Dialect = iota; SlackMrkdwn )
NotionMarkdown next release. The numeric values are not the order of Channels(); use names to
store or send a channel.
Channels() []Channel |
Every channel. |
(Channel) Name() string · ParseChannel(string) (Channel, bool) |
The string names. |
(Channel) Limit() int |
The part limit. |
(Dialect) Name() string · ParseDialect(string) (Dialect, bool) |
"markdown", "slack-mrkdwn". |
Repairs
type Repairs struct {
ClosedEmphasis, ClosedFence, RevertedCodeSpan, DroppedMarker int
// channel rewrites — next release
EscapedChar, TagEmphasis, StrippedHTML, RewrittenBullet, RewrittenTable, ConvertedMarker int
}
Repaired() next release — did it repair anything (the first four). Changed() next release — did it repair
or rewrite anything. What each field counts: Concepts.
Widths
CharWidth(rune) int and StrWidth(string) int — the display widths used for monospace tables.
CLI
go install github.com/minjun0219/mdwire/go/cmd/mdwire@latest installs the same CLI as the Rust one,
with the same flags except -V/--version. See CLI.