package site import ( "fmt" "html" "strings" ) type BlockElement interface { Text() string BlockHTML() string } type Paragraph []InlineElement func (p Paragraph) Text() string { var text []string for _, ie := range p { text = append(text, ie.Text()) } return strings.Join(text, " ") } func (p Paragraph) BlockHTML() string { var body string for _, ie := range p { body += ie.InlineHTML() } return fmt.Sprintf("
%s
", body) } type SubTitle string func (st SubTitle) Text() string { return string(st) } func (st SubTitle) BlockHTML() string { return fmt.Sprintf("%s
", html.EscapeString(string(cb)))
}
type ListItem []InlineElement
func (li ListItem) Text() string {
var text []string
for _, ie := range li {
text = append(text, ie.Text())
}
return fmt.Sprintf("%s%s", LISTITEM_PREFIX, strings.Join(text, " "))
}
func (li ListItem) HTML() string {
var body string
for _, ie := range li {
body += ie.InlineHTML()
}
return fmt.Sprintf("