Skip to content

Commit

Permalink
chore: update code block output variable (#529)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackton1 authored Jan 4, 2024
1 parent 6c89b85 commit 116e612
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions internal/types/code_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (c *CodeBlock) GetData() error {
}

// writeDocumentation write the table to the output file
func (c *CodeBlock) writeDocumentation(inputCodeBlock, outputCodeBlock *strings.Builder) error {
func (c *CodeBlock) writeDocumentation(inputCodeBlock, outputTableOutput *strings.Builder) error {
var err error
input, err := os.ReadFile(c.OutputFileName)
// coverage:ignore
Expand Down Expand Up @@ -101,16 +101,16 @@ func (c *CodeBlock) writeDocumentation(inputCodeBlock, outputCodeBlock *strings.
[]byte(internal.OutputAutoDocEnd),
)

outputCodeBlockStr := strings.TrimSpace(outputCodeBlock.String())
outputTableOutputStr := strings.TrimSpace(outputTableOutput.String())

if hasOutputsData {
output = utils.ReplaceBytesInBetween(output, indices, []byte(outputCodeBlockStr))
output = utils.ReplaceBytesInBetween(output, indices, []byte(outputTableOutputStr))
} else {
re := regexp.MustCompile(fmt.Sprintf("(?m)^%s", internal.OutputsHeader))
output = re.ReplaceAllFunc(output, func(match []byte) []byte {
if bytes.HasPrefix(match, []byte(internal.OutputsHeader)) {
if outputCodeBlockStr != "" {
return []byte(fmt.Sprintf("%s\n\n%v", internal.OutputsHeader, outputCodeBlockStr))
if outputTableOutputStr != "" {
return []byte(fmt.Sprintf("%s\n\n%v", internal.OutputsHeader, outputTableOutputStr))
} else {
return []byte(internal.OutputsHeader)
}
Expand Down

0 comments on commit 116e612

Please sign in to comment.