Skip to content

Commit

Permalink
fix: Adapt logic for formatting comments for the documentation so has…
Browse files Browse the repository at this point in the history
…h symbols can still be used for anchor links

This fixes #10. The logic before removed all hash symbols, which will cause broken anchor links in the Markdown documentation.
  • Loading branch information
erNail authored Jun 10, 2024
1 parent 9485e7b commit afdf01f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
3 changes: 1 addition & 2 deletions internal/yamlutils/yaml_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,10 @@ func RemoveYamlDocumentSeparators(yamlContent []byte) []byte {
// Returns:
// - string: The cleaned comment string.
func FormatCommentAsPlainText(comment string) string {
comment = strings.ReplaceAll(comment, "#", "")
lines := strings.Split(comment, "\n")

for i, line := range lines {
lines[i] = strings.TrimSpace(line)
lines[i] = strings.TrimSpace(strings.TrimPrefix(line, "#"))
}

cleanedComment := strings.Join(lines, "\n")
Expand Down
13 changes: 13 additions & 0 deletions internal/yamlutils/yaml_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,19 @@ func TestFormatCommentAsPlainTextFormatsMultiLineComment(t *testing.T) {
assert.Equal(t, expectedFormattedComment, actualFormattedComment)
}

func TestFormatCommentAsPlainTextOnlyRemovesHashSymbolInTheBeginning(t *testing.T) {
t.Parallel()

multilineComment := `# This is a comment with a # in it
# This is a comment with an [anchor link](#anchor) in it`

expectedFormattedComment := "This is a comment with a # in it\nThis is a comment with an [anchor link](#anchor) in it"

actualFormattedComment := FormatCommentAsPlainText(multilineComment)

assert.Equal(t, expectedFormattedComment, actualFormattedComment)
}

func TestReadYamlFilesFromDirectoryWithNoYamlFilesReturnsNoYamlFiles(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit afdf01f

Please sign in to comment.