Integration
Editor Commands
Format text, insert content, import/export formats, and drive the editor programmatically.
Lextrix exposes imperative methods for formatting, inserting content, serializing, and querying document state. Use these when building custom toolbars or automating edits.
Formatting selection
editor.format('bold', true);
editor.format('italic', true);
editor.format('header', 2);
editor.format('list', 'bullet');Insert and delete
editor.insertText(0, 'Preface: ');
editor.deleteText(0, 8);
editor.insertEmbed(10, 'image', { url: 'https://example.com/photo.jpg' });Selection
editor.setSelection(0, 5);
editor.getSelection(); // { index, length } or null
editor.focus();Content operations
editor.setContents([
{ insert: 'Title\n', attributes: { header: 1 } },
{ insert: 'Body paragraph.\n' },
]);
editor.updateContents([
{ retain: 6 },
{ insert: 'Updated', attributes: { bold: true } },
]);
const length = editor.getLength();
const text = editor.getText(0, length);Serialization (2.x)
// Import
editor.importContent('# Hello\n\n**world**', 'markdown');
editor.importContent('<p>Hi</p>', 'html');
// Export
editor.exportContent('html');
editor.exportContent('markdown');
editor.exportContent('mdx');
editor.exportContent('json');
// Partial range
editor.exportContent({ format: 'html', index: 0, length: 100 });
// List registered formats
editor.listExportFormats();Prefer importContent / exportContent over getSemanticHTML() and manual clipboard conversion.
History
When the history module is enabled (default in full bundle):
editor.history.undo();
editor.history.redo();Events
editor.on('text-change', (changeSet, oldChangeSet, source) => {
// source: 'user' | 'api' | 'silent'
});
editor.on('selection-change', (range, oldRange, source) => {});Next steps
- Serialization — headless host, custom serializers, limitations
- Plugin System — wrap commands in custom modules
- API reference on GitHub