Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/core/parsers/markdown-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,12 @@ export class MarkdownParser {
contentBeforeChildren.push(line);
}

// Find first non-empty line
// Find first non-empty requirement text line, skipping optional metadata.
const directContent = contentBeforeChildren.join('\n').trim();
if (directContent) {
const firstLine = directContent.split('\n').find(l => l.trim());
const firstLine = directContent
.split('\n')
.find(l => l.trim() && !this.isRequirementMetadataLine(l));
if (firstLine) {
text = firstLine.trim();
}
Expand All @@ -237,6 +239,10 @@ export class MarkdownParser {
return requirements;
}

private isRequirementMetadataLine(line: string): boolean {
return /^\*\*[^*]+\*\*:/.test(line.trim());
}

protected parseScenarios(requirementSection: Section): Scenario[] {
const scenarios: Scenario[] = [];

Expand Down
27 changes: 27 additions & 0 deletions test/core/parsers/markdown-parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,33 @@ Then they are authenticated
expect(scenario.rawText).toContain('and see a maintenance warning');
});

it('should skip requirement metadata before description text', () => {
const content = `# File Serving Spec

## Purpose
This specification defines file serving requirements.

## Requirements

### Requirement: File Serving
**ID**: REQ-FILE-001
**Priority**: P1

The system MUST serve static files from the root directory.

#### Scenario: Static file request
- **WHEN** a client requests a static file
- **THEN** the file is returned`;

const parser = new MarkdownParser(content);
const spec = parser.parseSpec('file-serving');

expect(spec.requirements).toHaveLength(1);
expect(spec.requirements[0].text).toBe(
'The system MUST serve static files from the root directory.'
);
});

it('should throw error for missing overview', () => {
const content = `# Test Spec

Expand Down