From e098f4bcf79306c136a8ec2ef6773984c1341cf8 Mon Sep 17 00:00:00 2001 From: Erik Winter Date: Thu, 17 Mar 2022 16:20:59 +0100 Subject: [PATCH] most basic text formatter --- format/text.go | 16 ++++++++++++++++ format/text_test.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 format/text.go create mode 100644 format/text_test.go diff --git a/format/text.go b/format/text.go new file mode 100644 index 0000000..2c59c8e --- /dev/null +++ b/format/text.go @@ -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 +} diff --git a/format/text_test.go b/format/text_test.go new file mode 100644 index 0000000..4aa64f5 --- /dev/null +++ b/format/text_test.go @@ -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)) +}