Merge pull request #177 from colincross/docs
Fix property documentation bugs
diff --git a/bootstrap/bpdoc/bpdoc.go b/bootstrap/bpdoc/bpdoc.go
index 608cfac..cfbffba 100644
--- a/bootstrap/bpdoc/bpdoc.go
+++ b/bootstrap/bpdoc/bpdoc.go
@@ -7,13 +7,15 @@
"go/doc"
"go/parser"
"go/token"
+ "html/template"
"io/ioutil"
"reflect"
"sort"
"strconv"
"strings"
"sync"
- "text/template"
+ "unicode"
+ "unicode/utf8"
"github.com/google/blueprint"
"github.com/google/blueprint/proptools"
@@ -101,8 +103,8 @@
OtherNames []string
Type string
Tag reflect.StructTag
- Text string
- OtherTexts []string
+ Text template.HTML
+ OtherTexts []template.HTML
Properties []Property
Default string
}
@@ -131,7 +133,7 @@
return p.Name == other.Name && p.Type == other.Type && p.Tag == other.Tag &&
p.Text == other.Text && p.Default == other.Default &&
stringArrayEqual(p.OtherNames, other.OtherNames) &&
- stringArrayEqual(p.OtherTexts, other.OtherTexts) &&
+ htmlArrayEqual(p.OtherTexts, other.OtherTexts) &&
p.SameSubProperties(other)
}
@@ -185,6 +187,20 @@
return true
}
+func htmlArrayEqual(a, b []template.HTML) bool {
+ if len(a) != len(b) {
+ return false
+ }
+
+ for i := range a {
+ if a[i] != b[i] {
+ return false
+ }
+ }
+
+ return true
+}
+
func (p *Property) SameSubProperties(other Property) bool {
if len(p.Properties) != len(other.Properties) {
return false
@@ -287,11 +303,30 @@
typ = fmt.Sprintf("%T", f.Type)
}
+ var html template.HTML
+
+ lines := strings.Split(text, "\n")
+ preformatted := false
+ for _, line := range lines {
+ r, _ := utf8.DecodeRuneInString(line)
+ indent := unicode.IsSpace(r)
+ if indent && !preformatted {
+ html += "<pre>\n"
+ } else if !indent && preformatted {
+ html += "</pre>\n"
+ }
+ preformatted = indent
+ html += template.HTML(template.HTMLEscapeString(line)) + "\n"
+ }
+ if preformatted {
+ html += "</pre>\n"
+ }
+
props = append(props, Property{
Name: name,
Type: typ,
Tag: reflect.StructTag(tag),
- Text: text,
+ Text: html,
Properties: innerProps,
})
}