fix(docs): pair comment ids with the document order, not the spec order (#92)
Release / GoReleaser (push) Skipped
Tests / Secret scan (gitleaks) (push) Skipped
Tests / Test (Go 1.25) (push) Skipped
Tests / Test (Go stable) (push) Skipped
Tests / Secret scan (gitleaks) (pull_request) Successful in 5s
Tests / Test (Go 1.25) (pull_request) Successful in 22s
Tests / Test (Go stable) (pull_request) Successful in 37s

This commit is contained in:
2026-10-07 18:45:16 +01:00
parent 29d16b1645
commit 00b55caff8
2 changed files with 47 additions and 6 deletions
+4 -6
View File
@@ -65,6 +65,7 @@ func InjectDocxComments(src []byte, author string, comments []DocxComment) ([]by
}
used := make([]bool, len(comments))
applied := make([]DocxComment, 0, len(comments))
id := 0
newDoc := docxParaRe.ReplaceAllStringFunc(string(doc), func(p string) string {
txt := docxPlain(p)
@@ -73,6 +74,9 @@ func InjectDocxComments(src []byte, author string, comments []DocxComment) ([]by
continue
}
used[i] = true
// Record in document order so comments.xml id N matches the marker
// with id N (the spec order may differ from the document order).
applied = append(applied, c)
p = docxAddMarkers(p, id)
id++
break
@@ -80,12 +84,6 @@ func InjectDocxComments(src []byte, author string, comments []DocxComment) ([]by
return p
})
applied := make([]DocxComment, 0, len(comments))
for i, c := range comments {
if used[i] {
applied = append(applied, c)
}
}
parts["word/document.xml"] = []byte(newDoc)
parts["word/comments.xml"] = docxBuildComments(author, applied)
parts["[Content_Types].xml"] = docxAddContentType(parts["[Content_Types].xml"])