Snap for 5370966 from 12bcfa5e9b104e2fceaf6a5207af0f718b01d96a to qt-release
Change-Id: I211848c40f27672e0217eed95251fa21b526c6c7
diff --git a/bootstrap/bpdoc/bpdoc.go b/bootstrap/bpdoc/bpdoc.go
index ffb2cc0..8ce41cf 100644
--- a/bootstrap/bpdoc/bpdoc.go
+++ b/bootstrap/bpdoc/bpdoc.go
@@ -36,7 +36,7 @@
PkgPath string
// Text is the contents of the comment documenting the module type.
- Text string
+ Text template.HTML
// PropertyStructs is a list of PropertyStruct objects that contain information about each
// property struct that is used by the module type, containing all properties that are valid
diff --git a/bootstrap/bpdoc/properties.go b/bootstrap/bpdoc/properties.go
index 1126752..23b1ffd 100644
--- a/bootstrap/bpdoc/properties.go
+++ b/bootstrap/bpdoc/properties.go
@@ -224,30 +224,11 @@
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: html,
+ Text: formatText(text),
Properties: innerProps,
})
}
@@ -279,3 +260,25 @@
*props = filtered
}
+
+func formatText(text string) template.HTML {
+ 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\n"
+ preformatted = true
+ } else if !indent && line != "" && preformatted {
+ html += "</pre>\n"
+ preformatted = false
+ }
+ html += template.HTML(template.HTMLEscapeString(line)) + "\n"
+ }
+ if preformatted {
+ html += "</pre>\n"
+ }
+ return html
+}
diff --git a/bootstrap/bpdoc/reader.go b/bootstrap/bpdoc/reader.go
index 0a77844..a39ee3c 100644
--- a/bootstrap/bpdoc/reader.go
+++ b/bootstrap/bpdoc/reader.go
@@ -77,7 +77,7 @@
return &ModuleType{
Name: name,
PkgPath: pkgPath,
- Text: text,
+ Text: formatText(text),
}, nil
}
diff --git a/bootstrap/bpdoc/reader_test.go b/bootstrap/bpdoc/reader_test.go
index 8545ac6..b8ff109 100644
--- a/bootstrap/bpdoc/reader_test.go
+++ b/bootstrap/bpdoc/reader_test.go
@@ -59,7 +59,7 @@
t.Fatal(err)
}
- if mt.Text != "foo docs.\n" {
+ if mt.Text != "foo docs.\n\n" {
t.Errorf("unexpected docs %q", mt.Text)
}