github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/libkb/markup.go (about) 1 // Copyright 2015 Keybase, Inc. All rights reserved. Use of 2 // this source code is governed by the included BSD license. 3 4 package libkb 5 6 import ( 7 "bytes" 8 "fmt" 9 "io" 10 "strings" 11 ) 12 13 type Markup struct { 14 data string 15 } 16 17 func markupFrame(s string) string { 18 s = strings.TrimSpace(s) 19 if s[0] != '<' { 20 s = "<p>" + s + "</p>" 21 } 22 return s 23 } 24 25 func NewMarkup(s string) *Markup { 26 return &Markup{markupFrame(s)} 27 } 28 29 func FmtMarkup(f string, args ...interface{}) *Markup { 30 return &Markup{data: markupFrame(fmt.Sprintf(f, args...))} 31 } 32 33 func (m Markup) ToReader() io.Reader { 34 return bytes.NewBufferString(m.data) 35 } 36 37 func (m *Markup) Append(s string) { 38 m.data += s 39 } 40 41 func (m Markup) GetRaw() string { return m.data }