~chrisppy/go-barefeed

ref: e76763008dc2b1750154fb00285056605c882e40 go-barefeed/text.go -rw-r--r-- 842 bytes
e7676300Chris Palmer fix textType 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package barefeed

// TextType is an enumerated type for Text
type TextType uint

const (
	// TEXT denotes the text as plain text
	TEXT TextType = iota
	// HTML denotes the text as entity escaped html
	HTML
	// XHTML denotes the text as inline xhtml, wrapped in a div element
	XHTML
)

// Text contains info needed for any text
type Text struct {
	Value    string   `bare:"value"`
	TextType TextType `bare:"textType"`
}

// String converts the enumerated value to a string.  "TEXT" is default.
func (t TextType) String() string {
	switch t {
	case HTML:
		return "html"
	case XHTML:
		return "xhtml"
	default:
		return "text"
	}
}

// ToTextType converts a string to the enumerated value.  TEXT is default.
func ToTextType(t string) TextType {
	switch t {
	case "html":
		return HTML
	case "xhtml":
		return XHTML
	default:
		return TEXT
	}
}