diff --git a/adoc.go b/adoc.go index 8e65a2a..2551f3d 100644 --- a/adoc.go +++ b/adoc.go @@ -10,7 +10,6 @@ type ADoc struct { Title string Attributes map[string]string Author string - Path string Date time.Time Content []element.Element } diff --git a/format/asciidoc.go b/format/asciidoc.go index aa2ff79..0175f15 100644 --- a/format/asciidoc.go +++ b/format/asciidoc.go @@ -13,6 +13,12 @@ func AsciiDoc(doc *adoc.ADoc) string { func AsciiDocHeader(doc *adoc.ADoc) string { header := fmt.Sprintf("= %s\n", doc.Title) + if doc.Author != "" { + header += fmt.Sprintf("%s\n", doc.Author) + } + if !doc.Date.IsZero() { + header += fmt.Sprintf("%s\n", doc.Date.Format("2006-01-02")) + } for k, v := range doc.Attributes { header += fmt.Sprintf(":%s: %s\n", k, v) } diff --git a/format/asciidoc_test.go b/format/asciidoc_test.go index aad1e47..c425038 100644 --- a/format/asciidoc_test.go +++ b/format/asciidoc_test.go @@ -3,7 +3,9 @@ package format_test import ( "strings" "testing" + "time" + "ewintr.nl/adoc" "ewintr.nl/adoc/element" "ewintr.nl/adoc/format" "ewintr.nl/adoc/parser" @@ -23,6 +25,26 @@ With some text. test.Equals(t, input, format.AsciiDoc(doc)) } +func TestAsciiDocHeader(t *testing.T) { + input := &adoc.ADoc{ + Title: "title", + Author: "author", + Date: time.Date(2022, time.Month(6), 11, 12, 0, 0, 0, time.UTC), + Attributes: map[string]string{ + "key1": "value 1", + "key2": "value 2", + }, + } + exp := `= title +author +2022-06-11 +:key1: value 1 +:key2: value 2 +` + + test.Equals(t, exp, format.AsciiDocHeader(input)) +} + func TestAsciiDocFragment(t *testing.T) { for _, tc := range []struct { name string