I read the doc and haven't found an option to generate the full HTML. Since the generated HTML is just a string, it is easy to make it a full HTML-compliant:
import mammoth
with open("test.docx", "rb") as docx_file:
result = mammoth.convert_to_html(docx_file)
html = result.value # The generated HTML
messages = result.messages # Any messages,
full_html = (
'<!DOCTYPE html><html><head><meta charset="utf-8"/></head><body>'
+ html
+ "</body></html>"
)
with open("test.html", "w", encoding="utf-8") as f:
f.write(full_html)
In the above code, we just prepend and append the necessary opening and closing tags to make the html
string a valid HTML source code.