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

Commit 0ea4c0d

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 0ea4c0d

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
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: 1px gray dotted;
8+
margin: 0;
9+
}
10+
611
jw-editor {
712
display: block;
813
height: 100vh;

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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ 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 && item.textContent === '\u200B')
16+
);
1417
};
1518

1619
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)