1package md23import (4 "strings"56 "gno.land/p/nt/ufmt/v0"7)89// Builder helps to build a Markdown string from individual elements10type Builder struct {11 elements []string12}1314// NewBuilder creates a new Builder instance15func NewBuilder() *Builder {16 return &Builder{}17}1819// Add adds a Markdown element to the builder20func (m *Builder) Add(md ...string) *Builder {21 m.elements = append(m.elements, md...)22 return m23}2425// Render returns the final Markdown string joined with the specified separator26func (m *Builder) Render(separator string) string {27 return strings.Join(m.elements, separator)28}2930// Bold returns bold text for markdown31func Bold(text string) string {32 return ufmt.Sprintf("**%s**", text)33}3435// Italic returns italicized text for markdown36func Italic(text string) string {37 return ufmt.Sprintf("*%s*", text)38}3940// Strikethrough returns strikethrough text for markdown41func Strikethrough(text string) string {42 return ufmt.Sprintf("~~%s~~", text)43}4445// H1 returns a level 1 header for markdown46func H1(text string) string {47 return ufmt.Sprintf("# %s\n", text)48}4950// H2 returns a level 2 header for markdown51func H2(text string) string {52 return ufmt.Sprintf("## %s\n", text)53}5455// H3 returns a level 3 header for markdown56func H3(text string) string {57 return ufmt.Sprintf("### %s\n", text)58}5960// H4 returns a level 4 header for markdown61func H4(text string) string {62 return ufmt.Sprintf("#### %s\n", text)63}6465// H5 returns a level 5 header for markdown66func H5(text string) string {67 return ufmt.Sprintf("##### %s\n", text)68}6970// H6 returns a level 6 header for markdown71func H6(text string) string {72 return ufmt.Sprintf("###### %s\n", text)73}7475// BulletList returns an bullet list for markdown76func BulletList(items []string) string {77 var sb strings.Builder78 for _, item := range items {79 sb.WriteString(ufmt.Sprintf("- %s\n", item))80 }81 return sb.String()82}8384// OrderedList returns an ordered list for markdown85func OrderedList(items []string) string {86 var sb strings.Builder87 for i, item := range items {88 sb.WriteString(ufmt.Sprintf("%d. %s\n", i+1, item))89 }90 return sb.String()91}9293// TodoList returns a list of todo items with checkboxes for markdown94func TodoList(items []string, done []bool) string {95 var sb strings.Builder9697 for i, item := range items {98 checkbox := " "99 if done[i] {100 checkbox = "x"101 }102 sb.WriteString(ufmt.Sprintf("- [%s] %s\n", checkbox, item))103 }104 return sb.String()105}106107// Blockquote returns a blockquote for markdown108func Blockquote(text string) string {109 lines := strings.Split(text, "\n")110 var sb strings.Builder111 for _, line := range lines {112 sb.WriteString(ufmt.Sprintf("> %s\n", line))113 }114115 return sb.String()116}117118// InlineCode returns inline code for markdown119func InlineCode(code string) string {120 return ufmt.Sprintf("`%s`", code)121}122123// CodeBlock creates a markdown code block124func CodeBlock(content string) string {125 return ufmt.Sprintf("```\n%s\n```", content)126}127128// LanguageCodeBlock creates a markdown code block with language-specific syntax highlighting129func LanguageCodeBlock(language, content string) string {130 return ufmt.Sprintf("```%s\n%s\n```", language, content)131}132133// LineBreak returns the specified number of line breaks for markdown134func LineBreak(count uint) string {135 if count > 0 {136 return strings.Repeat("\n", int(count)+1)137 }138 return ""139}140141// HorizontalRule returns a horizontal rule for markdown142func HorizontalRule() string {143 return "---\n"144}145146// Link returns a hyperlink for markdown147func Link(text, url string) string {148 return ufmt.Sprintf("[%s](%s)", text, url)149}150151// Image returns an image for markdown152func Image(altText, url string) string {153 return ufmt.Sprintf("", altText, url)154}155156// Footnote returns a footnote for markdown157func Footnote(reference, text string) string {158 return ufmt.Sprintf("[%s]: %s", reference, text)159}160161// Paragraph wraps the given text in a Markdown paragraph162func Paragraph(content string) string {163 return ufmt.Sprintf("%s\n", content)164}165166// MdTable is an interface for table types that can be converted to Markdown format167type MdTable interface {168 String() string169}170171// Table takes any MdTable implementation and returns its markdown representation172func Table(table MdTable) string {173 return table.String()174}175176// EscapeMarkdown escapes special markdown characters in a string177func EscapeMarkdown(text string) string {178 return ufmt.Sprintf("``%s``", text)179}180Signatures reconstructed verbatim from vm/qfuncs — interface params keep their inline definitions.