UNPKG

@ckeditor/ckeditor5-html-support

Version:

HTML Support feature for CKEditor 5.

61 lines (60 loc) 1.8 kB
/** * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license */ /** * @module html-support/integrations/heading */ import { Plugin } from 'ckeditor5/src/core'; import { Enter } from 'ckeditor5/src/enter'; import DataSchema from '../dataschema'; /** * Provides the General HTML Support integration with {@link module:heading/heading~Heading Heading} feature. */ export default class HeadingElementSupport extends Plugin { /** * @inheritDoc */ static get requires() { return [DataSchema, Enter]; } /** * @inheritDoc */ static get pluginName() { return 'HeadingElementSupport'; } /** * @inheritDoc */ init() { const editor = this.editor; if (!editor.plugins.has('HeadingEditing')) { return; } const options = editor.config.get('heading.options'); this.registerHeadingElements(editor, options); } /** * Registers all elements supported by HeadingEditing to enable custom attributes for those elements. */ registerHeadingElements(editor, options) { const dataSchema = editor.plugins.get(DataSchema); const headerModels = []; for (const option of options) { if ('model' in option && 'view' in option) { dataSchema.registerBlockElement({ view: option.view, model: option.model }); headerModels.push(option.model); } } dataSchema.extendBlockElement({ model: 'htmlHgroup', modelSchema: { allowChildren: headerModels } }); } }