Skip to content

Conversation

@chittolinag
Copy link
Contributor

@chittolinag chittolinag commented Jan 23, 2026

Implements a context-aware creation of permStart and permEnd tags. We're reusing the same logic that we use in the passthroughNodeImporter file, which detects the context based on the node's path.

If the context accepts only block, we'll create a block permission tag. Otherwise we'll create the inline version.

@chittolinag chittolinag marked this pull request as ready for review January 23, 2026 19:01
Comment on lines +1 to +53
const INLINE_PARENT_NAMES = new Set([
'w:r',
'w:hyperlink',
'w:smartTag',
'w:fldSimple',
'w:proofErr',
'w:del',
'w:ins',
'w:p', // Paragraph is an inline container; unknown children must be inline-safe
]);

const INLINE_NODE_NAMES = new Set([
'm:oMathPara',
'm:oMath',
'm:t',
'm:r',
'm:ctrlPr',
'm:sSupPr',
'm:e',
'm:sup',
'm:sSup',
]);

const BLOCK_BOUNDARY_NAMES = new Set(['w:body', 'w:tbl', 'w:tc', 'w:tr']);

/**
* Determines if the current DOCX node position accepts inline-only content.
* Walks up the ancestor chain until it finds an inline parent or block boundary.
*
* @param {Array<{ name?: string }>} [path=[]] Ancestor chain leading to the current node.
* @param {string} [currentNodeName] Optional immediate node name override.
* @returns {boolean}
*/
export const isInlineContext = (path = [], currentNodeName) => {
const immediateName = currentNodeName ?? path[path.length - 1]?.name;
if (immediateName && INLINE_NODE_NAMES.has(immediateName)) {
return true;
}
if (!Array.isArray(path) || path.length === 0) return false;

for (let i = path.length - 1; i >= 0; i--) {
const ancestorName = path[i]?.name;
if (!ancestorName) continue;
if (INLINE_NODE_NAMES.has(ancestorName) || INLINE_PARENT_NAMES.has(ancestorName)) {
return true;
}
if (BLOCK_BOUNDARY_NAMES.has(ancestorName)) {
return false;
}
}

return false;
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just moved this out of passthroughNodeImporter so it can be reused.

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.

2 participants