Advanced document structuring capabilities that enable title and body sections for organized document creation. The Title plugin provides a specialized document structure with separate title and body areas.
Plugin that splits the document into Title and Body sections, providing structured document organization with separate editing areas.
/**
* Plugin that splits document into Title and Body sections.
*/
class Title extends Plugin {
/** Plugin name identifier */
static readonly pluginName: 'Title';
/** Indicates this is an official CKEditor 5 plugin */
static readonly isOfficialPlugin: true;
/** Required plugins that are automatically loaded */
static readonly requires: ['Paragraph'];
/**
* Sets up title/body document structure and conversion.
* Initializes the document with title and body sections.
*/
init(): void;
/**
* Returns document title as plain text.
* @param options - Formatting options with default empty object
* @returns The title content as a plain text string
*/
getTitle(options: Record<string, unknown> = {}): string;
/**
* Returns document body content.
* @param options - Formatting options with default empty object
* @returns The body content as formatted text
*/
getBody(options: Record<string, unknown> = {}): string;
}Usage Examples:
import { Title } from '@ckeditor/ckeditor5-heading';
// Basic Title plugin usage
ClassicEditor.create(document.querySelector('#editor'), {
plugins: [Title, /* other plugins */],
title: {
placeholder: 'Enter document title here...'
}
});
// Access title functionality
const titlePlugin = editor.plugins.get('Title');
// Get title and body content
const title = titlePlugin.getTitle();
const body = titlePlugin.getBody();
console.log('Document title:', title);
console.log('Document body:', body);
// Set up event listeners for title changes
editor.model.document.on('change:data', () => {
const currentTitle = titlePlugin.getTitle();
console.log('Title updated:', currentTitle);
});Configure the title section with custom placeholder text and behavior options.
/**
* Configuration interface for title feature.
*/
interface HeadingTitleConfig {
/** Custom placeholder text for title field */
placeholder?: string;
}Usage Examples:
// Configure title placeholder
const config = {
title: {
placeholder: 'Enter your document title...'
}
};
ClassicEditor.create(document.querySelector('#editor'), {
plugins: [Title],
title: config.title
});
// Multiple language support
const config = {
title: {
placeholder: t('Document Title Placeholder') // Localized placeholder
}
};The Title plugin creates a structured document with two distinct sections:
Title Section:
Body Section:
// Document structure example:
// ┌─────────────────────────────────┐
// │ Document Title Here... │ ← Title section
// ├─────────────────────────────────┤
// │ Body content starts here. │ ← Body section
// │ │
// │ Multiple paragraphs and other │
// │ content can be added here. │
// │ │
// │ [Additional content...] │
// └─────────────────────────────────┘The Title plugin provides methods to extract content from both sections:
getTitle() Method:
getBody() Method:
// Content extraction examples:
const titlePlugin = editor.plugins.get('Title');
// Get plain text title
const title = titlePlugin.getTitle();
// Returns: "My Document Title"
// Get body content with formatting
const body = titlePlugin.getBody();
// Returns formatted content with HTML/markup
// Use extracted content
document.title = title; // Set browser tab title
localStorage.setItem('documentTitle', title);
localStorage.setItem('documentBody', body);The Title plugin integrates with CKEditor 5's schema system:
Title Model Element:
Body Model Element:
// Internal model structure:
// <title>Document Title</title>
// <body>
// <paragraph>First body paragraph.</paragraph>
// <heading1>Body heading</heading1>
// <paragraph>More content...</paragraph>
// </body>The Title plugin provides specialized editing behavior:
Title Focus:
Body Focus:
// Keyboard navigation:
// - Tab in title → moves to body
// - Shift+Tab in body → moves to title
// - Enter in title → creates new paragraph in body
// - Up arrow at start of body → moves to titleThe Title plugin works alongside other CKEditor 5 features:
With Heading Plugin:
With Export/Save Features:
// Integration example:
ClassicEditor.create(document.querySelector('#editor'), {
plugins: [Title, Heading, /* other plugins */],
toolbar: ['heading', 'bold', 'italic'], // Available in body
title: {
placeholder: 'Document Title'
},
heading: {
options: [
{ model: 'paragraph', title: 'Paragraph', class: 'ck-heading_paragraph' },
// Note: No heading1 since title serves as H1
{ model: 'heading2', view: 'h2', title: 'Heading 2', class: 'ck-heading_heading2' },
{ model: 'heading3', view: 'h3', title: 'Heading 3', class: 'ck-heading_heading3' }
]
}
});