Title: Add revision management capability + tests + docs by amithkk · Pull Request #1534 · python-openxml/python-docx · GitHub
Open Graph Title: Add revision management capability + tests + docs by amithkk · Pull Request #1534 · python-openxml/python-docx
X Title: Add revision management capability + tests + docs by amithkk · Pull Request #1534 · python-openxml/python-docx
Description: 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 insertion Run.delete_tracked() - Mark existing text as a tracked deletion Paragraph.replace_tracked() - Replace specific text with revision tracking Document.find_and_replace_tracked() - Bulk find-and-replace across entire document document.settings.track_revisions - Enable/disable track changes mode TrackedInsertion and TrackedDeletion proxy classes with accept() and reject() methods Author and date metadata on all tracked changes Optional comment attachment to replacements Example Usage from docx import Document doc = Document('contract.docx') doc.settings.track_revisions = True count = doc.find_and_replace_tracked( "ACME Corp", "NewCo Inc", author="Legal Bot", comment="Company name updated per merger" ) doc.save('contract_revised.docx') 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.
Open Graph Description: 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 Wo...
X Description: 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 Wo...
Opengraph URL: https://github.com/python-openxml/python-docx/pull/1534
X: @github
Domain: patch-diff.githubusercontent.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:1fd01667-8158-b344-ec8d-fb5756f9b8b7 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | C37C:119AFD:7FADC9:AE62CF:6973C186 |
| html-safe-nonce | f6f6b019aaccb97526d810f9170d9c321e5809fc9cb61b7fbe279e0f18a8d516 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMzdDOjExOUFGRDo3RkFEQzk6QUU2MkNGOjY5NzNDMTg2IiwidmlzaXRvcl9pZCI6IjE3NDg4MDUzMDc2Nzc3ODY1MDIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 4169af04000dba040ec88b7d9eb1815ecbf0ab96d6967cf05b8e90d6ee04c159 |
| hovercard-subject-tag | pull_request:3152257580 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/python-openxml/python-docx/pull/1534/files |
| twitter:image | https://avatars.githubusercontent.com/u/1029727?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/1029727?s=400&v=4 |
| og:image:alt | 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 Wo... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | acb8c988baca9616cb18bcb596629b823688faa1ef21a000061fe3616b4e3605 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/python-openxml/python-docx git https://github.com/python-openxml/python-docx.git |
| octolytics-dimension-user_id | 3403760 |
| octolytics-dimension-user_login | python-openxml |
| octolytics-dimension-repository_id | 13592924 |
| octolytics-dimension-repository_nwo | python-openxml/python-docx |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 13592924 |
| octolytics-dimension-repository_network_root_nwo | python-openxml/python-docx |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | af4eb23c75c70abd61c0b216b767faf4c9a30817 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width