summaryrefslogtreecommitdiffstats
path: root/document.go
diff options
context:
space:
mode:
authorclsr <clsr@clsr.net>2017-08-24 17:21:03 +0200
committerclsr <clsr@clsr.net>2017-08-24 17:21:03 +0200
commit0cf5f7a9b1fcb272cd9d632bc76219edd7077c39 (patch)
tree106230b508851a313aaab30982402d25085c6378 /document.go
parent4184f047985bb28e79dd11863fe76c71865d89db (diff)
downloadcnm-go-0cf5f7a9b1fcb272cd9d632bc76219edd7077c39.tar.gz
cnm-go-0cf5f7a9b1fcb272cd9d632bc76219edd7077c39.zip
Export WriteIndent
Diffstat (limited to 'document.go')
-rw-r--r--document.go20
1 files changed, 12 insertions, 8 deletions
diff --git a/document.go b/document.go
index 5137b80..c01837c 100644
--- a/document.go
+++ b/document.go
@@ -87,15 +87,15 @@ func (doc *Document) WriteIndent(w io.Writer, n int) error {
func (doc *Document) Write(w io.Writer) error {
bw := bufio.NewWriter(w)
if doc.Title != "" {
- if err := writeIndent(bw, "title", 0); err != nil {
+ if err := WriteIndent(bw, "title", 0); err != nil {
return err
}
- if err := writeIndent(bw, Escape(doc.Title), 1); err != nil {
+ if err := WriteIndent(bw, Escape(doc.Title), 1); err != nil {
return err
}
}
if len(doc.Links) > 0 {
- if err := writeIndent(bw, "links", 0); err != nil {
+ if err := WriteIndent(bw, "links", 0); err != nil {
return err
}
for _, link := range doc.Links {
@@ -105,7 +105,7 @@ func (doc *Document) Write(w io.Writer) error {
}
}
if len(doc.Site.Children) > 0 {
- if err := writeIndent(bw, "site", 0); err != nil {
+ if err := WriteIndent(bw, "site", 0); err != nil {
return err
}
for _, site := range doc.Site.Children {
@@ -196,11 +196,11 @@ func (link Link) WriteIndent(w io.Writer, n int) error {
if link.Name != "" {
s += " " + Escape(link.Name)
}
- if err := writeIndent(w, s, n); err != nil {
+ if err := WriteIndent(w, s, n); err != nil {
return err
}
if link.Description != "" {
- if err := writeIndent(w, Escape(link.Description), n+1); err != nil {
+ if err := WriteIndent(w, Escape(link.Description), n+1); err != nil {
return err
}
}
@@ -225,7 +225,7 @@ func (site Site) WriteIndent(w io.Writer, n int) error {
if site.Name != "" {
s += " " + Escape(site.Name)
}
- if err := writeIndent(w, s, n); err != nil {
+ if err := WriteIndent(w, s, n); err != nil {
return err
}
for _, ch := range site.Children {
@@ -276,7 +276,11 @@ func parseUnknown(p *Parser, block *TokenBlock) (err error) {
return
}
-func writeIndent(w io.Writer, s string, depth int) error {
+// WriteIndent writes an indented line into a writer.
+//
+// Writes depth tab characters, the string s and a newline. If s is blank, no
+// indentation is used. s should not contain newlines.
+func WriteIndent(w io.Writer, s string, depth int) error {
const tabs = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"
if s == "" {