7.8 KiB
7.8 KiB
Fix Plan for Issue #483: Generated Markdown Formatting Issues
Overview
This plan addresses the GitHub issue #483 regarding inconsistent markdown generation that causes CRLF/whitespace issues on Windows, breaking automated editing tools that rely on exact string matches.
Problem Analysis
Root Causes Identified
- Line Ending Inconsistency: Generated markdown files use CRLF on Windows instead of normalized LF
- Non-deterministic Whitespace: Inconsistent blank lines and spacing around headings/sections
- Non-standard Formatting: Deviations from CommonMark/GFM conventions
- Template Issues: Story templates may not enforce consistent formatting
Current State Assessment
- ✅ Prettier is already configured (
prettier.config.mjs) - ✅ ESLint is configured for code quality
- ✅ Basic formatting scripts exist (
format:check,format:fix) - ❌ No
.editorconfigfile exists - ❌ No remark/remark-lint configuration
- ❌ Markdown generation doesn't normalize line endings
- ❌ Templates don't enforce consistent spacing
Implementation Strategy
Phase 1: Detection and Analysis (Todo Items 1-3)
Goal: Understand the current problem scope and create tests to detect issues
1.1 Analyze Current Markdown Generation
- Files to examine:
src/modules/bmm/workflows/4-implementation/create-story/template.md- Template processing logic in workflow instructions
- File writing utilities and output formatting code
- What to look for:
- How templates are processed and variables substituted
- Where line endings are set during file writing
- How spacing and formatting is controlled
1.2 Create Detection Tests
- Test categories needed:
- Line ending detection (CRLF vs LF)
- Whitespace consistency checks
- Heading hierarchy validation
- GFM compliance testing
- Test location:
test/markdown-formatting-tests.js
1.3 Create Test Fixtures
- Generate sample story files using current system
- Capture problematic output for comparison
- Create "golden" examples of correct formatting
Phase 2: Foundation Setup (Todo Items 4, 6-7, 12)
Goal: Establish tooling and configuration for consistent markdown formatting
2.1 Add .editorconfig File
# Example content
root = true
[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
charset = utf-8
[*.md]
trim_trailing_whitespace = false
max_line_length = off
[*.{yaml,yml}]
indent_style = space
indent_size = 2
2.2 Add Remark Linting
- Dependencies to add:
remarkremark-lintremark-preset-lint-consistentremark-preset-lint-recommended
- Configuration file:
.remarkrc.jsor.remarkrc.json
2.3 Update Prettier Config
- Ensure markdown-specific settings are optimized
- Consider
proseWrap: "always"vs current"preserve" - Verify
endOfLine: 'lf'is enforced for markdown
2.4 Update NPM Scripts
{
"scripts": {
"lint:md": "remark . --quiet --frail",
"lint:md:fix": "remark . --output",
"lint": "eslint . --ext .js,.cjs,.mjs,.yaml --max-warnings=0 && npm run lint:md"
}
}
Phase 3: Core Fix Implementation (Todo Items 5, 8-9)
Goal: Implement the actual formatting fixes
3.1 Create Markdown Formatting Utility
Location: src/utility/markdown-formatter.js
Functions needed:
normalizeLineEndings(content)- Force LF endingsnormalizeSpacing(content)- Consistent blank lines around sectionsvalidateGFMCompliance(content)- Check for GFM standardsformatMarkdownOutput(content)- Main formatter function
3.2 Update Template Processing
- Identify where templates are processed into final markdown
- Integrate the markdown formatter into the output pipeline
- Ensure all generated markdown goes through normalization
3.3 Update Story Template
File: src/modules/bmm/workflows/4-implementation/create-story/template.md
Changes needed:
- Consistent spacing around sections (one blank line)
- Proper heading hierarchy
- Standardized bullet point formatting
- Remove any potential smart quotes or special characters
Phase 4: Testing and Validation (Todo Items 10-11, 13)
Goal: Ensure the fixes work correctly across platforms
4.1 Snapshot Testing
- Create tests that generate markdown and compare to snapshots
- Test on both Windows and Unix-like systems
- Validate that output is identical across platforms
4.2 Windows-Specific Testing
- Test on Windows environment specifically
- Verify CRLF issues are resolved
- Confirm automated editing tools work correctly
4.3 Integration Testing
- Test the exact scenario from the issue (automated edits)
- Verify string replacement tools can find exact matches
- Test with tools like
remarkand static site generators
Phase 5: Final Validation (Todo Item 14)
Goal: Complete the solution and document changes
5.1 Comprehensive Testing
- Run full test suite
- Validate no regressions in existing functionality
- Ensure all markdown files are properly formatted
5.2 Documentation
- Update README if needed
- Document the formatting standards adopted
- Create guidelines for future template creation
Files to Modify
New Files
.editorconfig- Editor configuration for consistent formatting.remarkrc.js- Remark configuration for markdown lintingsrc/utility/markdown-formatter.js- Markdown formatting utilitytest/markdown-formatting-tests.js- Tests for markdown formatting
Modified Files
package.json- Add remark dependencies and scriptsprettier.config.mjs- Potentially adjust markdown settingssrc/modules/bmm/workflows/4-implementation/create-story/template.md- Update template formatting- Workflow instruction files that process templates - Add formatting normalization
- Template processing utilities - Integrate markdown formatter
Success Criteria
Technical Requirements
- ✅ All generated markdown uses LF line endings consistently
- ✅ Consistent blank line spacing around headings and sections
- ✅ GFM-compliant formatting (proper heading hierarchy, code blocks, etc.)
- ✅ No trailing whitespace except where needed
- ✅ Deterministic output (same input always produces identical output)
Functional Requirements
- ✅ Automated editing tools can successfully find and replace exact strings
- ✅ Generated markdown renders correctly on GitHub and static site generators
- ✅ No breaking changes to existing story files or workflows
- ✅ Cross-platform consistency (Windows, macOS, Linux)
Quality Requirements
- ✅ All tests pass
- ✅ No linting errors
- ✅ Snapshot tests validate consistent output
- ✅ No performance regression in markdown generation
Risk Mitigation
Potential Issues
- Breaking Changes: Template changes might affect existing workflows
- Mitigation: Thorough testing and backward compatibility checks
- Performance Impact: Additional formatting may slow generation
- Mitigation: Optimize formatter and measure performance impact
- Platform Differences: Different behavior on Windows vs Unix
- Mitigation: Cross-platform testing and explicit line ending handling
Rollback Plan
- Keep original templates as
.backupfiles - Implement feature flags for new formatting
- Maintain backward compatibility until full validation
Timeline Estimate
- Phase 1: 1-2 days (Analysis and detection)
- Phase 2: 1 day (Configuration setup)
- Phase 3: 2-3 days (Core implementation)
- Phase 4: 2 days (Testing and validation)
- Phase 5: 1 day (Final validation and documentation)
Total: 7-9 days estimated effort
Next Steps
- Start with Todo Item 1: Analyze current markdown generation
- Create detection tests to understand the scope of the problem
- Set up foundation tooling and configuration
- Implement the core fixes with proper testing
- Validate across platforms and use cases