full header in asciidoc formatter
This commit is contained in:
parent
315c1405e8
commit
f744089b62
1
adoc.go
1
adoc.go
|
@ -10,7 +10,6 @@ type ADoc struct {
|
||||||
Title string
|
Title string
|
||||||
Attributes map[string]string
|
Attributes map[string]string
|
||||||
Author string
|
Author string
|
||||||
Path string
|
|
||||||
Date time.Time
|
Date time.Time
|
||||||
Content []element.Element
|
Content []element.Element
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,12 @@ func AsciiDoc(doc *adoc.ADoc) string {
|
||||||
|
|
||||||
func AsciiDocHeader(doc *adoc.ADoc) string {
|
func AsciiDocHeader(doc *adoc.ADoc) string {
|
||||||
header := fmt.Sprintf("= %s\n", doc.Title)
|
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 {
|
for k, v := range doc.Attributes {
|
||||||
header += fmt.Sprintf(":%s: %s\n", k, v)
|
header += fmt.Sprintf(":%s: %s\n", k, v)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,9 @@ package format_test
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"ewintr.nl/adoc"
|
||||||
"ewintr.nl/adoc/element"
|
"ewintr.nl/adoc/element"
|
||||||
"ewintr.nl/adoc/format"
|
"ewintr.nl/adoc/format"
|
||||||
"ewintr.nl/adoc/parser"
|
"ewintr.nl/adoc/parser"
|
||||||
|
@ -23,6 +25,26 @@ With some text.
|
||||||
test.Equals(t, input, format.AsciiDoc(doc))
|
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) {
|
func TestAsciiDocFragment(t *testing.T) {
|
||||||
for _, tc := range []struct {
|
for _, tc := range []struct {
|
||||||
name string
|
name string
|
||||||
|
|
Loading…
Reference in New Issue