MCPcopy Create free account
hub / github.com/NanoNets/docstrange / process

Method process

docstrange/processors/html_processor.py:35–65  ·  view source on GitHub ↗

Process the HTML file and return a conversion result. Args: file_path: Path to the HTML file to process Returns: ConversionResult containing the processed content Raises: FileNotFoundError: If the file doe

(self, file_path: str)

Source from the content-addressed store, hash-verified

33 return ext in ['.html', '.htm']
34
35 def process(self, file_path: str) -> ConversionResult:
36 """Process the HTML file and return a conversion result.
37
38 Args:
39 file_path: Path to the HTML file to process
40
41 Returns:
42 ConversionResult containing the processed content
43
44 Raises:
45 FileNotFoundError: If the file doesn't exist
46 ConversionError: If processing fails
47 """
48 if not os.path.exists(file_path):
49 raise FileNotFoundError(f"File not found: {file_path}")
50
51 try:
52 try:
53 from markdownify import markdownify as md
54 except ImportError:
55 raise ConversionError("markdownify is required for HTML processing. Install it with: pip install markdownify")
56
57 metadata = self.get_metadata(file_path)
58 with open(file_path, 'r', encoding='utf-8') as f:
59 html_content = f.read()
60 content = md(html_content, heading_style="ATX")
61 return ConversionResult(content, metadata)
62 except Exception as e:
63 if isinstance(e, (FileNotFoundError, ConversionError)):
64 raise
65 raise ConversionError(f"Failed to process HTML file {file_path}: {str(e)}")

Callers

nothing calls this directly

Calls 4

FileNotFoundErrorClass · 0.85
ConversionErrorClass · 0.85
ConversionResultClass · 0.85
get_metadataMethod · 0.80

Tested by

no test coverage detected