Skip to content

Commit 77a8861

Browse files
committed
Lexical: Fixed double-bold text, updated tests
Double bold was due to text field exporting wrapping the output in <b> tags when the main tag would already be strong.
1 parent 8b062d4 commit 77a8861

File tree

7 files changed

+12
-6
lines changed

7 files changed

+12
-6
lines changed

resources/js/wysiwyg/lexical/core/__tests__/unit/LexicalEditor.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,7 @@ describe('LexicalEditor tests', () => {
10691069
__prev: null,
10701070
__size: 1,
10711071
__style: '',
1072+
__textFormat: 0,
10721073
__textStyle: '',
10731074
__type: 'paragraph',
10741075
});
@@ -1149,6 +1150,7 @@ describe('LexicalEditor tests', () => {
11491150
__prev: null,
11501151
__size: 1,
11511152
__style: '',
1153+
__textFormat: 0,
11521154
__textStyle: '',
11531155
__type: 'paragraph',
11541156
});

resources/js/wysiwyg/lexical/core/__tests__/unit/LexicalEditorState.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ describe('LexicalEditorState tests', () => {
7676
__prev: null,
7777
__size: 1,
7878
__style: '',
79+
__textFormat: 0,
7980
__textStyle: '',
8081
__type: 'paragraph',
8182
});
@@ -111,7 +112,7 @@ describe('LexicalEditorState tests', () => {
111112
});
112113

113114
expect(JSON.stringify(editor.getEditorState().toJSON())).toEqual(
114-
`{"root":{"children":[{"children":[{"detail":0,"format":0,"mode":"normal","style":"","text":"Hello world","type":"text","version":1}],"direction":null,"type":"paragraph","version":1,"id":"","alignment":"","inset":0,"textStyle":""}],"direction":null,"type":"root","version":1}}`,
115+
`{"root":{"children":[{"children":[{"detail":0,"format":0,"mode":"normal","style":"","text":"Hello world","type":"text","version":1}],"direction":null,"type":"paragraph","version":1,"id":"","alignment":"","inset":0,"textFormat":0,"textStyle":""}],"direction":null,"type":"root","version":1}}`,
115116
);
116117
});
117118

resources/js/wysiwyg/lexical/core/__tests__/unit/LexicalSerialization.test.ts

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

resources/js/wysiwyg/lexical/core/nodes/LexicalTextNode.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,7 @@ export class TextNode extends LexicalNode {
620620
// HTML content and not have the ability to use CSS classes.
621621
exportDOM(editor: LexicalEditor): DOMExportOutput {
622622
let {element} = super.exportDOM(editor);
623+
const originalElementName = (element?.nodeName || '').toLowerCase()
623624
invariant(
624625
element !== null && isHTMLElement(element),
625626
'Expected TextNode createDOM to always return a HTMLElement',
@@ -649,8 +650,8 @@ export class TextNode extends LexicalNode {
649650
// This is the only way to properly add support for most clients,
650651
// even if it's semantically incorrect to have to resort to using
651652
// <b>, <u>, <s>, <i> elements.
652-
if (this.hasFormat('bold')) {
653-
element = wrapElementWith(element, 'b');
653+
if (this.hasFormat('bold') && originalElementName !== 'strong') {
654+
element = wrapElementWith(element, 'strong');
654655
}
655656
if (this.hasFormat('italic')) {
656657
element = wrapElementWith(element, 'em');

resources/js/wysiwyg/lexical/core/nodes/__tests__/unit/LexicalParagraphNode.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ describe('LexicalParagraphNode tests', () => {
5353
direction: null,
5454
id: '',
5555
inset: 0,
56+
textFormat: 0,
5657
textStyle: '',
5758
type: 'paragraph',
5859
version: 1,

resources/js/wysiwyg/lexical/core/nodes/__tests__/unit/LexicalTextNode.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ describe('LexicalTextNode tests', () => {
839839
paragraph.append(textNode);
840840

841841
const html = $generateHtmlFromNodes($getEditor(), null);
842-
expect(html).toBe('<p><u><em><b><code spellcheck="false"><strong>hello</strong></code></b></em></u></p>');
842+
expect(html).toBe('<p><u><em><strong><code spellcheck="false"><strong>hello</strong></code></strong></em></u></p>');
843843
});
844844
});
845845

resources/js/wysiwyg/lexical/table/__tests__/unit/LexicalTableSelection.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ describe('table selection', () => {
123123
__prev: null,
124124
__size: 1,
125125
__style: '',
126+
__textFormat: 0,
126127
__textStyle: '',
127128
__type: 'paragraph',
128129
});

0 commit comments

Comments
 (0)