# TipTap Editor: How do I add a wrapping DIV when inserting the table?

**URL:** <https://forum.umbraco.com/t/tiptap-editor-how-do-i-add-a-wrapping-div-when-inserting-the-table/4521>\
**Category:** Questions\
**Tags:** extending, bellissima, v16\
**Created:** [July 10, 2025, 2:48pm UTC](https://forum.umbraco.com/t/tiptap-editor-how-do-i-add-a-wrapping-div-when-inserting-the-table/4521 "2025-07-10T14:48:21Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![warren](https://forum.umbraco.com/user_avatar/forum.umbraco.com/warren/32/78_2.png) [@warren](https://forum.umbraco.com/u/warren)\
**Post date:** [July 10, 2025, 2:48pm UTC](https://forum.umbraco.com/t/tiptap-editor-how-do-i-add-a-wrapping-div-when-inserting-the-table/4521/1 "2025-07-10T14:48:21Z")

</div>

Heya 👋  
I am migrating a project where the TinyMCE had a plugin that wrapped a DIV with a specific CSS class around the table anytime it was inserted into the editor.

### Previous TinyMCE code

```js
(function () {
    tinymce.PluginManager.add('wrap_tables', function (editor) {
        editor.on('PreInit', function () {
            editor.serializer.addNodeFilter('table', function (nodes) {
                nodes.forEach(node => {
                    // Check if the table already has a parent with class 'gsc-table__container'
                    if (node.parent && node.parent.name === 'div' && node.parent.attr('class') === 'gsc-table__container') {
                        return; // Skip if already wrapped
                    }

                    // Create a new wrapper div and wrap the table
                    let wrapper = new tinymce.html.Node('div', 1);
                    wrapper.attr('class', 'gsc-table__container');
                    node.wrap(wrapper);
                });
            });
        });
    });
})();

```

## How would I solve this problem now?

So with TipTap what extension points do I have available to me and what would be the best way to achieve the same result?

Is any of this available or the approach I should take?

- Extending/inheriting the current table TipTap extension to override a method when it inserts it into the editor?
- Listen for a specific event to know when a table is added into the editor so I can then amend and wrap it?
- Remove Umbraco’s table extension and have to replace it entirely \*(hoping I dont have to do this)
- Or… ?

---

<div class="post-metadata">

**Author:** ![warren](https://forum.umbraco.com/user_avatar/forum.umbraco.com/warren/32/78_2.png) [@warren](https://forum.umbraco.com/u/warren)\
**Post date:** [July 10, 2025, 3:05pm UTC](https://forum.umbraco.com/t/tiptap-editor-how-do-i-add-a-wrapping-div-when-inserting-the-table/4521/2 "2025-07-10T15:05:32Z")

</div>

Following up with my own notes

## Extending TipTap

> **[Custom extension | Tiptap Editor Docs](https://tiptap.dev/docs/editor/extensions/custom-extensions)**
>
> Customize and create extensions in Tiptap to extend your editor with new features and functionalities. More in the docs!

> **[Extensions | CMS | Umbraco Documentation](https://docs.umbraco.com/umbraco-cms/fundamentals/backoffice/property-editors/built-in-umbraco-property-editors/rich-text-editor/extensions)**
>
> Information on how to work with Tiptap extensions in the rich text editor.

---

<div class="post-metadata">

**Author:** ![warren](https://forum.umbraco.com/user_avatar/forum.umbraco.com/warren/32/78_2.png) [@warren](https://forum.umbraco.com/u/warren)\
**Post date:** [July 10, 2025, 3:12pm UTC](https://forum.umbraco.com/t/tiptap-editor-how-do-i-add-a-wrapping-div-when-inserting-the-table/4521/3 "2025-07-10T15:12:03Z")

</div>

Interestingly TipTap Extensions use a pattern where there is a method called Extend that can be used to change and configure how a TipTap extension works.

## Extending extensions HTML that is rendered

> **[Render HTML - Extend extensions | Tiptap Editor Docs](https://tiptap.dev/docs/editor/extensions/custom-extensions/extend-existing#render-html)**
>
> Every extension has an extend() method, which takes an object with everything you want to change or add to it. | Extend an already existing extension in Tiptap to add new features and functionalities to your editor. More in the docs!

Off to give it a go… will report back with some code if I get it all working

---

<div class="post-metadata">

**Author:** ![warren](https://forum.umbraco.com/user_avatar/forum.umbraco.com/warren/32/78_2.png) [@warren](https://forum.umbraco.com/u/warren)\
**Post date:** [July 10, 2025, 4:13pm UTC](https://forum.umbraco.com/t/tiptap-editor-how-do-i-add-a-wrapping-div-when-inserting-the-table/4521/4 "2025-07-10T16:13:09Z")

</div>

# No luck… ☘

So this is what I have tried, but have not been able to get to working. So just wondering if there is a step or something I may have missed.

### Manifest.ts

```ts
export const manifests: Array<UmbExtensionManifest> = [
    {
        "name": "Tiptap Wrap Tables",
        "alias": "Tiptap.WrapTables",
        "type": "tiptapExtension",
        "meta": {
            "group": "Custom",
            "label": "Wrap Tables in HTML",
            "description": "Wraps tables in a div with class 'gsc-table__container' to allow for custom styling.",
            "icon": "icon-grid-2x2",
        },
        js: () => import('./wrap-table/wrap-table'),
    }
];

```

### wrap-table.ts

```ts
import { UmbTiptapExtensionApiBase } from '@umbraco-cms/backoffice/tiptap';
import { WrapTable } from './wrap-table-extension';

export default class WrapTableExtensionApi extends UmbTiptapExtensionApiBase {
    getTiptapExtensions = () => [WrapTable]; // Add in our custom extended extension
}

```

### wrap-table-extension.ts

```ts
import { createColGroup } from '@tiptap/extension-table';
import type { DOMOutputSpec } from '@tiptap/pm/model';
import { mergeAttributes, UmbTable } from '@umbraco-cms/backoffice/external/tiptap';

// Extend UmbTable which is extending the Tiptap Table extension
// https://github.com/umbraco/Umbraco-CMS/blob/main/src/Umbraco.Web.UI.Client/src/external/tiptap/extensions/tiptap-umb-table.extension.ts#L37
export const WrapTable = UmbTable.extend({

    // https://github.com/ueberdosis/tiptap/blob/next/packages/extension-table/src/table/table.ts#L258C3-L271C5
    renderHTML({ node, HTMLAttributes }) {

        console.log('WRAP TABLE', node.toString(), HTMLAttributes);

         /*
            The first value in the array should be the name of HTML tag.
            If the second element is an object, it’s interpreted as a set of attributes. 
            Any elements after that are rendered as children.

            The number zero (representing a hole) is used to indicate where the content should be inserted.

            https://tiptap.dev/docs/editor/extensions/custom-extensions/extend-existing
        */

        // return ['strong', HTMLAttributes, 0]
        // return ['pre', ['code', HTMLAttributes, 0]]
        // return ['a', mergeAttributes(HTMLAttributes, { rel: this.options.rel }), 0]

        const { colgroup, tableWidth, tableMinWidth } = createColGroup(node, this.options.cellMinWidth)

        const table: DOMOutputSpec = [
            'div',
            { class: 'gsc-table__container' },
            [
                'table',
                mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, {
                    style: tableWidth ? `width: ${tableWidth}` : `min-width: ${tableMinWidth}`,
                }),
                colgroup,
                ['tbody', 0],
            ],
        ];

        return table;
    },
});

```

### Screenshot

My next train of thought was that perhaps I needed to enable it, so jumped into the DataType configuration of the Rich Text Editor and saved it. So I can see that Umbraco has picked up the manifest at least correctly.

 ![The image shows a screenshot of a web development interface with the settings for the Rich Text Editor, highlighting a custom option labeled "Wrap Tables in HTML." (Captioned by AI)](https://forum.umbraco.com/uploads/default/original/2X/9/9a2c227e1932c2bd3fce5cb1b97c7436b4f82185.png)

## What did I miss?

I am not seeing my lovely trusty console.log debug message when I add a table to the editor by using the toolbar button.

---

<div class="post-metadata">

**Author:** ![warren](https://forum.umbraco.com/user_avatar/forum.umbraco.com/warren/32/78_2.png) [@warren](https://forum.umbraco.com/u/warren)\
**Post date:** [July 23, 2025, 7:44am UTC](https://forum.umbraco.com/t/tiptap-editor-how-do-i-add-a-wrapping-div-when-inserting-the-table/4521/5 "2025-07-23T07:44:30Z")

</div>

## Update

Remember to read the docs properly 🙈 the manifest needs to use the property `API` and not `JS`

```ts
export const manifests: Array<UmbExtensionManifest> = [
    {
        "name": "Tiptap Wrap Tables",
        "alias": "Tiptap.WrapTables",
        "type": "tiptapExtension",
        "meta": {
            "group": "Custom",
            "label": "Wrap Tables in HTML",
            "description": "Wraps tables in a div with class 'gsc-table__container' to allow for custom styling.",
            "icon": "icon-grid-2x2",
        },
        //js: () => import('./wrap-table/wrap-table'), // NOPE
        api: () => import('./wrap-table/wrap-table'), 
    }
];

```

---

<div class="post-metadata">

**Author:** ![warren](https://forum.umbraco.com/user_avatar/forum.umbraco.com/warren/32/78_2.png) [@warren](https://forum.umbraco.com/u/warren)\
**Post date:** [July 24, 2025, 10:56am UTC](https://forum.umbraco.com/t/tiptap-editor-how-do-i-add-a-wrapping-div-when-inserting-the-table/4521/6 "2025-07-24T10:56:35Z")

</div>

## Solution

This is what I have, it may not be super perfect but it does what we need to do. I needed to unregister the one Umbraco ships with, which I done in an entrypoint.ts file I had.

### manifest.ts

```ts
export const manifests: Array<UmbExtensionManifest> = [
    {
        "name": "[Consilium] Tiptap Wrap Tables",
        "alias": "Consilium.Tiptap.WrapTables",
        "type": "tiptapExtension",
        "meta": {
            "group": "Consilium",
            "label": "Wrap Tables in HTML",
            "description": "Wraps tables in a div with class 'gsc-table__container' to allow for custom styling.",
            "icon": "icon-grid-2x2",
        },
        api: () => import('./wrap-table/wrap-table'),
    }
];

```

### wrap-table.ts

```ts
import { UmbTiptapExtensionApiBase } from '@umbraco-cms/backoffice/tiptap';
import { WrapTable } from './wrap-table-extension';
import { UmbTableCell, UmbTableHeader, UmbTableRow } from '@umbraco-cms/backoffice/external/tiptap';
import { css } from '@umbraco-cms/backoffice/external/lit';

export default class WrapTableTipTapExtensionApi extends UmbTiptapExtensionApiBase {

    // Umbraco's Table Extenion has 'UmbTableHeader, UmbTableRow, UmbTableCell'
    // We are simply replacing/extending UmbTable with WrapTable
    getTiptapExtensions = () => [WrapTable, UmbTableHeader, UmbTableRow, UmbTableCell];

    // I dont like I need to copy/paste from source
    // Was hoping I could get it from the UmbTiptapTableExtensionApi
    // https://github.com/umbraco/Umbraco-CMS/blob/main/src/Umbraco.Web.UI.Client/src/packages/tiptap/extensions/table/table.tiptap-api.ts#L11

    override getStyles = () => css`
		.tableWrapper {
			margin: 1.5rem 0;

			table {
				border-color: rgba(0, 0, 0, 0.1);
				border-radius: 0.25rem;
				border-spacing: 0;
				box-sizing: border-box;
				max-width: 100%;

				td,
				th {
					box-sizing: border-box;
					position: relative;
					min-width: 50px;
					border: 1px solid var(--uui-color-border);
					padding: 0.5rem;
					text-align: left;
					vertical-align: top;

					&:first-of-type:not(a),
					&:first-of-type:not(a) {
						margin-top: 0;
					}

					p {
						margin: 0;
					}

					p + p {
						margin-top: 0.75rem;
					}
				}

				th {
					font-weight: bold;
				}

				.column-resize-handle {
					cursor: ew-resize;
					cursor: col-resize;
					display: flex;
					position: absolute;
					top: 0;
					bottom: -2px;
					right: -0.25rem;
					width: 0.5rem;
				}

				.column-resize-handle:before {
					margin-left: 0.5rem;
					height: 100%;
					width: 1px;
				}

				.column-resize-handle:before {
					content: '';
				}

				.selectedCell {
					background-color: color-mix(in srgb, var(--uui-color-surface-emphasis) 50%, transparent);
					border-color: var(--uui-color-selected);
				}

				.grip-column,
				.grip-row {
					position: absolute;
					z-index: 10;
					display: flex;
					cursor: pointer;
					align-items: center;
					justify-content: center;
					background-color: rgba(0, 0, 0, 0.05);
					border-color: rgba(0, 0, 0, 0.2);

					uui-symbol-more {
						visibility: hidden;
					}

					&:hover {
						background-color: rgba(0, 0, 0, 0.1);
					}

					&.selected {
						border-color: rgba(0, 0, 0, 0.3);
						background-color: rgba(0, 0, 0, 0.3);
						box-shadow:
							0 0 #0000,
							0 0 #0000,
							0 0 rgba(0, 0, 0, 0.05);
					}

					&:hover uui-symbol-more,
					&.selected uui-symbol-more {
						visibility: visible;
					}
				}

				.grip-column {
					border-left-width: 1px;
					top: -0.75rem;
					left: 0;
					height: 0.75rem;
					width: calc(100% + 1px);
					margin-left: -1px;
				}

				.grip-row {
					border-top-width: 1px;
					flex-direction: column;
					top: 0;
					left: -0.75rem;
					height: calc(100% + 1px);
					width: 0.75rem;
					margin-top: -1px;

					uui-symbol-more {
						transform: rotate(90deg);
					}
				}
			}
		}
	`;
}

```

### wrap-table-extension.ts

```ts
import { createColGroup } from '@tiptap/extension-table';
import type { DOMOutputSpec } from '@tiptap/pm/model';
import { mergeAttributes, UmbTable } from '@umbraco-cms/backoffice/external/tiptap';

// Extend UmbTable which is extending the Tiptap Table extension
// https://tiptap.dev/docs/editor/extensions/custom-extensions/extend-existing
// https://github.com/umbraco/Umbraco-CMS/blob/main/src/Umbraco.Web.UI.Client/src/external/tiptap/extensions/tiptap-umb-table.extension.ts#L37
export const WrapTable = UmbTable.extend({

    // Uses same code from UmbTable which in turn is inhering from Tiptap's Table extension
    // https://github.com/ueberdosis/tiptap/blob/next/packages/extension-table/src/table/table.ts#L258C3-L271C5
    renderHTML({ node, HTMLAttributes }) {
        const { colgroup, tableWidth, tableMinWidth } = createColGroup(node, this.options.cellMinWidth);

        // Filter out the wrapper's class from HTMLAttributes
        const filteredHTMLAttributes = { ...HTMLAttributes };
        if (filteredHTMLAttributes.class) {
            filteredHTMLAttributes.class = filteredHTMLAttributes.class
                .split(' ')
                .filter((cls: string) => cls !== 'gsc-table__container')
                .join(' ');

            if (!filteredHTMLAttributes.class.trim()) {
                delete filteredHTMLAttributes.class;
            }
        }

        // Updated DOMOutpputSpec to include the 'gsc-table__container' class
        const table: DOMOutputSpec = [
            'div',
            { class: 'gsc-table__container' },
            [
                'table',
                mergeAttributes(this.options.HTMLAttributes, filteredHTMLAttributes, {
                    style: tableWidth ? `width: ${tableWidth}` : `min-width: ${tableMinWidth}`,
                }),
                colgroup,
                ['tbody', 0],
            ],
        ];
        return table;
    },

    // https://github.com/ueberdosis/tiptap/blob/next/packages/extension-table/src/table/table.ts#L254C3-L256C5
    parseHTML() {
        return [
            {
                tag: 'div.gsc-table__container',
            }
        ]
    }
});

```

### entrypoint.ts

```ts
import { UmbEntryPointOnInit, UmbEntryPointOnUnload } from '@umbraco-cms/backoffice/extension-api';
import { UMB_AUTH_CONTEXT } from '@umbraco-cms/backoffice/auth';
import { client } from './api/client.gen';

// load up the manifests here
export const onInit: UmbEntryPointOnInit = (_host, _extensionRegistry) => {

  // Will use only to add in Open API config with generated TS OpenAPI HTTPS Client
  // Do the OAuth token handshake stuff
  _host.consumeContext(UMB_AUTH_CONTEXT, async (authContext) => {

    // Get the token info from Umbraco
    const config = authContext?.getOpenApiConfiguration();

    client.setConfig({
      baseUrl: config?.base,
      credentials: config?.credentials,
      auth: () => config?.token(), // Dont need to use the interceptor approach anymore
    });
  });

  // Unregister Umbraco TipTap table extension
  // As we have our own that it extends theirs to wrap with a div with a class
  //_extensionRegistry.unregister('Umb.Tiptap.Table');
  _extensionRegistry.exclude('Umb.Tiptap.Table');
};

export const onUnload: UmbEntryPointOnUnload = (_host, _extensionRegistry) => {
  // Use to do any cleanup work when the entry point is unloaded
};

```

---

<div class="post-metadata">

**Author:** ![system](https://forum.umbraco.com/uploads/default/original/1X/624adeddd330a3d0268a184db47946ca7e82c676.png) [@system](https://forum.umbraco.com/u/system)\
**Post date:** [August 23, 2025, 10:57am UTC](https://forum.umbraco.com/t/tiptap-editor-how-do-i-add-a-wrapping-div-when-inserting-the-table/4521/7 "2025-08-23T10:57:26Z")

</div>

Closed on August 23, 2025, 10:57am UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
