Skip to content

Conversation

@nanxstats
Copy link
Collaborator

Closes #175

This PR:

  • Implements RTFDocument.write_html() and RTFDocument.write_pdf() alongside write_docx(), using the same temporary RTF + LibreOffice conversion flow and optional converter= reuse.
  • Moves LibreOffice-generated HTML companion resource directory (*.html_files) next to the output when present.
  • Refactors write format tests to be parameterized across DOCX/HTML/PDF; adds PDF text extraction coverage via new pdf extra (pypdf).
  • Improves LibreOffice test gating by requiring a successful headless conversion in the availability check (due to possible sandboxing).

- Implement a function to check for pypdf installation.
- Update the LibreOffice check to validate successful document conversion.
- Introduce new tests for HTML, PDF, and DOCX export functionalities.
- Remove outdated test files related to DOCX export.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds write_html() and write_pdf() methods to RTFDocument, following the same pattern as the existing write_docx() method. The implementation uses LibreOffice for conversion from temporary RTF files.

Key changes:

  • Implements RTFDocument.write_html() and RTFDocument.write_pdf() methods with optional converter= parameter
  • Adds HTML resource directory handling for LibreOffice-generated companion files
  • Refactors tests to use parameterized testing across DOCX/HTML/PDF formats
  • Adds pypdf dependency (version 6.5.0) for PDF text extraction in tests
  • Improves LibreOffice availability checking with actual conversion test

Reviewed changes

Copilot reviewed 11 out of 12 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/rtflite/encode.py Adds write_html() and write_pdf() methods following the same pattern as write_docx()
tests/test_write_format.py New parameterized integration tests covering all three export formats (DOCX/HTML/PDF)
tests/test_write_format_args.py New parameterized unit tests for testing converter reuse and temp file handling
tests/conftest.py Enhanced LibreOffice availability check with actual conversion test; adds pypdf check
tests/test_write_docx.py Removed (replaced by parameterized tests)
tests/test_write_docx_args.py Removed (replaced by parameterized tests)
pyproject.toml Adds pdf optional dependency with pypdf>=5.0.0
uv.lock Locks pypdf 6.5.0 with dependencies
docs/index.md Updates dev setup to use --all-extras
README.md Updates dev setup to use --all-extras
docs/changelog.md Documents new features and testing improvements
CHANGELOG.md Documents new features and testing improvements

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@nanxstats nanxstats marked this pull request as ready for review December 26, 2025 22:59
@elong0527 elong0527 merged commit 36d7089 into main Dec 26, 2025
9 checks passed
@nanxstats nanxstats deleted the write-html-pdf branch December 26, 2025 23:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add write_html and write_pdf methods

3 participants