8000 DEV-24325 Add support for comment replies by harvestcore · Pull Request #21 · FontoXML/docxml · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

DEV-24325 Add support for comment replies #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 1, 2025

Conversation

harvestcore
Copy link

Comments (and ranges) now have a new parentId property so they're internally linked together. The way replies work in OOXML is wild:

  1. Replies also need ranges, this is fine.
  2. Linking a reply to a comment introduces the need of a new XML file: CommentsExtended.xml.
    a. This one is pretty simple actually, contains w15:commentEx nodes with some attributes.
    b. w15:paraId. This one is the identifier of the paragraph inside the Comment (remember that a w:comment has a w:p child node).
    c. w15:paraIdParent. This one is optional, is the identifier of the parent paragraph.
  3. This means that comments (and replies) are linked together by the paragraph inside the w:comment node, not by the w:comment themselves 🤡.

A few changes:

  • I've updated the Paragraph class, it now allows setting a new id property. This one translates to w14:paraId when converted to a node.
  • The CommentsXML class is now extended with a CommentsExtended internal property, to handle the replies and all that.
  • To generate the w15:paraId attribute I'm using the Comment identifier, but converted to a 4 bytes hexadecimal value (again, 🤡).
  • Added a few test here and there. I've also updated some others.

Copy link
@luiisgallego luiisgallego left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks good, but take a look at my comments. I haven't tested this branch specifically as the PR of the replies in FO was already using it.

// For regular paragraphs this identifier is not required.
// It is when comments have replies. These "links" (X comment is a reply of Y comment)
// are handled via this identifier.
#id: string | null = null;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this 'id' is specific to that case and, consequently, only to the 'paraId' attribute, shouldn't it be called 'paraId' directly?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The paraId is the identifier of the paragraph. I used id to remove the redundant para part.

* This identifier is used by comment replies.
*/
public set id(id: number | string) {
this.#id = typeof id === 'string' ? id : toHex(id);
8000 Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is confusing for me. Word provides (or requires) the value of paraId as a string and in hexadecimal, right? If so, this value should always be a string. It is FO who has to provide the value accordingly. Maybe I'm wrong, but docxml doesn't usually do type conversions and such (apart from dimensions).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I store a hexadecimal value (instead of a number) just to simplify a bit everything. This setter allows a number or an string just to simplify setting a value. When importing a paragraph (fromNode) the value will be already in hexadecimal, so the string is used in that case. When creating a reply it may be needed to set an identifier, in that case it is easier to give this function a number.

In all cases the hexadecimal value is always handled in this class, so no external classes need to handle that.

Maybe it is best to create a new Id type, similar to Length, so we can handle multiple formats at once.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've implemented a new Id type.

/**
* Creates an XML DOM node for this component instance.
*/
public override async toNode(ancestry: ComponentAncestor[]): Promise<Node> {
/**
* For some reason, MSWord requires the paraId attribute to have the w14 namespace, and at the

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This scares me a bit... Could we find out something more in depth? It's the first thing I see in the project where ‘"w14" or ".w15" is used... wouldn't "w" be enough?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clarification: It scares me because I have the feeling that it could lead to compatibility problems, but I can't prove my thoughts right now either.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing a quick test my Word uses those namespaces, I guess they are correct. Sorry for my monologue hahaha

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find a reason why this happens. MSWord things ¯_(ツ)_/¯.

@harvestcore harvestcore merged commit 53ef7ef into develop Jun 1, 2025
2 checks passed
@harvestcore harvestcore deleted the DEV-24325-comment-replies branch June 1, 2025 19:33
@wvbe
Copy link
wvbe commented Jun 2, 2025

👀 This is awesome guys!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0