docx-comment-injection
БесплатноЗапускает вложенные скриптыНе проверенDeliver review comments into a co-authored manuscript as native anchored .docx comments - the offline alternative to driving Google Docs through browser…
от Delphine-L★ 23 звезды на GitHubОб этом скилле
DOCX Comment Injection Skill
Overview
There is a third option between "hand the user a find → replace table" and "drive their live
manuscript through a canvas editor". Round-trip the document as .docx, write
w:commentRangeStart / w:commentRangeEnd markers around the sentences you want to flag,
upload it back, and every point lands as a native sidebar comment anchored to its sentence —
reviewable, repliable, resolvable, and attributable.
This is the safe channel. Nothing in the body is modified, so there is no equivalent of
the focus-loss failure documented in collaboration/live-document-editing. If the output is
wrong you throw the file away; the live document was never touched.
The script: inject_comments.py, next to this file. Standard library only.
python3 inject_comments.py manuscript.docx comments.tsv -o reviewed.docx \
--author "D. Lariviere" --initials DL
Why not just use a docx library
Two constraints make this harder than it looks, and both are load-bearing.
1. Google Docs cannot anchor a comment to a text range through any API.
Drive.Comments.create and Apps Script produce document-level, unanchored comments. The
only way to get an anchored comment into a Google Doc is to put it in an uploaded .docx and
let Drive's importer convert it. The OpenXML round trip is not a workaround — it is the only
route.
2. Reference-manager citations are hyperlinks, not text. A Paperpile citation is
<w:hyperlink r:id="rId10">
<w:r><w:rPr><w:vertAlign w:val="superscript"/></w:rPr><w:t>2-7</w:t></w:r>
</w:hyperlink>
with rId10 resolving through word/_rels/document.xml.rels to a
https://paperpile.com/c/... cloud id. EndNote uses ADDIN EN.CITE field codes; Zotero uses
bookmarks. pandoc, naive python-docx scripts and regex converters flatten these to plain
text, and the co-author's bibliography stops being formattable. Editing the package directly
and touching nothing but the comment markers keeps all of it alive.
The namespace trap — the one thing that breaks everything
Never ET.parse() then ET.write() a word/document.xml and expect it to open.
A real Word or Google Docs export declares a dozen namespaces on its root element and then
names some of them in mc:Ignorable:
<w:document xmlns:w="..." xmlns:mc="..." xmlns:w14="..." xmlns:w15="..." xmlns:wp14="..."
mc:Ignorable="w14 w15 wp14">
xml.etree.ElementTree emits only the namespaces its nodes use. Every declaration nothing
happens to touch is silently dropped, and the rest are renamed ns0, ns1, … The
mc:Ignorable attribute is carried through as an opaque string, so you end up with:
<w:document xmlns:ns1="...markup-compatibility/2006" ... ns1:Ignorable="w14 w15 wp14">
mc:Ignorable now names three prefixes that are not declared anywhere. Word reports "found
unreadable content" and refuses the file. python-docx reopens it happily, so a round-trip
test in Python will tell you everything is fine.
ET.register_namespace() does not fix this. It stabilises prefixes for namespaces that
are used; it does not make ElementTree emit a declaration for one that is not.
The fix: capture the root start-tag as a string before parsing, and substitute it back after serialising.
ROOT_TAG = re.compile(r"<w:document\b[^>]*>")
raw = doc_path.read_text(encoding="utf-8")
original_root = ROOT_TAG.search(raw).group(0) # before parsing
...
tree.write(doc_path, xml_declaration=True, encoding="UTF-8")
out = doc_path.read_text(encoding="utf-8")
doc_path.write_text(ROOT_TAG.sub(lambda _: original_root, out, count=1)) # after
The same class of problem hits word/_rels/document.xml.rels and [Content_Types].xml, which
use a default namespace. There, ET.register_namespace("", PKG_R) before parsing is
sufficient, because the default namespace is always in use.
What the markup looks like
Three additions to the body, and nothing else:
<w:p>
<w:commentRangeStart w:id="1"/>
<w:r><w:t xml:space="preserve">the sentence being commented on</w:t></w:r>
<w:hyperlink r:id="rIdPaperpile1">...</w:hyperlink> <!-- untouched -->
<w:commentRangeEnd w:id="1"/>
<w:r><w:rPr><w:rStyle w:val="CommentReference"/></w:rPr>
<w:commentReference w:id="1"/></w:r>
</w:p>
plus a new word/comments.xml, one relationship of type .../relationships/comments, and one
[Content_Types].xml override for /word/comments.xml.
Insert back-to-front. Inserting at first shifts every later child index by one. Sort the
pending insertions by descending paragraph then descending child index, or anchor n+1 lands
in the wrong place after anchor n is written.
comments.xml must carry the same namespace declarations as document.xml. Easiest to
serialise it by hand from the captured declaration string rather than building it with
ElementTree.
Anchoring: match on offsets, not on a prefix
The tempti
Установить docx-comment-injection в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
ReadWriteEditBashGrepGlobВложенные файлы
FAQ
Что делает скилл docx-comment-injection?
Deliver review comments into a co-authored manuscript as native anchored .docx comments - the offline alternative to driving Google Docs through browser automation, preserving live Paperpile/EndNote/Zotero citations
Как установить скилл docx-comment-injection?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл docx-comment-injection запускает скрипты?
Да, скилл несёт исполняемые скрипты. Проверь исходник перед установкой.
Похожие скиллы
docx
Use this skill whenever the user wants to create, read, edit, or manipulate Word documents (.docx files) or Word templates (.dotx files). Triggers include…
от AnthropicUse this skill whenever the user wants to do anything with PDF files. This includes reading or extracting text/tables from PDFs, combining or merging multiple…
от Anthropicxlsx
Use this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing…
от Anthropicpptx
Use this skill any time a .pptx or .potx file is involved in any way — as input, output, or both. This includes: creating slide decks, pitch decks, or…
от Anthropic