From 0cf5f7a9b1fcb272cd9d632bc76219edd7077c39 Mon Sep 17 00:00:00 2001 From: clsr Date: Thu, 24 Aug 2017 17:21:03 +0200 Subject: Export WriteIndent --- cnmfmt/cnmfmt.go | 27 ++------------------------- 1 file changed, 2 insertions(+), 25 deletions(-) (limited to 'cnmfmt/cnmfmt.go') diff --git a/cnmfmt/cnmfmt.go b/cnmfmt/cnmfmt.go index cb8dc64..fa2ec65 100644 --- a/cnmfmt/cnmfmt.go +++ b/cnmfmt/cnmfmt.go @@ -199,7 +199,7 @@ func (t Text) WriteIndent(w io.Writer, n int) error { si = cleanupTags(state[:], order, span.Format) format = span.Format } - return writeIndent(w, strings.Join(line, ""), n) + return cnm.WriteIndent(w, strings.Join(line, ""), n) } func tagOrder(state []byte, old, new Format) []byte { @@ -430,7 +430,7 @@ func NewTextFmtBlock(paragraphs []Text) *cnm.TextBlock { func (tf TextFmtContents) WriteIndent(w io.Writer, n int) error { for i, p := range tf.Paragraphs { if i != 0 { - if err := writeIndent(w, "", 0); err != nil { + if err := cnm.WriteIndent(w, "", 0); err != nil { return err } } @@ -469,29 +469,6 @@ func Parse(paragraphs string) []Text { return txt } -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 == "" { - _, err := w.Write([]byte{'\n'}) - return err - } - if depth == 0 { - _, err := w.Write([]byte(s + "\n")) - return err - } - - var ind string - if depth <= len(tabs) { - ind = tabs[:depth] - } else { - ind = strings.Repeat("\t", depth) - } - _, err := w.Write([]byte(ind + s + "\n")) - return err - -} - func parseTextFmt(p *cnm.Parser, block *cnm.TokenBlock) (cnm.TextContents, error) { txt := TextFmtContents{} var paragraph []string -- cgit