Upgrading from 0.4
Version 0.5 replaces pypandoc and pytidylib with a direct call to pandoc, and adds validation, safety checks, and limits.
What you may need to do
- Check your pandoc version. It must be 3.6 or newer. libtidy is no longer needed.
- Decide about
--strictin scripts. Default mode still converts with a warning, but automation should usually use it. - Handle exit code 3 in scripts if you check for specific codes.
- Update Python code that calls
convert_to_html(), as described below. - Check anything that depends on the HTML's structure, such as CSS or scrapers, since the markup has changed.
What's fixed
| In 0.4 | In 0.5 |
|---|---|
[, ?, or * in a path could silently convert a different file, merge files, or crash | Paths are always literal |
| Images pointed at files that were never written | Images are embedded in the HTML |
| No charset declared, so non-English text could be garbled | UTF-8 is declared |
| On macOS, a 2006 version of libtidy stripped HTML5 tags, so highlights were lost and footnote sections lost their structure | tidy isn't used |
.DOCX passed the extension check, then failed | Extensions aren't case-sensitive |
| Output was written in place, and through symlinks | Atomic writes that never follow a symlink |
| No limits, so a 3 KB file could exhaust all memory | Validation and limits |
import word2html could exit your program if a dependency was missing | No Python dependencies, and importing never exits |
What's different in the output
- HTML5 from pandoc's default template rather than tidied HTML 4, including pandoc's default CSS.
- Images are embedded, so files can be larger.
- The page has a title, instead of an empty one.
- Smart quotes are plain UTF-8 characters rather than HTML entities.
- Permissions on an existing output file are kept. New files use your normal defaults.
Command-line changes
- New options:
--strict,--timeout,--max-memory,--max-file-size, and--version. - New exit code:
3, for refusals. - Messages now start with
word2html: warning:,word2html: refused:, orword2html: error:. tidy's warnings are gone.
Python changes
convert_to_html() now returns a result and no longer prints anything:
# 0.4
convert_to_html("report.docx") # Printed its progress, and returned None
# 0.5
result = convert_to_html("report.docx")
print("Wrote", result.output_path)
for finding in result.warnings:
print("warning:", finding.message)
Error handling is mostly compatible. FileNotFoundError is unchanged, and InvalidDocumentError is a ValueError, so existing handlers still catch those. Other failures now raise specific exceptions based on WordToHtmlError.
The word2html.main entry point and the __version__ and VERSION attributes still exist. pypandoc and pytidylib are no longer installed, so if your own code imports them, add them to your own dependencies.