Docs › Saving and output
HTML source view
View and edit the HTML with the source button.
The source button turns the editing area into an HTML code view. Use it to fix tags by hand or to drop in HTML made elsewhere. Press it again and the edited HTML goes back into the editor.
Try it
Notice
We are closed this Saturday. See the website for details.
Code for this demo
createEditor('#editor', {
toolbar: 'heading | bold italic | link | source',
});Using it
- Shortcut: Ctrl+Shift+U opens and closes it.
- The HTML is shown indented, with tags and attributes colored.
- Tab inserts two spaces instead of moving focus.
- On close, the HTML is filtered through the allow-list (no
<script>, noon*attributes) and applied as an undoable change. - Closing without edits leaves the content untouched, with no undo step.
- While it is open, only
source,preview,print,fullscreen,help,undoandredowork.
The toolbar item is source, in the ⋯ menu of the board (default) and full presets. In code, editor.toggleSource() opens and closes it, and the source event reports open (true) or closed (false).
editor.on('source', (open) => {
saveButton.disabled = open; // close the code view before saving
});
editor.toggleSource(true);Calling getHTML() while the code view is open returns the filtered HTML from the code view, so nothing is lost.
Options
| Name | Type | Default | Description |
|---|---|---|---|
source | toolbar item | - | Open or close the HTML code view |
toggleSource(open?) | method | - | Open (true), close (false) or toggle (omitted) |
source | event | - | true when opened, false when closed |
allowedTags | string[] | - | Allowed tags (Security) |
allowedAttributes | object | - | Allowed attributes per tag |