feat(proxy): add proxy file system for non-markdown source conversion
Introduces a new `markitect/proxy/` module with pluggable extractors that convert non-markdown sources (PDF, HTML) into tracked markdown proxy files. Proxy files preserve origin metadata (path, checksum, timestamp) so they can be kept in sync when the original changes. CLI commands: `proxy create`, `proxy update`, `proxy status`, `proxy extractors`. Built-in extractors: PDF (pymupdf4llm), HTML (markdownify), Markdown (built-in). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
44
markitect/proxy/extractors/pdf.py
Normal file
44
markitect/proxy/extractors/pdf.py
Normal file
@@ -0,0 +1,44 @@
|
||||
"""
|
||||
PDF extractor using pymupdf4llm.
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from markitect.proxy.extractors.base import BaseExtractor
|
||||
from markitect.proxy.models import ExtractionResult
|
||||
from markitect.proxy.exceptions import DependencyMissingError
|
||||
|
||||
|
||||
class PdfExtractor(BaseExtractor):
|
||||
"""Extracts markdown from PDF files via pymupdf4llm."""
|
||||
|
||||
name = "pdf"
|
||||
version = "1.0"
|
||||
extensions = (".pdf",)
|
||||
|
||||
def check_dependencies(self) -> bool:
|
||||
try:
|
||||
import pymupdf4llm # noqa: F401
|
||||
return True
|
||||
except ImportError:
|
||||
return False
|
||||
|
||||
def dependency_hint(self) -> str:
|
||||
return 'pip install "markitect[proxy-pdf]" (or: pip install pymupdf4llm)'
|
||||
|
||||
def extract(self, source_path: Path) -> ExtractionResult:
|
||||
if not self.check_dependencies():
|
||||
raise DependencyMissingError(
|
||||
"pymupdf4llm is required to extract PDF files.",
|
||||
package="pymupdf4llm",
|
||||
install_hint=self.dependency_hint(),
|
||||
)
|
||||
|
||||
import pymupdf4llm
|
||||
|
||||
md_text = pymupdf4llm.to_markdown(str(source_path))
|
||||
return ExtractionResult(
|
||||
content=md_text,
|
||||
extractor=self.name,
|
||||
extractor_version=self.version,
|
||||
)
|
||||
Reference in New Issue
Block a user