Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

/p/nt/mdalert/v0

Directory · 5 Files
README.md Open

v0 - Unaudited This is an initial version of this package that has not yet been formally audited. A fully audited version will be published as a subsequent release. Use in production at your own risk.

mdalert - Markdown alerts

Render gnoweb-flavored Markdown alert blocks (note, tip, info, success, warning, caution) with optional title and folded mode.

Usage

 1import "gno.land/p/nt/mdalert/v0"
 2
 3// One-liner helpers per type
 4md := mdalert.Warning("Heads up", "Disk almost full")
 5
 6// Formatted variants accept ufmt-style args
 7md = mdalert.Infof("Stats", "%d users online", n)
 8
 9// Full control via the Alert struct (e.g. folded by default)
10a := mdalert.New(mdalert.TypeTip, "Click to expand", "Hidden details here", true)
11md = a.String()

Rendered output (for the warning above):

> [!WARNING] Heads up
> Disk almost full

API

 1// Type identifies an alert variant.
 2type Type string
 3
 4const (
 5    TypeCaution Type = "CAUTION"
 6    TypeInfo         = "INFO"
 7    TypeNote         = "NOTE"
 8    TypeSuccess      = "SUCCESS"
 9    TypeTip          = "TIP"
10    TypeWarning      = "WARNING"
11)
12
13// Alert is a Markdown alert block.
14type Alert struct {
15    Type    Type   // Alert variant
16    Title   string // Optional title (header line)
17    Message string // Body; may contain newlines
18    Folded  bool   // If true, render collapsed (only title visible)
19}
20
21// String renders the alert as Markdown. Returns "" if Type is empty or Message is blank (whitespace only).
22func (a Alert) String() string
23
24// New builds an Alert.
25func New(t Type, title, msg string, folded bool) Alert
26
27// Per-type helpers (unfolded). The *f variants format msg with ufmt.Sprintf.
28func Caution(title, msg string) string
29func Cautionf(title, format string, a ...any) string
30func Info(title, msg string) string
31func Infof(title, format string, a ...any) string
32func Note(title, msg string) string
33func Notef(title, format string, a ...any) string
34func Success(title, msg string) string
35func Successf(title, format string, a ...any) string
36func Tip(title, msg string) string
37func Tipf(title, format string, a ...any) string
38func Warning(title, msg string) string
39func Warningf(title, format string, a ...any) string

Notes

  • Alert types are documented in the Markdown docs realm: /r/docs/markdown#alerts.
  • Per-type helpers always render unfolded. For folded alerts use New(...) with folded=true.
  • title and msg are emitted into Markdown as-is. When either carries untrusted input (a Render(path) segment, user text), wrap it with sanitize.InlineText from gno.land/p/nt/markdown/sanitize/v0 first, or it can inject structure into the rendered page. The *f variants format via ufmt.Sprintf, which supports only ufmt's verb subset (no %b, %o, %w, %+v).