diff options
author | Jaewoong Jung <jungjw@google.com> | 2019-03-11 14:34:11 -0700 |
---|---|---|
committer | Jaewoong Jung <jungjw@google.com> | 2019-03-11 14:34:29 -0700 |
commit | 40d8c975c74b2fc75b8ead07e9b1bff2e3adab1d (patch) | |
tree | b95e3ce4ddcfbfca070b4b78acceafd1e52e3fe5 | |
parent | 8610dfd44168b5dc5236e96440713fcc021cf6d3 (diff) | |
parent | 08ab48903b574accf1d598c259bf708428873247 (diff) | |
download | android_build_blueprint-40d8c975c74b2fc75b8ead07e9b1bff2e3adab1d.tar.gz android_build_blueprint-40d8c975c74b2fc75b8ead07e9b1bff2e3adab1d.tar.bz2 android_build_blueprint-40d8c975c74b2fc75b8ead07e9b1bff2e3adab1d.zip |
Merge remote-tracking branch 'aosp/upstream' into merge
* aosp/upstream:
bpdoc preformatted text improvments
Fixes: 124332708
Test: m soong_docs
Change-Id: I444e4c806d3c44e31d0242e18cc2b6a4ed224ee0
-rw-r--r-- | bootstrap/bpdoc/bpdoc.go | 2 | ||||
-rw-r--r-- | bootstrap/bpdoc/properties.go | 43 | ||||
-rw-r--r-- | bootstrap/bpdoc/reader.go | 2 | ||||
-rw-r--r-- | bootstrap/bpdoc/reader_test.go | 2 |
4 files changed, 26 insertions, 23 deletions
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 @@ type ModuleType struct { 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 @@ func structProperties(structType *ast.StructType) (props []Property, err error) 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 @@ func filterPropsByTag(props *[]Property, key, value string, exclude bool) { *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 @@ func (r *Reader) ModuleType(name string, factory reflect.Value) (*ModuleType, er 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 @@ func TestModuleTypeDocs(t *testing.T) { t.Fatal(err) } - if mt.Text != "foo docs.\n" { + if mt.Text != "foo docs.\n\n" { t.Errorf("unexpected docs %q", mt.Text) } |