Search Apps Documentation Source Content File Folder Download Copy Actions Download

md.gno

0.91 Kb ยท 48 lines
 1package md
 2
 3import (
 4	"strings"
 5)
 6
 7type MD struct {
 8	elements []string
 9}
10
11func New() *MD {
12	return &MD{elements: []string{}}
13}
14
15func (m *MD) H1(text string) {
16	m.elements = append(m.elements, "# "+text)
17}
18
19func (m *MD) H3(text string) {
20	m.elements = append(m.elements, "### "+text)
21}
22
23func (m *MD) P(text string) {
24	m.elements = append(m.elements, text)
25}
26
27func (m *MD) Code(text string) {
28	m.elements = append(m.elements, "  ```\n"+text+"\n```\n")
29}
30
31func (m *MD) Im(path string, caption string) {
32	m.elements = append(m.elements, "!["+caption+"]("+path+" \""+caption+"\")")
33}
34
35func (m *MD) Bullet(point string) {
36	m.elements = append(m.elements, "- "+point)
37}
38
39func Link(text, url string, title ...string) string {
40	if len(title) > 0 && title[0] != "" {
41		return "[" + text + "](" + url + " \"" + title[0] + "\")"
42	}
43	return "[" + text + "](" + url + ")"
44}
45
46func (m *MD) Render() string {
47	return strings.Join(m.elements, "\n\n")
48}