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

Commit 2495204

Browse files
committed
[FIX] LineBreak: List item empty with br are displayed as twice line
The mobile versions represent the <br> in li as making 2 lines and not just one (unlike browsers). The implementation of linebreaks needs to change. The invisible terminal BR must be an invisible character so that the previous BR is displayed but respecting more the W3 rules.
1 parent a7ba7c3 commit 2495204

File tree

5 files changed

+26
-38
lines changed

5 files changed

+26
-38
lines changed

examples/demo/demo.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ body {
33
height:100vh;
44
}
55

6+
* {
7+
border-top: 3px black solid;
8+
margin: 0;
9+
}
10+
611
jw-editor {
712
display: block;
813
height: 100vh;

examples/demo/demo.xml

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,37 +17,6 @@ neologisms such as "galumphing" and "chortle".
1717

1818
<h1>Table examples</h1>
1919

20-
<table class="mondrian" cellspacing=0>
21-
<tbody>
22-
<tr style="">
23-
<td style="border: 4px solid black; margin: 0; background-color: #3c4681;" colspan="2" rowspan="2"><br></td>
24-
<td width="50%" height="5%" style="border: 4px solid black; margin: 0; background-color: #d42627;" colspan="4"><br></td>
25-
<td style="border: 4px solid black; margin: 0;" rowspan="4"><br></td>
26-
</tr>
27-
<tr>
28-
<td style="border: 4px solid black; margin: 0; background-color: #fcd202;" colspan="2" rowspan="2"><br></td>
29-
<td style="border: 4px solid black; margin: 0;" width="15%" colspan="2" rowspan="2"><br></td>
30-
</tr>
31-
<tr>
32-
<td style="border: 4px solid black; margin: 0;" width="25%" rowspan="3"><br></td>
33-
<td style="border: 4px solid black; margin: 0;" width="8%" height="40%"><br></td>
34-
</tr>
35-
<tr>
36-
<td width="15%" style="border: 4px solid black; margin: 0; background-color: #3c4681;" colspan="2" rowspan="2"><br></td>
37-
<td style="border: 4px solid black; margin: 0; background-color: #d42627;" colspan="3"><br></td>
38-
</tr>
39-
<tr>
40-
<td style="border: 4px solid black; margin: 0;" colspan="2" rowspan="2"><br></td>
41-
<td style="border: 4px solid black; margin: 0; background-color: #3c4681;
42-
vertical-align: bottom; text-align: right; color: #7166ab;" colspan="2" rowspan="2"><sub><i>© Piet
43-
Mondrian</i></sub></td>
44-
</tr>
45-
<tr>
46-
<td height="5%" style="border: 4px solid black; margin: 0; background-color: #fcd202;" colspan="3"><br></td>
47-
</tr>
48-
</tbody>
49-
</table>
50-
5120
<p><br></p>
5221

5322
<table>
@@ -132,7 +101,14 @@ neologisms such as "galumphing" and "chortle".
132101
</li>
133102
<li style="list-style: none;">
134103
<ol>
135-
<li>1.2.1</li>
104+
<li>A 2 br<br><br></li>
105+
<li>A br + char<br>&#8203;</li>
106+
<li>B 3 br<br><br><br></li>
107+
<li>B 2 br + char<br><br>&#8203;</li>
108+
<li><p class="toto">P B 3 br<br><br><br></p></li>
109+
<li><p class="toto">P B 2 br + char<br><br>&#8203;</p></li>
110+
<li>B 4 br<br><br><br><br></li>
111+
<li>B 3 br + char<br><br><br>&#8203;</li>
136112
<li>1.2.2</li>
137113
<li>1.2.3</li>
138114
<li style="list-style: none;">

packages/plugin-linebreak/src/LineBreakDomObjectRenderer.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ export class LineBreakDomObjectRenderer extends NodeRenderer<DomObject> {
2222
worker.locate([node], br);
2323
if (!node.nextSibling()) {
2424
// If a LineBreakNode has no next sibling, it must be rendered
25-
// as two BRs in order for it to be visible.
26-
const br2 = { tag: 'BR' };
27-
const domObject = { children: [br, br2] };
28-
worker.locate([node], br2);
25+
// as a BR and a placeholder invisible char in order for it to be
26+
// visible.
27+
const invisible: DomObject = { text: '\u200B' };
28+
const domObject = { children: [br, invisible] };
29+
worker.locate([node], invisible);
2930
return domObject;
3031
}
3132
return br;

packages/plugin-linebreak/src/LineBreakXmlDomParser.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ export class LineBreakXmlDomParser extends AbstractParser<Node> {
1010
engine: XmlDomParsingEngine;
1111

1212
predicate = (item: Node): boolean => {
13-
return item instanceof Element && nodeName(item) === 'BR';
13+
return (
14+
(item instanceof Element && nodeName(item) === 'BR') ||
15+
(item instanceof Text &&
16+
item.textContent === '\u200B' &&
17+
!item.nextSibling &&
18+
(!item.previousSibling || nodeName(item.previousSibling) === 'BR'))
19+
);
1420
};
1521

1622
async parse(item: Element): Promise<LineBreakNode[]> {

packages/plugin-renderer-dom-object/src/DomObjectRenderingEngine.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ export class DomObjectRenderingEngine extends RenderingEngine<DomObject> {
270270
async renderChildren(node: VNode): Promise<Array<DomObject | VNode>> {
271271
const children: Array<DomObject | VNode> = node.children();
272272
if (!children.length && this.editor.mode.is(node, RuleProperty.ALLOW_EMPTY) !== true) {
273-
children.push({ tag: 'BR' });
273+
children.push({ text: '\u200B' });
274274
}
275275
return children;
276276
}

0 commit comments

Comments
 (0)