From 0cf5f7a9b1fcb272cd9d632bc76219edd7077c39 Mon Sep 17 00:00:00 2001 From: clsr Date: Thu, 24 Aug 2017 17:21:03 +0200 Subject: Export WriteIndent --- document.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'document.go') 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 == "" { -- cgit