Skip to content

Commit 7a9fa1e

Browse files
fix(context): properly detect frontmatter and markdown sections
- Frontmatter must start at beginning of file (not mid-file ---) - Detect both h1 (#) and h2 (##) headers as sections - Fix type mismatch in sections slice ([]interface{} not []map)
1 parent f7c7ba8 commit 7a9fa1e

2 files changed

Lines changed: 28 additions & 6 deletions

File tree

internal/cli/context.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ func LintContext(rootPath string, quiet bool, verbose bool) (*LintSummary, error
8585
}
8686

8787
// parseMarkdownSections parses markdown content into sections
88-
func parseMarkdownSections(content string) []map[string]interface{} {
89-
var sections []map[string]interface{}
88+
func parseMarkdownSections(content string) []interface{} {
89+
var sections []interface{}
9090

9191
// This is a simplified parser - in practice, would use a proper markdown parser
9292
lines := []string{}
@@ -102,8 +102,19 @@ func parseMarkdownSections(content string) []map[string]interface{} {
102102
for _, line := range lines {
103103
line = strings.TrimSpace(line)
104104

105-
if strings.HasPrefix(line, "# ") {
106-
// New section found
105+
// Detect markdown headers (# or ##)
106+
if strings.HasPrefix(line, "## ") {
107+
// New h2 section found
108+
if inSection {
109+
sections = append(sections, currentSection)
110+
}
111+
currentSection = map[string]interface{}{
112+
"heading": strings.TrimPrefix(line, "## "),
113+
"content": "",
114+
}
115+
inSection = true
116+
} else if strings.HasPrefix(line, "# ") {
117+
// New h1 section found
107118
if inSection {
108119
sections = append(sections, currentSection)
109120
}

internal/frontend/parser.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,23 @@ type Frontmatter struct {
1212
Body string
1313
}
1414

15-
// ParseYAMLFrontmatter extracts YAML frontmatter from markdown content
15+
// ParseYAMLFrontmatter extracts YAML frontmatter from markdown content.
16+
// Frontmatter must start at the beginning of the file with "---".
1617
func ParseYAMLFrontmatter(content string) (*Frontmatter, error) {
18+
// Frontmatter must start at the very beginning of the file
19+
trimmed := strings.TrimLeft(content, " \t")
20+
if !strings.HasPrefix(trimmed, "---") {
21+
// No frontmatter - return content as body
22+
return &Frontmatter{
23+
Data: make(map[string]interface{}),
24+
Body: content,
25+
}, nil
26+
}
27+
1728
// Split content by ---
1829
parts := strings.SplitN(content, "---", 3)
1930

20-
// If we have less than 3 parts, there's no frontmatter
31+
// If we have less than 3 parts, there's no closing ---
2132
if len(parts) < 3 {
2233
return &Frontmatter{
2334
Data: make(map[string]interface{}),

0 commit comments

Comments
 (0)