2017-02-14 13:21:45 +00:00
|
|
|
package formatter
|
|
|
|
|
2017-04-06 05:39:49 +00:00
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"io"
|
|
|
|
|
|
|
|
"github.com/x86kernel/htmlcolor"
|
|
|
|
)
|
|
|
|
|
2017-02-14 13:21:45 +00:00
|
|
|
type htmlFormatter struct {
|
|
|
|
textFormatter
|
|
|
|
}
|
|
|
|
|
2017-04-06 05:39:49 +00:00
|
|
|
func (f *htmlFormatter) Format(writer io.Writer, data []byte) error {
|
|
|
|
htmlFormatter := htmlcolor.NewFormatter()
|
|
|
|
buf := bytes.NewBuffer(make([]byte, 0, len(data)))
|
2017-04-06 06:41:46 +00:00
|
|
|
err := htmlFormatter.Format(buf, data)
|
2017-04-06 05:39:49 +00:00
|
|
|
|
2017-04-06 06:41:46 +00:00
|
|
|
if err == io.EOF {
|
|
|
|
writer.Write(buf.Bytes())
|
|
|
|
return nil
|
|
|
|
}
|
2017-04-06 05:39:49 +00:00
|
|
|
|
2017-04-06 06:41:46 +00:00
|
|
|
return errors.New("html formatter error")
|
2017-04-06 05:39:49 +00:00
|
|
|
}
|
|
|
|
|
2017-02-14 13:21:45 +00:00
|
|
|
func (f *htmlFormatter) Title() string {
|
|
|
|
return "[html]"
|
|
|
|
}
|