package wiki
import (
"strings"
ice "shylinux.com/x/icebergs"
"shylinux.com/x/icebergs/base/nfs"
"shylinux.com/x/icebergs/base/ssh"
kit "shylinux.com/x/toolkits"
)
func _spark_show(m *ice.Message, name, text string, arg ...string) *ice.Message {
if _option(m, m.CommandKey(), name, text, arg...); name == "" {
return _wiki_template(m, name, text, arg...)
}
m.Echo(`
`, arg[0])}
for _, l := range kit.SplitLine(strings.Join(arg[1:], ice.NL)) {
list = append(list, "
", Format("label", kit.Select("> ", "$ ", arg[0] == SHELL)), Format("span", l), "
")
}
return strings.Join(append(list, "
"), "")
})
}},
"md": {Name: "md file", Help: "md", Hand: func(m *ice.Message, arg ...string) {
block, code := "", []string{}
text := func() {
if len(code) > 0 {
m.Cmdy(SPARK, kit.Join(code, ice.NL))
code = []string{}
}
}
m.Cmd(nfs.CAT, m.Option(nfs.FILE), func(line string) {
for _, ls := range [][]string{
[]string{"# ", TITLE}, []string{"## ", TITLE, CHAPTER}, []string{"### ", TITLE, SECTION},
} {
if strings.HasPrefix(line, ls[0]) {
text()
m.Cmdy(ls[1:], strings.TrimPrefix(line, ls[0]))
return
}
}
if strings.HasPrefix(line, "```") {
if block == "" {
text()
block = "```"
} else {
m.Cmdy(SPARK, SHELL, kit.Join(code, ice.NL))
block, code = "", []string{}
}
return
}
code = append(code, line)
})
text()
}},
}, WordAction(`