Skip to content

Commit 6aa8a1d

Browse files
feat(editor): DP-181154 replacing 0 width tables with full width (#1145)
1 parent e5b5fa6 commit 6aa8a1d

File tree

1 file changed

+16
-1
lines changed
  • packages/dialtone-vue/components/rich_text_editor/extensions/table

1 file changed

+16
-1
lines changed

packages/dialtone-vue/components/rich_text_editor/extensions/table/table.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,29 @@ const createAttribute = (name) => ({
1010
},
1111
});
1212

13+
const createTableStyleAttribute = () => {
14+
let attribute = createAttribute('style');
15+
attribute.renderHTML = (attributes) => {
16+
if (!attributes['style']) return {};
17+
return { ['style']: replaceZeroWidth(attributes['style']) };
18+
}
19+
return attribute;
20+
};
21+
22+
function replaceZeroWidth(style) {
23+
return style.replace(/(?<![a-z-])width\s*:\s*([^;]+);?/gi, (match, value) => {
24+
return /^\s*0\s*[a-z%]*\s*(!important)?\s*$/i.test(value) ? 'width: 100%;' : match;
25+
});
26+
}
27+
1328
export const CustomTable = Table.extend({
1429
addAttributes () {
1530
return {
1631
...this.parent?.(),
1732
border: createAttribute('border'),
1833
cellpadding: createAttribute('cellpadding'),
1934
cellspacing: createAttribute('cellspacing'),
20-
style: createAttribute('style'),
35+
style: createTableStyleAttribute(),
2136
};
2237
},
2338

0 commit comments

Comments
 (0)