mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-06-20 08:42:15 +03:00
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.
This commit is contained in:
@ -1069,6 +1069,7 @@ describe('LexicalEditor tests', () => {
|
|||||||
__prev: null,
|
__prev: null,
|
||||||
__size: 1,
|
__size: 1,
|
||||||
__style: '',
|
__style: '',
|
||||||
|
__textFormat: 0,
|
||||||
__textStyle: '',
|
__textStyle: '',
|
||||||
__type: 'paragraph',
|
__type: 'paragraph',
|
||||||
});
|
});
|
||||||
@ -1149,6 +1150,7 @@ describe('LexicalEditor tests', () => {
|
|||||||
__prev: null,
|
__prev: null,
|
||||||
__size: 1,
|
__size: 1,
|
||||||
__style: '',
|
__style: '',
|
||||||
|
__textFormat: 0,
|
||||||
__textStyle: '',
|
__textStyle: '',
|
||||||
__type: 'paragraph',
|
__type: 'paragraph',
|
||||||
});
|
});
|
||||||
|
@ -76,6 +76,7 @@ describe('LexicalEditorState tests', () => {
|
|||||||
__prev: null,
|
__prev: null,
|
||||||
__size: 1,
|
__size: 1,
|
||||||
__style: '',
|
__style: '',
|
||||||
|
__textFormat: 0,
|
||||||
__textStyle: '',
|
__textStyle: '',
|
||||||
__type: 'paragraph',
|
__type: 'paragraph',
|
||||||
});
|
});
|
||||||
@ -111,7 +112,7 @@ describe('LexicalEditorState tests', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
expect(JSON.stringify(editor.getEditorState().toJSON())).toEqual(
|
expect(JSON.stringify(editor.getEditorState().toJSON())).toEqual(
|
||||||
`{"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}}`,
|
`{"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}}`,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
File diff suppressed because one or more lines are too long
@ -620,6 +620,7 @@ export class TextNode extends LexicalNode {
|
|||||||
// HTML content and not have the ability to use CSS classes.
|
// HTML content and not have the ability to use CSS classes.
|
||||||
exportDOM(editor: LexicalEditor): DOMExportOutput {
|
exportDOM(editor: LexicalEditor): DOMExportOutput {
|
||||||
let {element} = super.exportDOM(editor);
|
let {element} = super.exportDOM(editor);
|
||||||
|
const originalElementName = (element?.nodeName || '').toLowerCase()
|
||||||
invariant(
|
invariant(
|
||||||
element !== null && isHTMLElement(element),
|
element !== null && isHTMLElement(element),
|
||||||
'Expected TextNode createDOM to always return a HTMLElement',
|
'Expected TextNode createDOM to always return a HTMLElement',
|
||||||
@ -649,8 +650,8 @@ export class TextNode extends LexicalNode {
|
|||||||
// This is the only way to properly add support for most clients,
|
// This is the only way to properly add support for most clients,
|
||||||
// even if it's semantically incorrect to have to resort to using
|
// even if it's semantically incorrect to have to resort to using
|
||||||
// <b>, <u>, <s>, <i> elements.
|
// <b>, <u>, <s>, <i> elements.
|
||||||
if (this.hasFormat('bold')) {
|
if (this.hasFormat('bold') && originalElementName !== 'strong') {
|
||||||
element = wrapElementWith(element, 'b');
|
element = wrapElementWith(element, 'strong');
|
||||||
}
|
}
|
||||||
if (this.hasFormat('italic')) {
|
if (this.hasFormat('italic')) {
|
||||||
element = wrapElementWith(element, 'em');
|
element = wrapElementWith(element, 'em');
|
||||||
|
@ -53,6 +53,7 @@ describe('LexicalParagraphNode tests', () => {
|
|||||||
direction: null,
|
direction: null,
|
||||||
id: '',
|
id: '',
|
||||||
inset: 0,
|
inset: 0,
|
||||||
|
textFormat: 0,
|
||||||
textStyle: '',
|
textStyle: '',
|
||||||
type: 'paragraph',
|
type: 'paragraph',
|
||||||
version: 1,
|
version: 1,
|
||||||
|
@ -839,7 +839,7 @@ describe('LexicalTextNode tests', () => {
|
|||||||
paragraph.append(textNode);
|
paragraph.append(textNode);
|
||||||
|
|
||||||
const html = $generateHtmlFromNodes($getEditor(), null);
|
const html = $generateHtmlFromNodes($getEditor(), null);
|
||||||
expect(html).toBe('<p><u><em><b><code spellcheck="false"><strong>hello</strong></code></b></em></u></p>');
|
expect(html).toBe('<p><u><em><strong><code spellcheck="false"><strong>hello</strong></code></strong></em></u></p>');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -123,6 +123,7 @@ describe('table selection', () => {
|
|||||||
__prev: null,
|
__prev: null,
|
||||||
__size: 1,
|
__size: 1,
|
||||||
__style: '',
|
__style: '',
|
||||||
|
__textFormat: 0,
|
||||||
__textStyle: '',
|
__textStyle: '',
|
||||||
__type: 'paragraph',
|
__type: 'paragraph',
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user