Add revision management capability + tests + docs #1534
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds comprehensive support for creating and managing tracked changes (revisions) in Word documents, enabling programmatic document editing with full revision history visible in Microsoft Word.
Tests have been added for new functionality, and existing tests have been run to ensure that backwards compatibility is maintained.
Why?
Users need to make programmatic changes to Word documents while preserving some sort of an audit trail. Solves #930 and #340
Features
Paragraph.add_run_tracked()- Add text as a tracked insertionRun.delete_tracked()- Mark existing text as a tracked deletionParagraph.replace_tracked()- Replace specific text with revision trackingDocument.find_and_replace_tracked()- Bulk find-and-replace across entire documentdocument.settings.track_revisions- Enable/disable track changes modeTrackedInsertionandTrackedDeletionproxy classes withaccept()andreject()methodsExample Usage
This is just barebones, and this capability can be extended by later additions to possibly build out a context manager (eg.
with document.track_all_changes() as doc:) to make it function similar to how "Track Changes" works in word. However there are a fair number of edge cases you'd have to deal with in that situation.Some of this work draws on the exhaustive code written in OpenXmlPowerTools WmlComparer and the underlying .NET library.