Skip to content

How to deal with linebreaks when convertig a marked text to a block elmenet (headline) #5761

Answered by lanwin
lanwin asked this question in Q&A
Discussion options

You must be logged in to vote

For anyone else having this problem, the following code did it.

Transforms.setNodes(editor, { type: "h4" }, { mode: 'lowest', voids: false, split: true });

const after = Editor.after(editor, editor.selection);
if (after) {
  const [nodeAfter, pathAfter] = Editor.node(editor, after);
  if (Text.isText(nodeAfter) && nodeAfter.text.startsWith('\n'))
	Transforms.delete(editor, { at: { path: pathAfter, offset: 0 }, distance: 1 });
}
const before = Editor.before(editor, editor.selection);
if (before) {
  const [nodeBefore, pathBefore] = Editor.node(editor, before);
  if (Text.isText(nodeBefore) && nodeBefore.text.endsWith('\n'))
	Transforms.delete(editor, { at: { path: pathBefore, offset: node…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@lanwin
Comment options

@gerardnico
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by lanwin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants