Skip to content
This repository was archived by the owner on May 5, 2021. It is now read-only.

Commit e0414f7

Browse files
sebgeelendmo-odoo
authored andcommitted
[FIX] Underline: always put <u> as deep as possible in the rendered DOM
The underline style (`text-decoration: underline;`) can be broken if a child element has a css `display: inline-block;`. ( see W3C spec https://www.w3.org/TR/CSS21/text.html#lining-striking-props ). To combat this we have ton ensure that a `<u>` tag is as deep a possible in the rendered DOM, so he cannot contain other child element expect Characters. + Add unit tests
1 parent b4c93c3 commit e0414f7

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { Format } from '../../core/src/Format';
2+
import { ModifierLevel } from '../../core/src/Modifier';
23

34
export class UnderlineFormat extends Format {
45
htmlTag = 'U';
6+
level = ModifierLevel.LOW;
57
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import { describePlugin } from '../../utils/src/testUtils';
2+
import { BasicEditor } from '../../bundle-basic-editor/BasicEditor';
3+
import JWEditor from '../../core/src/JWEditor';
4+
import { Constructor } from '../../utils/src/utils';
5+
import { Format } from '../../core/src/Format';
6+
import { UnderlineFormat } from '../src/UnderlineFormat';
7+
import { SpanFormat } from '../../plugin-span/src/SpanFormat';
8+
import { Underline } from '../src/Underline';
9+
import { Inline } from '../../plugin-inline/src/Inline';
10+
11+
const toggleFormat = async (editor: JWEditor, FormatClass: Constructor<Format>): Promise<void> => {
12+
await editor.execCommand<Inline>('toggleFormat', {
13+
FormatClass: FormatClass,
14+
});
15+
};
16+
describePlugin(Underline, testEditor => {
17+
describe('underline format', () => {
18+
it('should keep formats in order if not touched', async () => {
19+
await testEditor(BasicEditor, {
20+
contentBefore: '<span><u>g[]ga</u></span>',
21+
contentAfter: '<span><u>g[]ga</u></span>',
22+
});
23+
});
24+
it('should keep formats in order if not touched (2)', async () => {
25+
await testEditor(BasicEditor, {
26+
contentBefore: '<u><span>g[]ga</span></u>',
27+
contentAfter: '<u><span>g[]ga</span></u>',
28+
});
29+
});
30+
it('should put underline inside a span', async () => {
31+
await testEditor(BasicEditor, {
32+
contentBefore: 'a<span>b[cd]e</span>f',
33+
stepFunction: async (editor: JWEditor) => {
34+
await toggleFormat(editor, UnderlineFormat);
35+
},
36+
contentAfter: 'a<span>b[<u>cd]</u>e</span>f',
37+
});
38+
});
39+
it('should put underline inside a span (2)', async () => {
40+
await testEditor(BasicEditor, {
41+
contentBefore: 'a[<span>bcde]</span>f',
42+
stepFunction: async (editor: JWEditor) => {
43+
await toggleFormat(editor, UnderlineFormat);
44+
},
45+
contentAfter: 'a[<span><u>bcde]</u></span>f',
46+
});
47+
});
48+
it('should put underline inside a span (3)', async () => {
49+
await testEditor(BasicEditor, {
50+
contentBefore: '[a<span>bcd]e</span>f',
51+
stepFunction: async (editor: JWEditor) => {
52+
await toggleFormat(editor, UnderlineFormat);
53+
},
54+
contentAfter: '<u>[a</u><span><u>bcd]</u>e</span>f',
55+
});
56+
});
57+
it('should put underline inside a span (4)', async () => {
58+
await testEditor(BasicEditor, {
59+
contentBefore: '[a<span>bc<span>xx</span>de</span>f]',
60+
stepFunction: async (editor: JWEditor) => {
61+
await toggleFormat(editor, UnderlineFormat);
62+
},
63+
contentAfter:
64+
'<u>[a</u><span><u>bc</u><span><u>xx</u></span><u>de</u></span><u>f]</u>',
65+
});
66+
});
67+
it('should put underline inside a span (5)', async () => {
68+
await testEditor(BasicEditor, {
69+
contentBefore: '<u>ab[cd]ef</u>',
70+
stepFunction: async (editor: JWEditor) => {
71+
await toggleFormat(editor, SpanFormat);
72+
},
73+
contentAfter: '<u>ab[</u><span><u>cd]</u></span><u>ef</u>',
74+
});
75+
});
76+
});
77+
});

0 commit comments

Comments
 (0)