most basic text formatter

This commit is contained in:
Erik Winter 2022-03-17 16:20:59 +01:00
parent d2b00c93e1
commit e098f4bcf7
2 changed files with 44 additions and 0 deletions

16
format/text.go Normal file
View File

@ -0,0 +1,16 @@
package format
import (
"fmt"
"ewintr.nl/adoc"
)
func Text(doc *adoc.ADoc) string {
txt := fmt.Sprintf("%s\n\n", doc.Title)
for _, el := range doc.Content {
txt += fmt.Sprintf("%s\n\n", el.Text())
}
return txt
}

28
format/text_test.go Normal file
View File

@ -0,0 +1,28 @@
package format_test
import (
"strings"
"testing"
"ewintr.nl/adoc/format"
"ewintr.nl/adoc/parser"
"ewintr.nl/go-kit/test"
)
func TestText(t *testing.T) {
input := `= A Title
Some Document
With some text`
exp := `A Title
Some Document
With some text
`
doc := parser.New(strings.NewReader(input)).Parse()
test.Equals(t, exp, format.Text(doc))
}