MCPcopy Create free account
hub / github.com/Paper2Poster/Paper2Poster / convert

Method convert

docling/backend/html_backend.py:68–90  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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:

Callers 1

_build_documentMethod · 0.45

Calls 2

is_validMethod · 0.95
walkMethod · 0.95

Tested by

no test coverage detected