-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathbbcode.go
More file actions
42 lines (37 loc) · 747 Bytes
/
bbcode.go
File metadata and controls
42 lines (37 loc) · 747 Bytes
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
// Copyright 2015 Frustra. All rights reserved.
// Use of this source code is governed by the MIT
// license that can be found in the LICENSE file.
// Package bbcode implements a parser and HTML generator for BBCode.
package bbcode
import "sort"
type BBOpeningTag struct {
Name string
Value string
Args map[string]string
Raw string
}
type BBClosingTag struct {
Name string
Raw string
}
func (t *BBOpeningTag) String() string {
str := t.Name
if len(t.Value) > 0 {
str += "=" + t.Value
}
keys := make([]string, len(t.Args))
i := 0
for key := range t.Args {
keys[i] = key
i++
}
sort.Strings(keys)
for _, key := range keys {
v := t.Args[key]
str += " " + key
if len(v) > 0 {
str += "=" + v
}
}
return str
}