René's URL Explorer Experiment


Title: Keep comment anchors when assigning `Paragraph.text` by Dmitry-Kov · Pull Request #1645 · python-openxml/python-docx · GitHub

Open Graph Title: Keep comment anchors when assigning `Paragraph.text` by Dmitry-Kov · Pull Request #1645 · python-openxml/python-docx

X Title: Keep comment anchors when assigning `Paragraph.text` by Dmitry-Kov · Pull Request #1645 · python-openxml/python-docx

Description: Takes over #1605 by @gyanu2507, which was closed unmerged with an open invitation to pick it up. The commit keeps their credit with a Co-authored-by trailer. This fixes the comment half of #1604. Footnotes and tracked changes are still affected, so #1604 should stay open. Problem Paragraph.text = ... calls clear(), which removes every child of the paragraph except w:pPr. That includes w:commentRangeStart / w:commentRangeEnd (these are paragraph children, not run content) and the run holding w:commentReference. The stays in comments.xml anchored to nothing. Word opens the file without a warning and doesn't show the comment. Change Before clearing, the setter collects the paragraph's comment markers. It then puts them back around the new run: each w:commentRangeStart before it, and each w:commentRangeEnd and comment-reference run after it, both groups in document order. The original elements are moved, not rebuilt, so whatever Word wrote on them (including a localized reference rStyle) is kept. A comment that covered part of the paragraph now covers the whole new run, not its original word span. For a full-text replacement that's the only outcome that makes sense, and it matches what Word does when you retype a commented passage. The docstring says so. Differences from #1605: Only markers that were in this paragraph come back. #1605 re-emitted start, end and reference for every commentRangeStart it found. So for a comment spanning two paragraphs (add_comment() supports this), assigning text to the first paragraph gave the comment a second commentRangeEnd and commentReference. Assigning text to the second paragraph still left it orphaned. Markers inside a w:hyperlink are kept too. add_comment() places them there when the anchor run is inside a hyperlink, and the setter removes the hyperlink. #1605's own test is kept unchanged apart from ruff format. Not fixed here (#1604 stays open) Footnote and endnote reference runs are still removed. The note body stays in footnotes.xml / endnotes.xml with nothing referencing it. w:ins / w:del around the runs are still removed. Separate, pre-existing: add_comment() writes rStyle="CommentReference" without defining that style (#1609). Tests Unit: it_keeps_only_the_comment_markers_it_contains_when_text_is_assigned is parametrized over: a range that starts here and ends in a later paragraph a range that ends here two comments on different words a comment inside a hyperlink w:pPr staying first Acceptance: a new scenario in par-set-text.feature, run against the existing Word-authored comments-rich-para.docx. Every new test fails on master. pytest: 1615 passed. behave: 651 scenarios passed. ruff check and ruff format --check are clean, and pyright reports nothing new for paragraph.py (Python 3.9, deps from uv.lock). Checked against the saved files Before/after pairs produced through paragraph.text and checked with ooxml-integrity check out.docx --against in.docx (0.9.0). Disclosure: I maintain that tool. Case master (1.2.0) #1605 this PR #1604 repro: comment on one run CMT005 orphaned comment, FID001 comment anchors 1 → 0 no comment findings no comment findings Word-authored comments-rich-para.docx, text set on the commented paragraph CMT005, FID001 comment anchors 4 → 3 no comment findings no comment findings Comment spanning two paragraphs, text set on the first CMT002 commentRangeEnd without start second commentRangeEnd + commentReference for the same id (FID002 anchors 1 → 2) no comment findings, markers as in the source Same, text set on the second CMT001, CMT003, CMT005, FID001 anchors 1 → 0 CMT001, CMT003, CMT005, FID001 anchors 1 → 0 no comment findings The only other findings are FID014, which is the intended text change, and STY001 (#1609), which is already present in the python-docx-generated source files. 🤖 Generated with Claude Code

Open Graph Description: Takes over #1605 by @gyanu2507, which was closed unmerged with an open invitation to pick it up. The commit keeps their credit with a Co-authored-by trailer. This fixes the comment half of #1604. F...

X Description: Takes over #1605 by @gyanu2507, which was closed unmerged with an open invitation to pick it up. The commit keeps their credit with a Co-authored-by trailer. This fixes the comment half of #1604. F...

Opengraph URL: https://github.com/python-openxml/python-docx/pull/1645

X: @github

direct link

