Loading...
Loading...
Install, create the editor, and display saved content.
<!-- 1. Include CSS -->
<link href="https://cdn.jsdelivr.net/npm/suneditor@3.0.0/dist/css/suneditor.min.css" rel="stylesheet">
<!-- 2. Include JS -->
<script src="https://cdn.jsdelivr.net/npm/suneditor@3.0.0/dist/suneditor.min.js"><\/script>
<!-- 3. Create Textarea -->
<textarea id="my-editor"></textarea>
<!-- 4. Create Editor -->
<script>
const editor = SUNEDITOR.create("my-editor", {
value: "<p>Hello SunEditor</p>",
buttonList: [
["undo", "redo"],
["bold", "italic", "underline"],
["link", "image"]
]
});
<\/script>When displaying HTML generated by the editor, CSS and class names are required.
<!-- 1. SunEditor contents CSS required -->
<link href="https://cdn.jsdelivr.net/npm/suneditor@3.0.0/dist/css/suneditor-contents.min.css" rel="stylesheet">
<!-- 2. sun-editor-editable Wrap with class -->
<div class="sun-editor-editable">
<!-- HTML from editor.getContents() -->
</div>The editor instance exposes a $ object β a dependency bag containing all internal subsystems (L1βL2βL3).
const editor = SunEditor.create('textarea', { /* options */ });
// $ β dependency bag (all internals)
editor.$.selection // Selection handler
editor.$.format // Block formatting
editor.$.history // Undo/Redo stack
// ... and more