Documentation Center

How to set a preference for text in newly-created elements

A specific implementation that uses attributes of the node configuration element.

When the schema specifies a content model of both text and paragraphs for an element, you can use the configuration to specify a preference of text. The node configuration attribute node can be used to help Content Editor to specify text as the preferred content type for a node.

Change the default editor behavior

By default when using a role to insert an element (for example using toolbar buttons to insert a list), the current context will be wrapped. This means that if the current context is a paragraph, the newly-created child will contain a paragraph.

By using node you can change this default behavior. By setting the node attribute to true on this element, then when inserting an element, you instruct the editor to not add a paragraph to the newly-created child. You need to keep in mind that even if you configure a preference, the requirements of the schema or specifications of a template still take precedence.

Illustrating the use of the preferText role.

In this example, we want to configure Content Editor to create listitems with just text instead of paragraphs inside. Also notice the node attribute, which in turn ensures that the ol element is wrapped around the current context instead of inserting an ol element directly at the cursor position, when both are possible according to the schema.

Given the following configuration settings:
<x:node match="ol" preferElementsOnlyParent="true">
    <x:role>list</x:role>
</x:node>
<x:node match="li" preferText="true">
    <x:role>listitem</x:role>
</x:node> 
And the following content:
<p>Some text content|</p>
When the user presses the Ordered List button in Content Editor , it will create a structure like this:
<ol>
  <li>Some text content</li>
</ol>
Without setting preferText, it will create a structure like this:
<ol>
   <li><p>Some text content</p></li>
</ol>