Domain: github.com

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:02110c76-8c6f-79c3-e12d-02f7fa938338
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idD5A0:3204C8:802AD4:942EE1:6AFF65CF
html-safe-nonce6554f78c6d46b4fecdd317863dd0da91f14d66ff767c9ad4c3ecd525cb3bbb38
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENUEwOjMyMDRDODo4MDJBRDQ6OTQyRUUxOjZBRkY2NUNGIiwidmlzaXRvcl9pZCI6IjQ5MzMwOTk0MjQzNDg1MDI1NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac2bf545f1d684680df53f0f6fa0be4d01c6da9b1fa3efebac522f65c87620d375
hovercard-subject-tagpull_request:5236540679
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/python-openxml/python-docx/pull/1645/files
twitter:imagehttps://avatars.githubusercontent.com/u/177517982?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/177517982?s=400&v=4
og:image:altTakes over #1605 by @gyanu2507, which was closed unmerged with an open invitation to pick it up. The commit keeps their credit with a Co-authored-by trailer. This fixes the comment half of #1604. F...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None41b58589a1c4eda1e3c8904144a412b88ca4455f63ca2ad3629f2e9f3c3a1d12
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/python-openxml/python-docx git https://github.com/python-openxml/python-docx.git
octolytics-dimension-user_id3403760
octolytics-dimension-user_loginpython-openxml
octolytics-dimension-repository_id13592924
octolytics-dimension-repository_nwopython-openxml/python-docx
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id13592924
octolytics-dimension-repository_network_root_nwopython-openxml/python-docx
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release8968d6d6acc65d74e4df332d23932dd3fd0502a4
ui-targetcanary-1
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python-openxml/python-docx/pull/1645/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython-openxml%2Fpython-docx%2Fpull%2F1645%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython-openxml%2Fpython-docx%2Fpull%2F1645%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=python-openxml%2Fpython-docx
Reloadhttps://github.com/python-openxml/python-docx/pull/1645/files
Reloadhttps://github.com/python-openxml/python-docx/pull/1645/files
Reloadhttps://github.com/python-openxml/python-docx/pull/1645/files
python-openxmlhttps://github.com/python-openxml
python-docxhttps://github.com/python-openxml/python-docx
Codehttps://github.com/python-openxml/python-docx
Issues387 (387)https://github.com/python-openxml/python-docx/issues
Pull requests167 (167)https://github.com/python-openxml/python-docx/pulls
Actionshttps://github.com/python-openxml/python-docx/actions
Projectshttps://github.com/python-openxml/python-docx/projects
Wikihttps://github.com/python-openxml/python-docx/wiki
Security and qualityhttps://github.com/python-openxml/python-docx/security
Insightshttps://github.com/python-openxml/python-docx/insights
Sign up for GitHub https://github.com/signup?return_to=%2Fpython-openxml%2Fpython-docx%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fpython-openxml%2Fpython-docx%2Fissues%2Fnew%2Fchoose
Dmitry-Kovhttps://github.com/Dmitry-Kov
python-openxml:masterhttps://github.com/python-openxml/python-docx/tree/master
Dmitry-Kov:paragraph-text-keeps-commentshttps://github.com/Dmitry-Kov/python-docx/tree/paragraph-text-keeps-comments
Conversation 0 https://github.com/python-openxml/python-docx/pull/1645
Commits 1 https://github.com/python-openxml/python-docx/pull/1645/commits
Checks 0 https://github.com/python-openxml/python-docx/pull/1645/checks
Files changed https://github.com/python-openxml/python-docx/pull/1645/files
Please reload this pagehttps://github.com/python-openxml/python-docx/pull/1645/files
Keep comment anchors when assigning Paragraph.text https://github.com/python-openxml/python-docx/pull/1645/files#top
Show all changes 1 commit https://github.com/python-openxml/python-docx/pull/1645/files
caa5c69 fix: keep comment anchors when assigning Paragraph.text Dmitry-Kov Nov 10, 2026 https://github.com/python-openxml/python-docx/pull/1645/commits/caa5c699acc655904386f5360e75c8f9fe777e06
Clear filters https://github.com/python-openxml/python-docx/pull/1645/files
Please reload this pagehttps://github.com/python-openxml/python-docx/pull/1645/files
Please reload this pagehttps://github.com/python-openxml/python-docx/pull/1645/files
par-set-text.feature https://github.com/python-openxml/python-docx/pull/1645/files#diff-aa9902268777c56280867f4ac4c8ad1c93a34577f93ca1b7a83362c267e1115e
paragraph.py https://github.com/python-openxml/python-docx/pull/1645/files#diff-86e03dcf5254cd61a249733e8fa4dd47bf0377747869d59411493df2e288f18a
paragraph.py https://github.com/python-openxml/python-docx/pull/1645/files#diff-97eceaeb4ca0c9bd77aa456168dff469c3196b2dd4891f694d9f66c2c8fe4da0
test_paragraph.py https://github.com/python-openxml/python-docx/pull/1645/files#diff-e9a03c4eb41c734107ef5073b6657104cccdf9eede0e18cca01fe0885670b7d3
features/par-set-text.featurehttps://github.com/python-openxml/python-docx/pull/1645/files#diff-aa9902268777c56280867f4ac4c8ad1c93a34577f93ca1b7a83362c267e1115e
View file https://github.com/python-openxml/python-docx/blob/caa5c699acc655904386f5360e75c8f9fe777e06/features/par-set-text.feature
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python-openxml/python-docx/pull/1645/{{ revealButtonHref }}
https://github.com/python-openxml/python-docx/pull/1645/files#diff-aa9902268777c56280867f4ac4c8ad1c93a34577f93ca1b7a83362c267e1115e
features/steps/paragraph.pyhttps://github.com/python-openxml/python-docx/pull/1645/files#diff-86e03dcf5254cd61a249733e8fa4dd47bf0377747869d59411493df2e288f18a
View file https://github.com/python-openxml/python-docx/blob/caa5c699acc655904386f5360e75c8f9fe777e06/features/steps/paragraph.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python-openxml/python-docx/pull/1645/{{ revealButtonHref }}
https://github.com/python-openxml/python-docx/pull/1645/files#diff-86e03dcf5254cd61a249733e8fa4dd47bf0377747869d59411493df2e288f18a
https://github.com/python-openxml/python-docx/pull/1645/files#diff-86e03dcf5254cd61a249733e8fa4dd47bf0377747869d59411493df2e288f18a
https://github.com/python-openxml/python-docx/pull/1645/files#diff-86e03dcf5254cd61a249733e8fa4dd47bf0377747869d59411493df2e288f18a
https://github.com/python-openxml/python-docx/pull/1645/files#diff-86e03dcf5254cd61a249733e8fa4dd47bf0377747869d59411493df2e288f18a
https://github.com/python-openxml/python-docx/pull/1645/files#diff-86e03dcf5254cd61a249733e8fa4dd47bf0377747869d59411493df2e288f18a
src/docx/text/paragraph.pyhttps://github.com/python-openxml/python-docx/pull/1645/files#diff-97eceaeb4ca0c9bd77aa456168dff469c3196b2dd4891f694d9f66c2c8fe4da0
View file https://github.com/python-openxml/python-docx/blob/caa5c699acc655904386f5360e75c8f9fe777e06/src/docx/text/paragraph.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python-openxml/python-docx/pull/1645/{{ revealButtonHref }}
https://github.com/python-openxml/python-docx/pull/1645/files#diff-97eceaeb4ca0c9bd77aa456168dff469c3196b2dd4891f694d9f66c2c8fe4da0
https://github.com/python-openxml/python-docx/pull/1645/files#diff-97eceaeb4ca0c9bd77aa456168dff469c3196b2dd4891f694d9f66c2c8fe4da0
https://github.com/python-openxml/python-docx/pull/1645/files#diff-97eceaeb4ca0c9bd77aa456168dff469c3196b2dd4891f694d9f66c2c8fe4da0
https://github.com/python-openxml/python-docx/pull/1645/files#diff-97eceaeb4ca0c9bd77aa456168dff469c3196b2dd4891f694d9f66c2c8fe4da0
tests/text/test_paragraph.pyhttps://github.com/python-openxml/python-docx/pull/1645/files#diff-e9a03c4eb41c734107ef5073b6657104cccdf9eede0e18cca01fe0885670b7d3
View file https://github.com/python-openxml/python-docx/blob/caa5c699acc655904386f5360e75c8f9fe777e06/tests/text/test_paragraph.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python-openxml/python-docx/pull/1645/{{ revealButtonHref }}
https://github.com/python-openxml/python-docx/pull/1645/files#diff-e9a03c4eb41c734107ef5073b6657104cccdf9eede0e18cca01fe0885670b7d3
https://github.com/python-openxml/python-docx/pull/1645/files#diff-e9a03c4eb41c734107ef5073b6657104cccdf9eede0e18cca01fe0885670b7d3
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.