Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GHS integration with Heading. #10664

Merged
merged 8 commits into from Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/ckeditor5-html-support/src/generalhtmlsupport.js
Expand Up @@ -12,6 +12,7 @@ import { Plugin } from 'ckeditor5/src/core';
import DataFilter from './datafilter';
import CodeBlockElementSupport from './integrations/codeblock';
import DualContentModelElementSupport from './integrations/dualcontent';
import HeadingElementSupport from './integrations/heading';
import ImageElementSupport from './integrations/image';
import MediaEmbedElementSupport from './integrations/mediaembed';
import TableElementSupport from './integrations/table';
Expand Down Expand Up @@ -40,6 +41,7 @@ export default class GeneralHtmlSupport extends Plugin {
DataFilter,
CodeBlockElementSupport,
DualContentModelElementSupport,
HeadingElementSupport,
ImageElementSupport,
MediaEmbedElementSupport,
TableElementSupport
Expand Down
65 changes: 65 additions & 0 deletions packages/ckeditor5-html-support/src/integrations/heading.js
@@ -0,0 +1,65 @@
/**
* @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. 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 DataSchema from '../dataschema';

/**
* Provides the General HTML Support integration with {@link module:heading/heading~Heading Heading} feature.
*
* @extends module:core/plugin~Plugin
*/
export default class HeadingElementSupport extends Plugin {
/**
* @inheritDoc
*/
static get requires() {
return [ DataSchema ];
}

/**
* @inheritDoc
*/
init() {
const editor = this.editor;
const dataSchema = editor.plugins.get( DataSchema );

const options = editor.plugins.has( 'Heading' ) ? editor.config.get( 'heading.options' ) : [];

const htmlGroupChildren = [
'htmlH1',
'htmlH2',
'htmlH3',
'htmlH4',
'htmlH5',
'htmlH6'
];

for ( const option of options ) {
niegowski marked this conversation as resolved.
Show resolved Hide resolved
if ( 'model' in option && 'view' in option ) {
dataSchema.registerBlockElement( {
view: option.view,
model: option.model
} );

htmlGroupChildren.push( option.model );
}
}

// I'm not sure if it should be defined here. Mayby only amended somehow.
dataSchema.registerBlockElement( {
model: 'htmlHgroup',
view: 'hgroup',
modelSchema: {
allowChildren: htmlGroupChildren
}
} );
niegowski marked this conversation as resolved.
Show resolved Hide resolved
}
}
30 changes: 0 additions & 30 deletions packages/ckeditor5-html-support/src/schemadefinitions.js
Expand Up @@ -51,18 +51,6 @@
export default {
block: [
// Existing features
{
model: 'heading1',
view: 'h2'
},
{
model: 'heading2',
view: 'h3'
},
{
model: 'heading3',
view: 'h4'
},
{
model: 'codeBlock',
view: 'pre'
Expand Down Expand Up @@ -321,24 +309,6 @@ export default {
inheritAllFrom: '$htmlSection'
}
},
{
model: 'htmlHgroup',
view: 'hgroup',
modelSchema: {
allowChildren: [
'htmlHeading1',
'htmlHeading2',
'htmlHeading3',
'htmlHeading4',
'htmlHeading5',
'htmlHeading6',
'heading1',
'heading2',
'heading3'
],
isBlock: true
}
},
{
model: 'htmlH1',
view: 'h1',
Expand Down