API reference
This page documents everything exported from the main entry @powerduck/md-editor and from the ./react subpath. Signatures are taken directly from the source.
MarkdownEditor
The top-level editor class. Construct it with a container and options.
class MarkdownEditor {
constructor(container: HTMLElement | string, options?: MarkdownEditorOptions);
getValue(): string;
setValue(value: string): void;
getHtml(): string;
renderNow(): void;
setAutoPreview(auto: boolean): void;
setMode(mode: EditorMode): void;
setTheme(theme: EditorTheme): void;
focus(): void;
destroy(): void;
}
constructor(container, options?)
container: HTMLElement | string— a DOM element or CSS selector. If no element matches, throwsMarkdownEditor: mount container not found.options?: MarkdownEditorOptions— see Configuration.
Builds the layout, creates the CodeEditor, wires keyboard shortcuts, and (in complex mode) builds the toolbar and status bar. An initial render and status-bar update run on construction.
getValue(): string
Returns the current Markdown source.
setValue(value: string): void
Replaces the entire document, cancels any pending debounced render, re-renders the preview synchronously, and refreshes the status bar.
getHtml(): string
Renders the current source to HTML via the internal Renderer and returns the string.
renderNow(): void
Cancels any pending debounced render and forces a preview render immediately. Useful when autoPreview is false.
setAutoPreview(auto: boolean): void
Enables or disables automatic preview re-rendering on edit. Enabling immediately renders the current value.
setMode(mode: EditorMode): void
Switches between 'simple' and 'complex'. Destroying and recreating the toolbar and status bar as needed; toggles line numbers. No-op when the mode is unchanged.
setTheme(theme: EditorTheme): void
Sets data-theme on the root element and reconfigures the CodeMirror highlight compartment. Also swaps the toolbar theme-toggle icon between sun and moon.