Playground
gnomod.toml
module = "gno.land/p/mason/md/v0" gno = "0.9" [addpkg] creator = "g1edq4dugw0sgat4zxcw9xardvuydqf6cgleuc8p"
md.gno
package md
import (
"strings"
)
type MD struct {
elements []string
}
func New() *MD {
return &MD{elements: []string{}}
}
func (m *MD) H1(text string) {
m.elements = append(m.elements, "# "+text)
}
func (m *MD) H3(text string) {
m.elements = append(m.elements, "### "+text)
}
func (m *MD) P(text string) {
m.elements = append(m.elements, text)
}
func (m *MD) Code(text string) {
m.elements = append(m.elements, " ```\n"+text+"\n```\n")
}
func (m *MD) Im(path string, caption string) {
m.elements = append(m.elements, "")
}
func (m *MD) Bullet(point string) {
m.elements = append(m.elements, "- "+point)
}
func Link(text, url string, title ...string) string {
if len(title) > 0 && title[0] != "" {
return "[" + text + "](" + url + " \"" + title[0] + "\")"
}
return "[" + text + "](" + url + ")"
}
func (m *MD) Render() string {
return strings.Join(m.elements, "\n\n")
}