adoc/formatter/text.go

30 lines
490 B
Go
Raw Normal View History

2022-06-11 09:30:22 +02:00
package formatter
import (
"fmt"
2024-09-15 12:07:22 +02:00
"go-mod.ewintr.nl/adoc/document"
"go-mod.ewintr.nl/adoc/element"
2022-06-11 09:30:22 +02:00
)
type Text struct{}
func NewText() *Text {
return &Text{}
}
func (t *Text) Format(doc *document.Document) string {
txt := fmt.Sprintf("%s\n\n", doc.Title)
txt += t.FormatFragments(doc.Content...)
return txt
}
func (t *Text) FormatFragments(els ...element.Element) string {
var text string
for _, el := range els {
text += fmt.Sprintf("%s\n\n", el.Text())
}
return text
}