most basic text formatter
This commit is contained in:
parent
d2b00c93e1
commit
e098f4bcf7
|
@ -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
|
||||
}
|
|
@ -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))
|
||||
}
|
Loading…
Reference in New Issue