shitty-ssg/pkg/adoc/block.go

56 lines
910 B
Go
Raw Normal View History

package adoc
2020-12-04 12:50:20 +01:00
import (
"fmt"
"strings"
)
type BlockElement interface {
Text() 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, " ")
}
type SubTitle string
func (st SubTitle) Text() string { return string(st) }
type SubSubTitle string
func (st SubSubTitle) Text() string { return string(st) }
type CodeBlock string
func (cb CodeBlock) Text() string { return 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, ""))
2020-12-04 12:50:20 +01:00
}
type List []ListItem
func (l List) Text() string {
var items []string
for _, item := range l {
items = append(items, item.Text())
}
return strings.Join(items, "\n")
}