Editing the HTML
The Source code button (code) opens the document’s HTML for editing. Saving reads it back
through the editor’s schema, with the same cleanup and checks as any HTML the editor loads, so the
dialog can’t put a script or a javascript: link into the document. With the fullpagehtml plugin
it shows the whole page, its head included.
The code editor
Section titled “The code editor”With the advcode plugin, the same button opens the HTML in a code editor:
createEditor({ element, plugins: ['advcode'] });- the HTML laid out with one block per line, nested ones indented, opened where the cursor is in the text;
- colors for HTML, and for CSS and JavaScript inside it;
- matching brackets and tags, folding (the arrows by the line numbers), tags closed as you type, several cursors (Ctrl+click), a rectangular selection (Alt+drag);
- search and replace: the magnifier, or Ctrl+F;
- a smaller or larger text, wrapped or long lines, and full screen, from the buttons above the code;
- the colors of the editor’s theme, light or dark.
| Keys | What they do |
|---|---|
| Ctrl+F | find and replace |
| Ctrl+D | select the next occurrence of the selection |
| Ctrl+Alt+G | go to a line |
| Ctrl+/ | comment the line out, or back in |
| Alt+↑ / ↓ | move the line up or down |
| Ctrl+Shift+K | delete the line |
| Ctrl+Space | suggest a tag or attribute |
| Ctrl+S | save and close |
| Esc | close a search or several cursors; then the dialog |
On a Mac, Cmd takes the place of Ctrl (but not in Ctrl+Space). Tab moves to the buttons, as everywhere else, so a keyboard never gets stuck in the code; Ctrl+] and Ctrl+[ indent.
The code editor (CodeMirror) loads when it is first opened, not with the page. If it can’t load (offline, say), the plain dialog opens instead.
pluginOptions: { advcode: { prettify: true, // lay the HTML out on lines (yes); false: only line breaks after blocks wrap: true, // wrap long lines (yes) fontSize: 14, // in pixels },}The layout is also a helper of its own: prettyHTML(editor.getHTML()) gives the same lines, and
reading them back gives the same document.
Coming from TinyMCE
Section titled “Coming from TinyMCE”plugins: 'advcode' with tinymce.init() works, and mceCodeEditor opens it.
advcode_prettify_editor is prettify, and advcode_prettify_getcontent lays out what
getContent() returns (as getContent({ prettify: true }) does). advcode_inline isn’t needed:
the code editor opens in a dialog with a full screen button.