Skip to main content

BoldExtension

Summary

When added to your editor it will provide the toggleBold command which makes the text under the cursor / or at the provided position range bold.

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 { BoldExtension } from 'remirror/extensions';

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

Examples

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

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

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

const BoldButton = () => {
const commands = useCommands();
const active = useActive(true);
return (
<button
onMouseDown={(event) => event.preventDefault()}
onClick={() => commands.toggleBold()}
className={cx(active.bold() && 'active')}
>
Bold
</button>
);
};

const Basic = (): JSX.Element => {
const { manager, state, onChange } = useRemirror({
extensions: extensions,
content: '<p>Text in <b>bold</b></p>',
stringHandler: htmlToProsemirrorNode,
});

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

export default Basic;

API