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:
committed by
Ian Storm Taylor
parent
92c48d9f1d
commit
97002a4835
@@ -123,8 +123,10 @@ class Leaf extends React.Component {
|
||||
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
|
||||
// <br/> to get the block to have the proper height.
|
||||
if (text == '' && parent.kind == 'block' && parent.text == '') return <br />
|
||||
// line break to get the block to have the proper height.
|
||||
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
|
||||
// an inline void node, so we render a zero-width space so that the
|
||||
|
@@ -81,7 +81,7 @@ class Text extends React.Component {
|
||||
if (n.node != p.node) return true
|
||||
|
||||
// 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') {
|
||||
const pLast = p.parent.nodes.last()
|
||||
const nLast = n.parent.nodes.last()
|
||||
|
@@ -40,11 +40,11 @@ function findDOMPoint(key, offset) {
|
||||
}
|
||||
|
||||
// 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 (
|
||||
el.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 }
|
||||
}
|
||||
|
@@ -19,7 +19,9 @@ export const output = `
|
||||
<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>
|
||||
<span><br></span>
|
||||
<span>
|
||||
<span data-slate-empty-block="true">\n</span>
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
@@ -17,7 +17,9 @@ export const output = `
|
||||
<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>
|
||||
<span><br></span>
|
||||
<span>
|
||||
<span data-slate-empty-block="true">\n</span>
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user