Repository navigation
Description
Parent Issue
Part of Epic #69: Text Editor Architecture Enhancement - Phase 1
Summary
Implement ContentProcessor service with Logseq-inspired dual-representation pattern to enable seamless switching between markdown source and rendered display while preparing for backlinking.
Current Problem
Content processing is scattered across TextNode and MinimalBaseNode components, mixing UI logic with business logic. Missing dual-representation needed for future backlinking system.
Proposed Solution
Create enhanced ContentProcessor service implementing dual-representation pattern:
Core Functionality
- Dual-Representation Management: Source (markdown) ↔ AST (parsed) ↔ Display (HTML)
- Markdown Processing: Advanced parsing with backlink preparation
- Content Validation: Sanitization and XSS prevention
- Header Management: Level parsing and syntax handling
- Backlink Preparation: Parse
[[wikilinks]]syntax (foundation for Phase 2)
Service Interface
interface ContentProcessor {
// Dual-representation pattern (Logseq-inspired)
parseMarkdown(source: string): MarkdownAST;
renderAST(ast: MarkdownAST): string;
astToMarkdown(ast: MarkdownAST): string;
// Legacy compatibility
markdownToDisplay(markdown: string): string;
displayToMarkdown(html: string): string;
// Content validation
validateContent(content: string): ValidationResult;
sanitizeContent(content: string): string;
// Header detection
parseHeaderLevel(content: string): number;
stripHeaderSyntax(content: string): string;
// Backlink preparation (Phase 2 foundation)
detectWikiLinks(content: string): WikiLink[];
prepareBacklinkSyntax(content: string): PreparedContent;
}
interface MarkdownAST {
type: 'document';
children: ASTNode[];
metadata: ContentMetadata;
}
interface WikiLink {
text: string;
target: string;
startPos: number;
endPos: number;
}Implementation Tasks
- Create enhanced ContentProcessor service interface
- Implement dual-representation pattern (source ↔ AST ↔ display)
- Add advanced markdown parsing with AST generation
- Implement header level parsing and management
- Add content validation and sanitization
- Create wikilink detection for Phase 2 foundation
- Build comprehensive unit tests for all patterns
- Update TextNode to use dual-representation
- Remove scattered content processing from components
- Add performance benchmarks for large documents
Acceptance Criteria
- ContentProcessor service implements dual-representation correctly
- Source markdown ↔ AST ↔ display conversions are lossless
- TextNode uses ContentProcessor instead of inline logic
- Wikilink syntax
[[text]]is detected and prepared for linking - Header detection works for H1-H6 levels with proper AST representation
- Content validation prevents XSS and malformed content
- Performance handles 1000+ node documents efficiently
- All existing functionality preserved
- Foundation ready for Phase 2 backlinking
Dependencies
None - can be implemented independently as foundation
Estimated Effort
5-6 days (expanded for dual-representation and backlink preparation)
Definition of Done
- Service implemented with full test coverage (>95%)
- TextNode refactored to use dual-representation
- AST generation and rendering working correctly
- Wikilink detection foundation implemented
- Performance benchmarks meet requirements
- All existing functionality preserved and enhanced
- Documentation updated with dual-representation patterns
- Code review completed
Notes
This enhanced ContentProcessor establishes the foundation for the entire backlinking system in Phase 2, making it critical to implement the dual-representation pattern correctly from the start.
Activity
[-]Phase 1.1: Implement ContentProcessor Service[/-][+]Phase 1.1: Enhanced ContentProcessor with Dual-Representation[/+]Implement Enhanced ContentProcessor with Dual-Representation (Phase 1.1)
Phase 1.1: Enhanced ContentProcessor with Dual-Representation (#76)
Implement Logseq-style focus/blur dual-representation in TextNode
Phase 1.1: Enhanced ContentProcessor with Dual-Representation (#76)
Implement Logseq-style focus/blur dual-representation in TextNode
Phase 1.1: Enhanced ContentProcessor with Dual-Representation (#76)
Implement Logseq-style focus/blur dual-representation in TextNode