(self)
| 66 | return {InputFormat.HTML} |
| 67 | |
| 68 | def convert(self) -> DoclingDocument: |
| 69 | # access self.path_or_stream to load stuff |
| 70 | origin = DocumentOrigin( |
| 71 | filename=self.file.name or "file", |
| 72 | mimetype="text/html", |
| 73 | binary_hash=self.document_hash, |
| 74 | ) |
| 75 | |
| 76 | doc = DoclingDocument(name=self.file.stem or "file", origin=origin) |
| 77 | _log.debug("Trying to convert HTML...") |
| 78 | |
| 79 | if self.is_valid(): |
| 80 | assert self.soup is not None |
| 81 | content = self.soup.body or self.soup |
| 82 | # Replace <br> tags with newline characters |
| 83 | for br in content.find_all("br"): |
| 84 | br.replace_with("\n") |
| 85 | doc = self.walk(content, doc) |
| 86 | else: |
| 87 | raise RuntimeError( |
| 88 | f"Cannot convert doc with {self.document_hash} because the backend failed to init." |
| 89 | ) |
| 90 | return doc |
| 91 | |
| 92 | def walk(self, element: Tag, doc: DoclingDocument): |
| 93 | try: |
no test coverage detected