Skip to main content

Content Behavior

These options control how the editor handles content creation, Enter key behavior, text patterns, and drag-and-drop operations.

Options

OptionTypeDefaultDescription
forced_root_blockstring'p'Block element used to wrap text nodes at the root level.
forced_root_block_attrsobject{}HTML attributes applied to the forced root block element.
newline_behaviorstring'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_prebooleantrueInsert a <br> instead of splitting into a new <pre> block when Enter is pressed inside a <pre> element.
br_newline_selectorstring'.editor42-m-toc h2,figcaption,caption'CSS selector for elements where Enter inserts a <br> instead of creating a new block.
no_newline_selectorstring''CSS selector for elements where the Enter key is suppressed entirely.
keep_stylesbooleantrueCarry text formatting (bold, italic, etc.) into the new paragraph when pressing Enter.
end_container_on_empty_blockboolean/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_patternsobject[]/falsesee belowMarkdown-like text patterns that trigger automatic formatting. Set to false to disable.
text_patterns_lookupfunctionCallback that dynamically provides additional text patterns based on context.
block_unsupported_dropbooleantrueBlock drag-and-drop of content types that the editor does not support.
table_tab_navigationbooleantrueAllow the Tab key to navigate between table cells.
newdocument_contentstring''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 list
  • 1. — 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>' }
]
});