Content Behavior
These options control how the editor handles content creation, Enter key behavior, text patterns, and drag-and-drop operations.
Options
| Option | Type | Default | Description |
|---|---|---|---|
forced_root_block | string | 'p' | Block element used to wrap text nodes at the root level. |
forced_root_block_attrs | object | {} | HTML attributes applied to the forced root block element. |
newline_behavior | string | 'default' | What happens when the user presses Enter. 'block' inserts a new block, 'linebreak' inserts a <br>, 'invert' swaps the behavior of Enter and Shift+Enter, 'default' uses the standard behavior. |
br_in_pre | boolean | true | Insert a <br> instead of splitting into a new <pre> block when Enter is pressed inside a <pre> element. |
br_newline_selector | string | '.editor42-m-toc h2,figcaption,caption' | CSS selector for elements where Enter inserts a <br> instead of creating a new block. |
no_newline_selector | string | '' | CSS selector for elements where the Enter key is suppressed entirely. |
keep_styles | boolean | true | Carry text formatting (bold, italic, etc.) into the new paragraph when pressing Enter. |
end_container_on_empty_block | boolean/string | 'blockquote' | End a containing block when the user presses Enter twice on an empty line. Set to a tag name or true for all blocks. |
text_patterns | object[]/false | see below | Markdown-like text patterns that trigger automatic formatting. Set to false to disable. |
text_patterns_lookup | function | — | Callback that dynamically provides additional text patterns based on context. |
block_unsupported_drop | boolean | true | Block drag-and-drop of content types that the editor does not support. |
table_tab_navigation | boolean | true | Allow the Tab key to navigate between table cells. |
newdocument_content | string | '' | HTML content inserted when the "New Document" command is executed. |
Default text patterns
The built-in text patterns include:
*text*— italic**text**— bold#— heading 1 (up to######for heading 6)*or-— unordered list1.— ordered list
Example
editor42.init({
selector: 'textarea',
forced_root_block: 'div',
newline_behavior: 'linebreak',
keep_styles: true,
text_patterns: [
{ start: '*', end: '*', format: 'italic' },
{ start: '**', end: '**', format: 'bold' },
{ start: '# ', cmd: 'editor42InsertContent', value: '<h1>$1</h1>' }
]
});