Skip to content

Commit 4431cae

Browse files
committed
trim markdown content
1 parent bc444d8 commit 4431cae

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

internal/formats/singlefile.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,10 @@ func renderToSingleFile(sourceDir string, format Format) error {
5555
// Add the rule to the combined content
5656
combinedContent.WriteString(fmt.Sprintf("## %s\n\n", title))
5757

58-
// Add the content without frontmatter
58+
// Add the content without frontmatter, trimming any leading whitespace
5959
ruleContent := stripFrontmatter(content)
60+
// Ensure there's no trailing whitespace after each rule
61+
ruleContent = bytes.TrimRight(ruleContent, " \t\n\r")
6062
combinedContent.Write(ruleContent)
6163
combinedContent.WriteString("\n\n")
6264
}
@@ -117,6 +119,7 @@ func hasFrontmatter(content []byte) bool {
117119
}
118120

119121
// stripFrontmatter removes the frontmatter from a rule file
122+
// and trims any leading whitespace from the markdown content
120123
func stripFrontmatter(content []byte) []byte {
121124
// Check if the file has frontmatter
122125
if !hasFrontmatter(content) {
@@ -130,5 +133,6 @@ func stripFrontmatter(content []byte) []byte {
130133
return content
131134
}
132135

133-
return bodyContent
136+
// Trim leading whitespace from the body content
137+
return bytes.TrimLeft(bodyContent, " \t\n\r")
134138
}

internal/formats/transform.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ func TransformRuleContent(content []byte, format Format) ([]byte, error) {
7272
return nil, err
7373
}
7474

75-
// If no metadata (or empty), just return the body content
75+
// If no metadata (or empty), just return the trimmed body content
7676
if len(transformedMetadata) == 0 {
77-
return bodyContent, nil
77+
return bytes.TrimSpace(bodyContent), nil
7878
}
7979

8080
// Serialize metadata to YAML

0 commit comments

Comments
 (0)