feat: implement comprehensive asset shipping for md-render command
Some checks failed
Test Suite / unit-tests (3.11) (push) Has been cancelled
Test Suite / unit-tests (3.12) (push) Has been cancelled
Test Suite / code-quality (push) Has been cancelled
Test Suite / security-scan (push) Has been cancelled
Test Suite / integration-tests (push) Has been cancelled
Test Suite / e2e-tests (push) Has been cancelled
Test Suite / performance-tests (push) Has been cancelled
Test Suite / test-summary (push) Has been cancelled
Some checks failed
Test Suite / unit-tests (3.11) (push) Has been cancelled
Test Suite / unit-tests (3.12) (push) Has been cancelled
Test Suite / code-quality (push) Has been cancelled
Test Suite / security-scan (push) Has been cancelled
Test Suite / integration-tests (push) Has been cancelled
Test Suite / e2e-tests (push) Has been cancelled
Test Suite / performance-tests (push) Has been cancelled
Test Suite / test-summary (push) Has been cancelled
Add automatic asset copying when rendering markdown to different output directories with intelligent defaults and full user control. Key Features: - Environment variable support: MARKITECT_OUTPUT_DIR sets default output directory - Smart defaults: auto-ship assets for directory output, disabled for file output - CLI control flags: --ship-assets and --no-ship-assets for explicit control - Timestamp-based copying: only copies when source newer than destination - Path preservation: maintains relative directory structure in output - Graceful error handling: missing assets logged as warnings, not failures Technical Implementation: - Enhanced asset discovery in markitect/assets/discovery.py with discover_assets_from_markdown() - Added environment variable priority: CLI --output > MARKITECT_OUTPUT_DIR > input directory - Comprehensive asset shipping logic with _ship_assets() function - Directory vs file output detection for intelligent default behavior Examples and Testing: - Added image-assets example directory with 6 sample images and comprehensive README - Created comprehensive TDD test suite with 10 tests covering all functionality - Tests validate environment variables, CLI flags, asset discovery, shipping logic, timestamp handling, missing assets, path preservation, and default behaviors Usage: markitect md-render file.md -o /output/dir/ # Auto-ships assets markitect md-render file.md --no-ship-assets # Suppresses shipping MARKITECT_OUTPUT_DIR=/docs markitect md-render file.md # Uses env var 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -223,6 +223,45 @@ class MarkdownScanner:
|
||||
return len(lines)
|
||||
|
||||
|
||||
def discover_assets_from_markdown(markdown_content: str, base_path: Path) -> List[AssetReference]:
|
||||
"""
|
||||
Simple function to discover assets from markdown content for md-render.
|
||||
|
||||
Args:
|
||||
markdown_content: The markdown content to scan
|
||||
base_path: Base path for resolving relative asset paths
|
||||
|
||||
Returns:
|
||||
List of AssetReference objects found in the markdown
|
||||
"""
|
||||
scanner = MarkdownScanner()
|
||||
|
||||
# Create a temporary file to use the existing scan_file method
|
||||
import tempfile
|
||||
with tempfile.NamedTemporaryFile(mode='w', suffix='.md', delete=False) as temp_file:
|
||||
temp_file.write(markdown_content)
|
||||
temp_path = Path(temp_file.name)
|
||||
|
||||
try:
|
||||
references = scanner.scan_file(temp_path)
|
||||
# Update the source_file to the actual base_path for relative resolution
|
||||
for ref in references:
|
||||
ref.source_file = base_path
|
||||
# Resolve the asset path relative to base_path
|
||||
if not ref.asset_path.startswith(('http:', 'https:', 'mailto:', 'data:')):
|
||||
# Clean up relative path indicators
|
||||
clean_path = ref.asset_path.lstrip('./')
|
||||
resolved_path = base_path / clean_path
|
||||
if resolved_path.exists():
|
||||
ref.resolved_path = resolved_path
|
||||
else:
|
||||
ref.is_broken = True
|
||||
return references
|
||||
finally:
|
||||
# Clean up temporary file
|
||||
temp_path.unlink(missing_ok=True)
|
||||
|
||||
|
||||
class AssetDiscoveryEngine:
|
||||
"""Main engine for asset discovery and analysis."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user