-
Notifications
You must be signed in to change notification settings - Fork 191
fix(super-editor): render and round-trip w:smartTag content (SD-2647) #3546
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
caio-pizzol
merged 4 commits into
main
from
caio/sd-2647-bug-render-and-round-trip-content-wrapped-in-wsmarttag
May 28, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7c08072
fix(super-editor): render and round-trip w:smartTag content (SD-2647)
caio-pizzol 4ed82b4
fix(super-editor): route smartTag through export and preserve smartTa…
caio-pizzol 0fc5541
test(super-editor): assert smartTag child text survives export round-…
caio-pizzol f808304
test(super-editor): add v2 bridge unit + round-trip behavior coverage…
caio-pizzol File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
packages/layout-engine/pm-adapter/src/converters/inline-converters/smart-tag.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import { type InlineConverterParams } from './common'; | ||
|
|
||
| /** | ||
| * pm-adapter inline converter for the SuperDoc `smartTag` node (SD-2647). | ||
| * | ||
| * A smartTag is a transparent OOXML inline wrapper (`<w:smartTag>`); its | ||
| * children are normal inline content. The pm-adapter contribution mirrors | ||
| * `structuredContentNodeToBlocks`: visit the children with the inherited | ||
| * marks unchanged so the wrapper contributes no run of its own. | ||
| * | ||
| * SD-2781 (mirrors structured-content / bookmark-start): forward | ||
| * `inlineRunProperties` so children inside the smartTag wrapper preserve | ||
| * run-level bidi/script metadata. The wrapper itself doesn't introduce a new | ||
| * run boundary, so the parent run's inline source still applies. | ||
| * | ||
| * The wrapper's own attrs (`element`, `uri`, `smartTagPr`) are metadata only; | ||
| * they survive round-trip via the v3 translator and don't affect layout. | ||
| */ | ||
| export function smartTagNodeToBlocks({ | ||
| node, | ||
| inheritedMarks, | ||
| sdtMetadata, | ||
| visitNode, | ||
| runProperties, | ||
| inlineRunProperties, | ||
| }: InlineConverterParams): void { | ||
| node.content?.forEach((child) => | ||
| visitNode(child, inheritedMarks, sdtMetadata, runProperties, false, inlineRunProperties), | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
packages/super-editor/src/editors/v1/core/super-converter/v2/importer/smartTagImporter.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| // @ts-check | ||
| import { translator as wSmartTagNodeTranslator } from '../../v3/handlers/w/smartTag/index.js'; | ||
|
|
||
| /** | ||
| * Smart-tag node handler (SD-2647 / SD-3298). | ||
| * | ||
| * Captures `<w:smartTag>` before it falls through to the passthrough handler. | ||
| * Without this entry the wrapper is hidden as `passthroughInline`, dropping | ||
| * its visible children (e.g. WIPO ST.3 country-region names inside the | ||
| * customer IT-945 doc). | ||
| * | ||
| * @param {import('../../v3/node-translator').SCEncoderConfig} params | ||
| * @returns {Object} Handler result | ||
| */ | ||
| const handleSmartTagNode = (params) => { | ||
| const { nodes } = params; | ||
| if (!nodes.length || nodes[0].name !== 'w:smartTag') { | ||
| return { nodes: [], consumed: 0 }; | ||
| } | ||
| const result = wSmartTagNodeTranslator.encode(params); | ||
| if (!result) return { nodes: [], consumed: 0 }; | ||
| return { | ||
| nodes: Array.isArray(result) ? result : [result], | ||
| consumed: 1, | ||
| }; | ||
| }; | ||
|
|
||
| /** | ||
| * Smart-tag node handler entity. Slotted into `defaultNodeListHandler` | ||
| * BEFORE `passthroughNodeHandlerEntity`. | ||
| * | ||
| * @type {Object} | ||
| */ | ||
| export const smartTagNodeEntityHandler = { | ||
| handlerName: 'w:smartTagTranslator', | ||
| handler: handleSmartTagNode, | ||
| }; |
64 changes: 64 additions & 0 deletions
64
...ges/super-editor/src/editors/v1/core/super-converter/v2/importer/smartTagImporter.test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import { describe, it, expect, vi } from 'vitest'; | ||
| import { defaultNodeListHandler } from './docxImporter.js'; | ||
| import { smartTagNodeEntityHandler } from './smartTagImporter.js'; | ||
| import { registeredHandlers } from '../../v3/handlers/index.js'; | ||
|
|
||
| const baseParams = () => ({ | ||
| docx: {}, | ||
| converter: {}, | ||
| editor: { extensionService: { extensions: [] } }, | ||
| nodeListHandler: { handler: vi.fn(() => []), handlerEntities: [] }, | ||
| path: [], | ||
| extraParams: {}, | ||
| importTrackingContext: { addUnhandled: () => {} }, | ||
| }); | ||
|
|
||
| describe('smartTagNodeEntityHandler', () => { | ||
| it('claims w:smartTag and emits a smartTag PM node (consumed: 1)', () => { | ||
| const node = { | ||
| name: 'w:smartTag', | ||
| attributes: { 'w:element': 'country-region' }, | ||
| elements: [{ name: 'w:r', elements: [{ name: 'w:t', elements: [{ type: 'text', text: 'Brazil' }] }] }], | ||
| }; | ||
|
|
||
| const result = smartTagNodeEntityHandler.handler({ ...baseParams(), nodes: [node] }); | ||
|
|
||
| expect(result.consumed).toBe(1); | ||
| expect(result.nodes).toHaveLength(1); | ||
| expect(result.nodes[0].type).toBe('smartTag'); | ||
| expect(result.nodes[0].attrs.element).toBe('country-region'); | ||
| }); | ||
|
|
||
| it('refuses non-smartTag nodes (consumed: 0)', () => { | ||
| const node = { name: 'w:r', elements: [] }; | ||
| const result = smartTagNodeEntityHandler.handler({ ...baseParams(), nodes: [node] }); | ||
| expect(result).toEqual({ nodes: [], consumed: 0 }); | ||
| }); | ||
|
|
||
| it('is the only entity that claims w:smartTag in defaultNodeListHandler (passthrough refuses because w:smartTag is in v3 registeredHandlers)', () => { | ||
| // Regression guard: cubic/codex flagged this v2 bridge as "redundant | ||
| // duplicate of the v3 registration". It is not. passthroughNodeImporter | ||
| // refuses any node present in registeredHandlers, so without this bridge | ||
| // w:smartTag would silently fall off the end of the reducer chain. | ||
| expect(registeredHandlers['w:smartTag']).toBeDefined(); | ||
|
|
||
| const { handlerEntities } = defaultNodeListHandler(); | ||
| const withoutBridge = handlerEntities.filter((e) => e.handlerName !== 'w:smartTagTranslator'); | ||
| const node = { | ||
| name: 'w:smartTag', | ||
| attributes: { 'w:element': 'country-region' }, | ||
| elements: [{ name: 'w:r', elements: [{ name: 'w:t', elements: [{ type: 'text', text: 'X' }] }] }], | ||
| }; | ||
| const params = { | ||
| ...baseParams(), | ||
| nodes: [node], | ||
| nodeListHandler: { handler: () => [], handlerEntities: withoutBridge }, | ||
| }; | ||
| const result = withoutBridge.reduce((acc, h) => (acc.consumed > 0 ? acc : h.handler(params)), { | ||
| nodes: [], | ||
| consumed: 0, | ||
| }); | ||
| expect(result.consumed).toBe(0); | ||
| expect(result.nodes).toHaveLength(0); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/super-editor/src/editors/v1/core/super-converter/v3/handlers/w/smartTag/index.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { config, translator } from './smartTag-translator.js'; |
56 changes: 56 additions & 0 deletions
56
...rc/editors/v1/core/super-converter/v3/handlers/w/smartTag/smartTag-export-routing.test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import { describe, expect, it } from 'vitest'; | ||
| import { exportSchemaToJson } from '../../../../exporter.js'; | ||
|
|
||
| function collectText(xmlNode) { | ||
| if (!xmlNode) return ''; | ||
| if (typeof xmlNode.text === 'string') return xmlNode.text; | ||
| const children = Array.isArray(xmlNode.elements) ? xmlNode.elements : []; | ||
| return children.map(collectText).join(''); | ||
| } | ||
|
|
||
| describe('smartTag export routing (SD-2647)', () => { | ||
| it('routes a smartTag PM node through exportSchemaToJson to <w:smartTag>', () => { | ||
| const node = { | ||
| type: 'smartTag', | ||
| attrs: { element: 'country-region', uri: 'urn:schemas-microsoft-com:office:smarttags' }, | ||
| content: [{ type: 'run', attrs: {}, content: [{ type: 'text', text: 'Brazil' }] }], | ||
| }; | ||
|
|
||
| const result = exportSchemaToJson({ node }); | ||
|
|
||
| expect(result).not.toBeNull(); | ||
| expect(result?.name).toBe('w:smartTag'); | ||
| expect(result?.attributes?.['w:element']).toBe('country-region'); | ||
| expect(result?.attributes?.['w:uri']).toBe('urn:schemas-microsoft-com:office:smarttags'); | ||
| expect(collectText(result)).toBe('Brazil'); | ||
| }); | ||
|
|
||
| it('preserves the captured w:smartTagPr when re-emitting through exportSchemaToJson', () => { | ||
| const smartTagPr = { | ||
| type: 'element', | ||
| name: 'w:smartTagPr', | ||
| elements: [ | ||
| { | ||
| type: 'element', | ||
| name: 'w:attr', | ||
| attributes: { 'w:name': 'CountryRegion', 'w:val': 'BR' }, | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| const node = { | ||
| type: 'smartTag', | ||
| attrs: { element: 'country-region', uri: null, smartTagPr }, | ||
| content: [{ type: 'run', attrs: {}, content: [{ type: 'text', text: 'Brazil' }] }], | ||
| }; | ||
|
|
||
| const result = exportSchemaToJson({ node }); | ||
|
|
||
| expect(result?.name).toBe('w:smartTag'); | ||
| const firstChild = result?.elements?.[0]; | ||
| expect(firstChild?.name).toBe('w:smartTagPr'); | ||
| expect(firstChild?.elements?.[0]?.name).toBe('w:attr'); | ||
| expect(firstChild?.elements?.[0]?.attributes?.['w:val']).toBe('BR'); | ||
| expect(collectText(result)).toBe('Brazil'); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.