Skip to main content

HardBreakExtension

Summary

An extension which provides the functionality for inserting a hardBreak <br /> tag into the editor.

It will automatically exit when used inside a codeClock. To prevent problems occurring when the codeblock is the last node in the doc, you should add the TrailingNodeExtension which automatically appends a paragraph node to the last node.

Usage

Installation

This extension is installed for you when you install the main remirror package.

You can use the imports in the following way:

import { HardBreakExtension } from 'remirror/extensions';

The extension is provided by the @remirror/extension-hard-break package.

Examples

Source code
import 'remirror/styles/all.css';

import { htmlToProsemirrorNode } from 'remirror';
import { HardBreakExtension } from 'remirror/extensions';
import { Remirror, ThemeProvider, useCommands, useRemirror } from '@remirror/react';

const extensions = () => [new HardBreakExtension()];

const HardBreakButton = () => {
const commands = useCommands();
return (
<button
onMouseDown={(event) => event.preventDefault()}
onClick={() => commands.insertHardBreak()}
>
Insert
</button>
);
};

const Basic = (): JSX.Element => {
const { manager, state, onChange } = useRemirror({
extensions: extensions,
content: '<p>Text with <br />hard break</p>',
stringHandler: htmlToProsemirrorNode,
});

return (
<ThemeProvider>
<Remirror
manager={manager}
autoFocus
onChange={onChange}
initialContent={state}
autoRender='end'
>
<HardBreakButton />
</Remirror>
</ThemeProvider>
);
};

export default Basic;

API