1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-17 20:51:20 +02:00

replace <br /> to line break (#1322)

This commit is contained in:
Yifeng Wang
2017-10-28 16:41:03 -05:00
committed by Ian Storm Taylor
parent 92c48d9f1d
commit 97002a4835
5 changed files with 13 additions and 7 deletions

View File

@@ -123,8 +123,10 @@ class Leaf extends React.Component {
const { block, node, parent, text, index, leaves } = this.props const { block, node, parent, text, index, leaves } = this.props
// COMPAT: If the text is empty and it's the only child, we need to render a // COMPAT: If the text is empty and it's the only child, we need to render a
// <br/> to get the block to have the proper height. // line break to get the block to have the proper height.
if (text == '' && parent.kind == 'block' && parent.text == '') return <br /> if (text == '' && parent.kind == 'block' && parent.text == '') {
return <span data-slate-empty-block>{'\n'}</span>
}
// COMPAT: If the text is empty otherwise, it's because it's on the edge of // COMPAT: If the text is empty otherwise, it's because it's on the edge of
// an inline void node, so we render a zero-width space so that the // an inline void node, so we render a zero-width space so that the

View File

@@ -81,7 +81,7 @@ class Text extends React.Component {
if (n.node != p.node) return true if (n.node != p.node) return true
// If the node parent is a block node, and it was the last child of the // If the node parent is a block node, and it was the last child of the
// block, re-render to cleanup extra `<br/>` or `\n`. // block, re-render to cleanup extra `\n`.
if (n.parent.kind == 'block') { if (n.parent.kind == 'block') {
const pLast = p.parent.nodes.last() const pLast = p.parent.nodes.last()
const nLast = n.parent.nodes.last() const nLast = n.parent.nodes.last()

View File

@@ -40,11 +40,11 @@ function findDOMPoint(key, offset) {
} }
// COMPAT: For empty blocks with only a single empty text node, we will have // COMPAT: For empty blocks with only a single empty text node, we will have
// rendered a `<br/>` instead of a text node. // rendered a `<span>` with `\n` inside, instead of a text node.
if ( if (
el.childNodes.length == 1 && el.childNodes.length == 1 &&
el.childNodes[0].childNodes.length == 1 && el.childNodes[0].childNodes.length == 1 &&
el.childNodes[0].childNodes[0].tagName == 'BR' el.childNodes[0].childNodes[0].hasAttributes('data-slate-empty-block')
) { ) {
return { node: el.childNodes[0], offset: 0 } return { node: el.childNodes[0], offset: 0 }
} }

View File

@@ -19,7 +19,9 @@ export const output = `
<div style="position:relative"> <div style="position:relative">
<span contenteditable="false" style="pointer-events:none;display:inline-block;width:0;max-width:100%;white-space:nowrap;opacity:0.333"></span> <span contenteditable="false" style="pointer-events:none;display:inline-block;width:0;max-width:100%;white-space:nowrap;opacity:0.333"></span>
<span> <span>
<span><br></span> <span>
<span data-slate-empty-block="true">\n</span>
</span>
</span> </span>
</div> </div>
</div> </div>

View File

@@ -17,7 +17,9 @@ export const output = `
<div style="position:relative"> <div style="position:relative">
<span contenteditable="false" style="pointer-events:none;display:inline-block;width:0;max-width:100%;white-space:nowrap;opacity:0.333"></span> <span contenteditable="false" style="pointer-events:none;display:inline-block;width:0;max-width:100%;white-space:nowrap;opacity:0.333"></span>
<span> <span>
<span><br></span> <span>
<span data-slate-empty-block="true">\n</span>
</span>
</span> </span>
</div> </div>
</div> </div>