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,
|
||||
__size: 1,
|
||||
__style: '',
|
||||
__textFormat: 0,
|
||||
__textStyle: '',
|
||||
__type: 'paragraph',
|
||||
});
|
||||
@ -1149,6 +1150,7 @@ describe('LexicalEditor tests', () => {
|
||||
__prev: null,
|
||||
__size: 1,
|
||||
__style: '',
|
||||
__textFormat: 0,
|
||||
__textStyle: '',
|
||||
__type: 'paragraph',
|
||||
});
|
||||
|
@ -76,6 +76,7 @@ describe('LexicalEditorState tests', () => {
|
||||
__prev: null,
|
||||
__size: 1,
|
||||
__style: '',
|
||||
__textFormat: 0,
|
||||
__textStyle: '',
|
||||
__type: 'paragraph',
|
||||
});
|
||||
@ -111,7 +112,7 @@ describe('LexicalEditorState tests', () => {
|
||||
});
|
||||
|
||||
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.
|
||||
exportDOM(editor: LexicalEditor): DOMExportOutput {
|
||||
let {element} = super.exportDOM(editor);
|
||||
const originalElementName = (element?.nodeName || '').toLowerCase()
|
||||
invariant(
|
||||
element !== null && isHTMLElement(element),
|
||||
'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,
|
||||
// even if it's semantically incorrect to have to resort to using
|
||||
// <b>, <u>, <s>, <i> elements.
|
||||
if (this.hasFormat('bold')) {
|
||||
element = wrapElementWith(element, 'b');
|
||||
if (this.hasFormat('bold') && originalElementName !== 'strong') {
|
||||
element = wrapElementWith(element, 'strong');
|
||||
}
|
||||
if (this.hasFormat('italic')) {
|
||||
element = wrapElementWith(element, 'em');
|
||||
|
@ -53,6 +53,7 @@ describe('LexicalParagraphNode tests', () => {
|
||||
direction: null,
|
||||
id: '',
|
||||
inset: 0,
|
||||
textFormat: 0,
|
||||
textStyle: '',
|
||||
type: 'paragraph',
|
||||
version: 1,
|
||||
|
@ -839,7 +839,7 @@ describe('LexicalTextNode tests', () => {
|
||||
paragraph.append(textNode);
|
||||
|
||||
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,
|
||||
__size: 1,
|
||||
__style: '',
|
||||
__textFormat: 0,
|
||||
__textStyle: '',
|
||||
__type: 'paragraph',
|
||||
});
|
||||
|
Reference in New Issue
Block a user