1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
from . import docx, conversion, options, documents, images, underline
__all__ = ["convert_to_html", "extract_raw_text", "images", "underline"]
def convert_to_html(fileobj, transform_document=None, generate_uniquifier=None, **kwargs):
if transform_document is None:
transform_document = lambda x: x
return docx.read(fileobj).map(transform_document).bind(lambda document:
conversion.convert_document_element_to_html(
document,
generate_uniquifier=generate_uniquifier,
**options.read_options(kwargs)
)
)
def extract_raw_text(fileobj):
return docx.read(fileobj).map(_extract_raw_text_from_element)
def _extract_raw_text_from_element(element):
if isinstance(element, documents.Text):
return element.value
else:
text = "".join(map(_extract_raw_text_from_element, element.children))
if isinstance(element, documents.Paragraph):
return text + "\n\n"
else:
return text
|