The Comprehensive Content Processor now uses the builder pattern from logseq_py.builders to generate properly structured Logseq content. This integration provides:
- Type safety: Builder methods provide clear interfaces for content construction
- Maintainability: No more string concatenation or template manipulation
- Consistency: All content follows the same structural patterns
- Flexibility: Easy to extend with new content types and formatting options
The BlockBuilder class is the foundation for creating Logseq blocks with:
- Hierarchical structure (parent-child relationships)
- Inline properties (
key:: valueformat) - Proper indentation handling
- Media embeds and rich content
The MediaBuilder provides specialized methods for embedding:
- YouTube videos:
MediaBuilder().youtube(url) - Twitter/X posts:
MediaBuilder().twitter(url) - PDF documents:
MediaBuilder().pdf(url)
The PageBuilder handles page-level content with:
- Page properties
- Headings and sections
- Text blocks and formatting
- Integration with topic pages
# Old approach with string templates
enhanced_content = f"""- {{{{youtube {url}}}}}
**{title}**
By: {author}
Duration: {duration}
topic-1:: [[{topic1}]]
topic-2:: [[{topic2}]]"""# New approach with builders
block_builder = BlockBuilder()
media = MediaBuilder().youtube(url)
block_builder.content(media.build())
block_builder.child(BlockBuilder(f"**{title}**"))
block_builder.child(BlockBuilder(f"By: {author}"))
block_builder.child(BlockBuilder(f"Duration: {duration}"))
block_builder.child(BlockBuilder(f"topic-1:: [[{topic1}]]"))
block_builder.child(BlockBuilder(f"topic-2:: [[{topic2}]]"))
enhanced_content = block_builder.build()- Content structure is defined by builders
- Business logic stays in the processor
- Output formatting is handled automatically
- No manual indentation counting
- No missing delimiters or brackets
- Proper escaping of special characters
- Clear intent with method names
- Self-documenting code structure
- Easy to trace content hierarchy
- Easy to add new content types
- Simple to modify output formats
- Testable in isolation
- Extract content metadata (title, author, duration, etc.)
- Create BlockBuilder instance
- Set main content using MediaBuilder for embeds
- Add child blocks for metadata
- Add topic properties as inline format blocks
- Build final output with proper hierarchy
Topics are added as inline properties using Logseq's key:: value format:
- {{youtube https://youtube.com/watch?v=...}}
**Video Title**
By: Author Name
topic-1:: [[Machine Learning]]
topic-2:: [[Python Programming]]This format ensures:
- Properties are visible in the graph
- Topics can be linked and navigated
- Content remains readable in plain text
To test the builder integration:
# Run syntax check
python -m py_compile logseq_py/pipeline/comprehensive_processor.py
# Run unit tests (if available)
pytest tests/test_comprehensive_processor.py
# Run integration test with dry-run
python scripts/comprehensive_processor_cli.py --graph-path /path/to/graph --dry-runPotential improvements for the builder integration:
- Custom builder methods for common patterns (e.g.,
add_video_with_metadata()) - Builder validation to ensure required fields are present
- Template builders for reusable content structures
- Bulk operations for processing multiple items efficiently
- Export formats to support different Logseq syntax variations