diff --git a/pkg/docgen/docgen.go b/pkg/docgen/docgen.go index c35fb42..24d98d4 100644 --- a/pkg/docgen/docgen.go +++ b/pkg/docgen/docgen.go @@ -213,6 +213,10 @@ func getTypeDocs(generic *ast.GenDecl, trimSpace bool) string { if trimSpace { newLine = strings.TrimSpace(newLine) } + if strings.HasPrefix(strings.TrimSpace(newLine), "/*") { + newLine = strings.TrimPrefix(newLine, "/*") + newLine = strings.TrimSuffix(newLine, "*/") + } if !strings.HasPrefix(strings.TrimSpace(newLine), "+kubebuilder") && !strings.HasPrefix(strings.TrimSpace(newLine), "nolint") && !strings.HasPrefix(strings.TrimSpace(newLine), "+docName") { diff --git a/pkg/docgen/docgen_test.go b/pkg/docgen/docgen_test.go index 6a91b41..dad9d19 100644 --- a/pkg/docgen/docgen_test.go +++ b/pkg/docgen/docgen_test.go @@ -54,6 +54,8 @@ func TestGenParse(t *testing.T) { ### field1 (string, optional) {#sample-field1} Default: - + + `), }, { @@ -71,6 +73,8 @@ func TestGenParse(t *testing.T) { ### field1 (string, optional) {#sampledefault-field1} Default: testval + + `), }, { @@ -87,15 +91,48 @@ func TestGenParse(t *testing.T) { ### field1 (string, optional) {#sample-field1} - Description + Description {{< highlight yaml >}} test: code block some: more lines - indented: line + indented: line {{< /highlight >}} Default: - + + + `), + }, + { + docItem: docgen.DocItem{ + Name: "sample-codeblock-blockcomment", + SourcePath: filepath.Join(currentDir, "testdata", "sample_codeblock_blockcomment.go"), + DestPath: filepath.Join(currentDir, "../../build/_test/docgen"), + DefaultValueFromTagExtractor: func(tag string) string { + return docgen.GetPrefixedValue(tag, `asd:\"default:(.*)\"`) + }, + }, + expected: heredoc.Doc(` + ## Sample + + Description + + {{< highlight yaml >}} + test: code block + some: more lines + indented: line + indented: line + + indented: line + {{< /highlight >}} + + + ### field1 (string, optional) {#sample-field1} + + Default: - + + `), }, } @@ -112,7 +149,7 @@ func TestGenParse(t *testing.T) { t.Fatalf("%+v", err) } - if a, e := diff.TrimLinesInString(string(bytes)), diff.TrimLinesInString(item.expected); a != e { + if a, e := string(bytes), item.expected; a != e { t.Errorf("Result does not match (-actual vs +expected):\n%v\nActual: %s", diff.LineDiff(a, e), string(bytes)) } } diff --git a/pkg/docgen/testdata/sample_codeblock_blockcomment.go b/pkg/docgen/testdata/sample_codeblock_blockcomment.go new file mode 100644 index 0000000..14f34f3 --- /dev/null +++ b/pkg/docgen/testdata/sample_codeblock_blockcomment.go @@ -0,0 +1,30 @@ +// Copyright © 2020 Banzai Cloud +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package testdata + +// Description +/* +{{< highlight yaml >}} +test: code block +some: more lines + indented: line + indented: line + + indented: line +{{< /highlight >}} +*/ +type Sample struct { + Field1 string `json:"field1,omitempty"` +}