Basic Usage
Creating an Editor
The simplest way to create an editor:
ts
import { Marzipan } from '@pinkpixel/marzipan';
const [editor] = new Marzipan('#my-textarea', {
placeholder: 'Start typing...',
toolbar: true,
});
Getting & Setting Content
ts
// Get current content
const content = editor.getValue();
// Set new content
editor.setValue('# New Content\n\nHello world!');
Working with HTML
ts
// Get rendered HTML (with Marzipan classes)
const html = editor.getRenderedHTML();
// Get clean HTML (no Marzipan markup)
const cleanHtml = editor.getCleanHTML();
Display Modes
ts
// Toggle between edit and preview modes
editor.showPreviewMode(true); // Preview only
editor.showPreviewMode(false); // Edit mode
// Show/hide plain textarea (no overlay)
editor.showPlainTextarea(true); // Plain textarea
editor.showPlainTextarea(false); // Overlay preview
Statistics
ts
// Show stats panel
editor.showStats(true);
// Custom stats formatter
new Marzipan('#editor', {
showStats: true,
statsFormatter: ({ words, chars, lines, line, column }) => {
return `${words} words • ${chars} chars • Line ${line}:${column}`;
}
});
More Examples
Check out the API Reference for complete documentation.
Marzipan