fix: TipTap button style extraction when parsing HTML

Added getAttrs functions to parseHTML in tiptap-button-extension.ts.
Now properly extracts text/href/style from DOM elements:
- data-button: extracts from data-text, data-href, data-style
- a.button: extracts text/href, defaults to solid style
- a.button-outline: extracts text/href, defaults to outline style

This fixes the issue where buttons appeared unstyled (outline
instead of solid) when editing a card that contained buttons.
This commit is contained in:
Dwindi Ramadhana
2026-01-01 23:48:06 +07:00
parent 0a33ba0401
commit 1ce99e2bb6

View File

@@ -39,12 +39,27 @@ export const ButtonExtension = Node.create<ButtonOptions>({
return [ return [
{ {
tag: 'a[data-button]', tag: 'a[data-button]',
getAttrs: (node: HTMLElement) => ({
text: node.getAttribute('data-text') || node.textContent || 'Click Here',
href: node.getAttribute('data-href') || node.getAttribute('href') || '#',
style: node.getAttribute('data-style') || 'solid',
}),
}, },
{ {
tag: 'a.button', tag: 'a.button',
getAttrs: (node: HTMLElement) => ({
text: node.textContent || 'Click Here',
href: node.getAttribute('href') || '#',
style: 'solid',
}),
}, },
{ {
tag: 'a.button-outline', tag: 'a.button-outline',
getAttrs: (node: HTMLElement) => ({
text: node.textContent || 'Click Here',
href: node.getAttribute('href') || '#',
style: 'outline',
}),
}, },
]; ];
}, },