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] Introduce General HTML Support #9963

Merged
merged 218 commits into from
Jun 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
218 commits
Select commit Hold shift + click to select a range
0917227
Initial POC of general HTML support.
jacekbogdanski Jan 18, 2021
f30d329
Make sure to consume attribute on downcast.
jacekbogdanski Jan 18, 2021
a204ba3
Refactoring.
jacekbogdanski Jan 18, 2021
059edf5
Changed dataschema implementation to use view matcher.
jacekbogdanski Feb 4, 2021
8b1112b
Refactoring.
jacekbogdanski Feb 4, 2021
da9f31d
Refactored data schema definitions.
jacekbogdanski Feb 10, 2021
1d74150
Extended support for details.
jacekbogdanski Feb 10, 2021
17826af
Fixed dl schema.
jacekbogdanski Feb 11, 2021
f54b070
Break model into data schema and data filter.
jacekbogdanski Feb 16, 2021
eaa0ec5
Updated schema inheritance.
jacekbogdanski Feb 16, 2021
f448f5c
Fixed allowText.
jacekbogdanski Feb 17, 2021
4e1271d
Ensure that attribute is not used by other features.
jacekbogdanski Feb 17, 2021
bf3d979
Refactoring.
jacekbogdanski Feb 23, 2021
067ac03
Removed unnecessary code.
jacekbogdanski Feb 23, 2021
1dea09f
Use additional upcast converter to disallow attributes.
jacekbogdanski Feb 23, 2021
db8df3f
Changed conversion priority.
jacekbogdanski Feb 23, 2021
e84a96f
Fixed autoparagraphing for some elements.
jacekbogdanski Feb 23, 2021
665b13c
Fixed dependencies.
jacekbogdanski Feb 23, 2021
3628142
Refactored element name matching.
jacekbogdanski Feb 23, 2021
2b110eb
Better dataSchema and dataFilter separation.
jacekbogdanski Feb 23, 2021
2f5f5a0
Flatten styles and classes structure to simplify code.
jacekbogdanski Feb 24, 2021
af048b7
Refactoring, removed unused code.
jacekbogdanski Feb 24, 2021
79fd7da
Docs update.
jacekbogdanski Feb 26, 2021
ef5e974
Simplified downcast converter.
jacekbogdanski Feb 26, 2021
36ab682
Used view document styles processor.
jacekbogdanski Feb 26, 2021
47bd784
Changed ghs attributes format to object.
jacekbogdanski Feb 26, 2021
08cdbcf
Replaced uniq with Set.
jacekbogdanski Feb 26, 2021
0c15a7a
Docs update.
jacekbogdanski Feb 26, 2021
38d3f8a
Removed hard dependency on data schema.
jacekbogdanski Feb 26, 2021
7d231ca
Improved manual test with some additional comments.
jacekbogdanski Feb 26, 2021
19eece0
Removed unused attribute group.
jacekbogdanski Feb 26, 2021
30b0c0b
Extended definition with allowChildren.
jacekbogdanski Mar 1, 2021
161fe88
Changed attributes structure.
jacekbogdanski Mar 1, 2021
ca56a06
Minor refactoring.
jacekbogdanski Mar 1, 2021
8143ac3
Flatten definitions for getDefinitionsForView method.
jacekbogdanski Mar 1, 2021
e3f4b61
Refactoring.
jacekbogdanski Mar 1, 2021
a074984
Removed leftover.
jacekbogdanski Mar 1, 2021
ebf1f94
Docs.
jacekbogdanski Mar 2, 2021
baea36a
Updated block elements to allow only flow content.
jacekbogdanski Mar 3, 2021
78b30d0
Added test coverage for DataSchema.
jacekbogdanski Mar 3, 2021
878d544
Removed unreachable code.
jacekbogdanski Mar 3, 2021
274500b
Added test coverage for DataFilter.
jacekbogdanski Mar 3, 2021
9fffed1
Added package.json file.
jacekbogdanski Mar 3, 2021
88f0659
Corrected docs.
jacekbogdanski Mar 5, 2021
5b7e58a
Updated package.json.
jacekbogdanski Mar 5, 2021
f88cdf5
Refactoring.
jacekbogdanski Mar 5, 2021
89d8e4b
Corrected docs indentation.
jacekbogdanski Mar 5, 2021
af7781d
Renaming from ghs to html.
jacekbogdanski Mar 10, 2021
c90ebf0
Renaming from ghs to html (part2).
jacekbogdanski Mar 10, 2021
97c4ccb
Minor docs correction.
jacekbogdanski Mar 11, 2021
fdb4d6c
Typo fix.
niegowski Mar 11, 2021
eb4bd1a
Added missing empty line.
niegowski Mar 11, 2021
bd1920f
Added missing empty line.
niegowski Mar 11, 2021
c4c2f68
Apply suggestions from code review
niegowski Mar 11, 2021
681fead
Apply suggestions from code review
niegowski Mar 11, 2021
819ccfc
Apply suggestions from code review
niegowski Mar 11, 2021
838b68e
Apply suggestions from code review
niegowski Mar 11, 2021
9b447fb
Apply suggestions from code review
niegowski Mar 11, 2021
84a7492
Apply suggestions from code review
niegowski Mar 11, 2021
fa1c77c
Code review fixes.
niegowski Mar 11, 2021
9fc6ab1
Code review fixes.
niegowski Mar 11, 2021
840a924
Updated package.json to match the latest release.
jacekbogdanski Mar 29, 2021
beecd7a
Added initial support for inline elements.
jacekbogdanski Mar 10, 2021
31accfe
Nested inline elements support.
jacekbogdanski Mar 11, 2021
c1c6c62
Added initial test for inline elements.
jacekbogdanski Mar 12, 2021
a7f17a8
Added tests, improved element nesting.
jacekbogdanski Mar 15, 2021
3d014e9
Added missing unit tests.
jacekbogdanski Mar 15, 2021
d4ba2d0
Docs corrections.
jacekbogdanski Mar 15, 2021
142d013
Corrected attributes merging order.
jacekbogdanski Mar 15, 2021
91fc98c
Manual test fixes.
jacekbogdanski Mar 15, 2021
7e2ed81
Favor Set over uniq.
jacekbogdanski Mar 15, 2021
0a7fe46
Removed 'transparent' elements.
jacekbogdanski Mar 16, 2021
87bea09
Corrected regexpes.
jacekbogdanski Mar 16, 2021
7f1d7d8
Fixed converter to include passed model range.
jacekbogdanski Mar 16, 2021
11e15e1
Splitted schema register method into inline and block elements.
jacekbogdanski Mar 16, 2021
2f2a320
Renaming schema to modelSchema.
jacekbogdanski Mar 16, 2021
6596654
Apply suggestions from code review
jacekbogdanski Mar 17, 2021
b2ca371
Fixed manual test.
jacekbogdanski Mar 17, 2021
2f3626b
Renaming general to generic.
jacekbogdanski Mar 17, 2021
834b4d6
Refactoring.
jacekbogdanski Mar 17, 2021
baa3f8b
Renaming.
jacekbogdanski Mar 17, 2021
b73e6c8
Docs.
jacekbogdanski Mar 17, 2021
16e22f1
Added test coverage, updated error message.
jacekbogdanski Mar 17, 2021
6a9e3c8
Updated data schema docs to new API.
jacekbogdanski Mar 17, 2021
15a5be3
Extracted base data schema definition type.
jacekbogdanski Mar 17, 2021
fd542ac
Minor docs update.
jacekbogdanski Mar 17, 2021
c8b0e5c
Added additional test for attribute properties.
jacekbogdanski Mar 17, 2021
16d00e3
Added information about definition specific properties.
jacekbogdanski Mar 17, 2021
8382a8d
Update packages/ckeditor5-content-compatibility/src/datafilter.js
jacekbogdanski Mar 29, 2021
f40afe0
Docs update.
jacekbogdanski Mar 29, 2021
88b9fdb
Updated tests to use VirtualEditor.
jacekbogdanski Mar 30, 2021
0a10e2d
Corrected docs based on build verification.
jacekbogdanski Mar 30, 2021
6bdeed1
Removed @publicApi tags.
niegowski Mar 30, 2021
3f51d92
Simplified data filter attribute matchers.
jacekbogdanski Mar 31, 2021
ebe79c3
Added support to allow attributes on existing features.
jacekbogdanski Apr 6, 2021
7f81ef0
Rewording.
jacekbogdanski Apr 6, 2021
7dd2494
Renaming.
jacekbogdanski Apr 8, 2021
8b326e9
Ensure that model is not registered early.
jacekbogdanski Apr 8, 2021
5028c38
Return early for attribute filters also.
jacekbogdanski Apr 8, 2021
d5219fb
Reworded test to use real case scenario.
jacekbogdanski Apr 8, 2021
2686981
Removed dead code.
jacekbogdanski Apr 8, 2021
c1b734d
Minor refactoring, commenting.
jacekbogdanski Apr 8, 2021
b4d1af9
Added inline elements priority support, simplified code.
jacekbogdanski Apr 12, 2021
37bf728
Used model schema instead of isFeature, ensured that GHS is initializ…
jacekbogdanski Apr 14, 2021
e90852e
Renaming generic to general.
jacekbogdanski Apr 14, 2021
c7a592f
Added test coverage for initializing ghs from plugin.
jacekbogdanski Apr 14, 2021
723ad21
Updated defaults.
jacekbogdanski Apr 14, 2021
76be19c
Refactoring.
jacekbogdanski Apr 15, 2021
26033e1
Avoid specifying default priority.
jacekbogdanski Apr 15, 2021
3e12ab7
Added missing jsdoc.
jacekbogdanski Apr 15, 2021
397258d
Listen on priority higher than RTC.
jacekbogdanski Apr 15, 2021
df22ed4
Updated package.json to the latest CKE5 release.
jacekbogdanski May 6, 2021
a0700a4
Initial implementation for object elements.
jacekbogdanski May 6, 2021
09d528b
Styling, small bug fix.
jacekbogdanski May 6, 2021
0bcb808
Fixed allowChildren API, docs.
jacekbogdanski May 6, 2021
8321951
Refactoring, css fix.
jacekbogdanski May 6, 2021
94ded58
Rewritten implementation to embed whole objects instead.
jacekbogdanski May 9, 2021
0af2010
Corrected audio example.
jacekbogdanski May 9, 2021
9f41cfb
Added support for object block elements.
jacekbogdanski May 10, 2021
4e11c30
Small fixes, test coverage.
jacekbogdanski May 10, 2021
3594234
Added block object manual test.
jacekbogdanski May 10, 2021
db8824f
Respect UI language.
jacekbogdanski May 10, 2021
bc48865
Refactoring.
jacekbogdanski May 10, 2021
4ac3c04
Sanity check for dataschema API.
jacekbogdanski May 10, 2021
bb7ed34
Docs update.
jacekbogdanski May 10, 2021
d715d77
Refactoring.
jacekbogdanski May 10, 2021
6510eba
Reverted unnecessary docs change.
jacekbogdanski May 10, 2021
a5b013d
Fixed manual test.
jacekbogdanski May 11, 2021
c019ad9
Ensure that widget label is not changing by basic styles.
jacekbogdanski May 11, 2021
637ccb8
Simplified implementation to use original definition model.
jacekbogdanski May 12, 2021
fd1c79d
Transformed data filter and data schema into plugins.
jacekbogdanski May 12, 2021
c60409d
Docs.
jacekbogdanski May 12, 2021
78af6e8
Fixed manual test.
jacekbogdanski May 12, 2021
f2e23ca
Codeblock support, huge refactoring.
jacekbogdanski May 14, 2021
3ebc4c6
Added test coverage, removed dead code.
jacekbogdanski May 14, 2021
aa0a93d
Refactoring.
jacekbogdanski May 25, 2021
f841e6f
Handle registered object elements.
jacekbogdanski May 25, 2021
2b6fc2c
Added converter priority for object elements.
jacekbogdanski May 25, 2021
a76e103
Register missing schema keys.
jacekbogdanski May 25, 2021
ef33414
Separated t from editor.
jacekbogdanski May 25, 2021
957b8f7
Removed rtl support.
jacekbogdanski May 25, 2021
a74247e
Compose block helper conversions instead of separate attribute conver…
jacekbogdanski May 25, 2021
186433f
Separate code block from data filter, improve conversion
jacekbogdanski May 26, 2021
909f12c
Docs.
jacekbogdanski May 26, 2021
854e918
Docs, small fixes.
jacekbogdanski Jun 1, 2021
81af835
Added codeBlock attributes.
jacekbogdanski Jun 1, 2021
818f936
Removed invalid docs.
jacekbogdanski Jun 1, 2021
2affa41
Improved docs.
jacekbogdanski Jun 1, 2021
5891ac4
Protected API instead of public.
jacekbogdanski Jun 1, 2021
6f5a1cf
Updated docs.
jacekbogdanski Jun 7, 2021
b56ba53
Deps update to the latest release.
jacekbogdanski Jun 7, 2021
6368cb7
Fixed manual test.
niegowski Jun 7, 2021
423d9c0
Add data filter configuration loading.
maxbarnas May 13, 2021
f512de3
Add loading config.
maxbarnas May 17, 2021
3461201
Fix config loading.
maxbarnas May 18, 2021
1fcec51
Review fixes.
maxbarnas May 18, 2021
a781a74
Merge manual tests.
maxbarnas May 18, 2021
ee76ffb
Match when any pattern group is matched.
maxbarnas May 20, 2021
8563013
Match any pattern inside a rule.
maxbarnas May 20, 2021
d6a9630
Return pattern as array in _splitPattern method.
maxbarnas May 20, 2021
141bdc7
Display the source content as before passed through the editor.
Reinmar May 20, 2021
e13e84e
Some more examples.
Reinmar May 20, 2021
63797d6
Add missing tests and docs.
maxbarnas May 31, 2021
87b0b4e
Review fixes.
maxbarnas Jun 2, 2021
5a8528e
Update `allowElement()` method and tests.
maxbarnas Jun 4, 2021
3df9664
Rebase fixes.
maxbarnas Jun 4, 2021
f8a2f39
Fixed loading data filter by ghs plugin.
jacekbogdanski Jun 8, 2021
9d9adaa
Review fixes - more tests.
maxbarnas Jun 8, 2021
4a444d5
Allow matching all elements by skipping name.
jacekbogdanski Jun 8, 2021
4171bfd
Move methods outside of a class.
maxbarnas Jun 9, 2021
a14f1e0
Review fixes.
maxbarnas Jun 10, 2021
b93e929
Corrected sample.
jacekbogdanski Jun 10, 2021
5d963b9
Package renaming.
jacekbogdanski Jun 11, 2021
c0b07ba
Renamed config.
jacekbogdanski Jun 11, 2021
8cf0364
Added missing renaming.
jacekbogdanski Jun 11, 2021
4191bf4
Updated docs, package.json.
jacekbogdanski Jun 15, 2021
b44e02d
Added missing `@ckeditor/ckeditor5-html-support` dependency
psmyrek Jun 16, 2021
ac66883
First draft of the docs.
Reinmar Jun 14, 2021
2deb33d
Docs: basic language review.
godai78 Jun 14, 2021
6e1238f
Docs: grammar fix.
godai78 Jun 14, 2021
ef6a9c1
Moved docs to package directory.
jacekbogdanski Jun 15, 2021
7ba990c
Updated technical docs issues.
jacekbogdanski Jun 15, 2021
63d6d49
Reverted unnecessary change.
jacekbogdanski Jun 15, 2021
f12c7f9
Docs: further fixes to the docs.
godai78 Jun 16, 2021
6192504
Docs: renaming section.
godai78 Jun 17, 2021
8ac83d4
Docs: section rewording.
godai78 Jun 17, 2021
e0849a4
Docs: Updated package name in the GHS feature guide.
Mgsy Jun 17, 2021
ab2124e
Updated known issues section.
jacekbogdanski Jun 18, 2021
66e0806
Added missing definitions for headings.
jacekbogdanski Jun 21, 2021
4d7b3b3
Removed unused attributes in demo.
jacekbogdanski Jun 21, 2021
6b281c2
Typo.
jacekbogdanski Jun 21, 2021
efb1096
Added missing abbrv definition.
jacekbogdanski Jun 21, 2021
301f6f6
Apply suggestions from code review
jacekbogdanski Jun 21, 2021
bafe5f1
Unified package name in docs guide.
jacekbogdanski Jun 21, 2021
88e0b93
Complete schema definition with missing features.
jacekbogdanski Jun 17, 2021
4137e83
Expanded data schema with missing elements.
jacekbogdanski Jun 17, 2021
14e4235
Updated definintions with another set of elements.
jacekbogdanski Jun 17, 2021
3e066ab
Updated description list, fixed unit test.
jacekbogdanski Jun 17, 2021
a4d2052
Model renaming, adding new definitions.
jacekbogdanski Jun 18, 2021
834ad63
Set attributes on correct editing element.
jacekbogdanski Jun 18, 2021
330f785
Corrected definitions, tests.
jacekbogdanski Jun 18, 2021
c7e419d
Schema definitions test.
jacekbogdanski Jun 18, 2021
8326de3
Refactoring, test coverage.
jacekbogdanski Jun 18, 2021
90e60a4
Cleanup.
jacekbogdanski Jun 18, 2021
0a492a1
Fixed center element.
jacekbogdanski Jun 18, 2021
cf043a1
Renaming to .
jacekbogdanski Jun 21, 2021
71499fc
Updated existing features.
jacekbogdanski Jun 21, 2021
daf203d
Removed unused config.
jacekbogdanski Jun 25, 2021
c4f74c4
Ensure that attribute is consumed.
jacekbogdanski Jun 25, 2021
3e6a1d3
Corrected invalid test.
jacekbogdanski Jun 25, 2021
a85bbf7
Corrected comment.
jacekbogdanski Jun 25, 2021
834bc1d
Remove already consumed attributes from data filter.
jacekbogdanski Jun 28, 2021
ef7156b
Args renaming.
jacekbogdanski Jun 28, 2021
f1d1ded
Apply suggestions from code review
jacekbogdanski Jun 28, 2021
8cfeafe
Updated docs.
jacekbogdanski Jun 28, 2021
eb0283f
Update packages/ckeditor5-html-support/src/datafilter.js
maxbarnas Jun 28, 2021
c08eec9
Merge pull request #9968 from ckeditor/ci/764-datafilter
maxbarnas Jun 28, 2021
5932b3c
Docs: Updated GHS feature guide.
Mgsy Jun 28, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/_snippets/features/mathtype.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ ClassicEditor
} )

.then( editor => {
window.editor = editor;

window.attachTourBalloon( {
target: window.findToolbarItem( editor.ui.view.toolbar,
item => item.label && item.label === 'Insert a math equation - MathType' ),
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@ckeditor/ckeditor5-highlight": "^28.0.0",
"@ckeditor/ckeditor5-horizontal-line": "^28.0.0",
"@ckeditor/ckeditor5-html-embed": "^28.0.0",
"@ckeditor/ckeditor5-html-support": "^28.0.0",
"@ckeditor/ckeditor5-image": "^28.0.0",
"@ckeditor/ckeditor5-indent": "^28.0.0",
"@ckeditor/ckeditor5-language": "^28.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<div id="snippet-general-html-support">
<h2 data-i18n-context="title">General HTML support</h2>

<div style="color: red; padding: 10px; text-align: center; border: solid 3px red">
<p data-i18n-context="experimental-note">This is an experimental feature.</p>

<details data-i18n-context="experimental-note">
<summary>Read more</summary>

<p>The General HTML support feature is <strong>experimental and not yet production-ready</strong>.</p>
<p>Follow the <a href="https://github.com/ckeditor/ckeditor5/issues/9856">"Stabilize and release a production-ready General HTML support feature"</a> issue for more updates.</p>
</details>
</div>

<p data-i18n-context="description">The <abbr title="General HTML Support">GHS</abbr> feature is enabled in this editor and configured to support the following content (in addition to the content already support by other editor features):</p>

<ul>
<li><code>&lt;div></code>, <code>&lt;details></code>, and <code>&lt;summary></code> elements with all kind of attributes,</li>
<li>paragraphs and headings with <code>data-*</code> attributes and all classes,</li>
<li><code>&lt;span></code> elements with all inline styles and <code>&lt;abbr></code> elements with `title` attributes.</li>
</ul>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/**
* @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
*/

/* globals console, window, document */

import { CS_CONFIG } from '@ckeditor/ckeditor5-cloud-services/tests/_utils/cloud-services-config.js';

import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
import Code from '@ckeditor/ckeditor5-basic-styles/src/code';
import EasyImage from '@ckeditor/ckeditor5-easy-image/src/easyimage';
import ImageUpload from '@ckeditor/ckeditor5-image/src/imageupload';
import CloudServices from '@ckeditor/ckeditor5-cloud-services/src/cloudservices';

import SourceEditing from '@ckeditor/ckeditor5-source-editing/src/sourceediting';
import GeneralHtmlSupport from '@ckeditor/ckeditor5-html-support/src/generalhtmlsupport';

ClassicEditor
.create( document.querySelector( '#snippet-general-html-support' ), {
plugins: [
ArticlePluginSet,
Code,
EasyImage,
ImageUpload,
CloudServices,
SourceEditing,
GeneralHtmlSupport
],
toolbar: {
items: [
'sourceEditing',
'|',
'heading',
'|',
'bold',
'italic',
'code',
'bulletedList',
'numberedList',
'|',
'outdent',
'indent',
'|',
'blockQuote',
'link',
'mediaEmbed',
'insertTable',
'|',
'undo',
'redo'
],
viewportTopOffset: window.getViewportTopOffsetConfig()
},
image: {
toolbar: [
'imageStyle:inline',
'imageStyle:wrapText',
'imageStyle:breakText',
'|',
'toggleImageCaption',
'imageTextAlternative'
]
},
table: {
contentToolbar: [ 'tableColumn', 'tableRow', 'mergeTableCells' ]
},
cloudServices: CS_CONFIG,

htmlSupport: {
allow: [
// Enables <div>, <details>, and <summary> elements with all kind of attributes.
{
name: /^(div|details|summary)$/,
styles: true,
classes: true,
attributes: true
},

// Extends the existing Paragraph and Heading features
// with classes and data-* attributes.
{
name: /^(p|h[2-4])$/,
classes: true,
attributes: /^data-/
},

// Enables <span>s with any inline styles.
{
name: 'span',
styles: true
},

// Enables <abbr>s with the title attribute.
{
name: 'abbr',
attributes: [ 'title' ]
}
]
}
} )
.then( editor => {
window.editor = editor;

window.attachTourBalloon( {
target: window.findToolbarItem( editor.ui.view.toolbar,
item => item.label && item.label === 'Source' ),
text: 'Switch to the source mode to check out the source of the content and play with it.',
editor
} );
} )
.catch( err => {
console.error( err.stack );
} );
239 changes: 239 additions & 0 deletions packages/ckeditor5-html-support/docs/features/general-html-support.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
---
category: features
modified_at: 2021-06-13
updated_at: 2021-06-14
---

# General HTML Support

The General HTML Support ("GHS") feature allows developers to easily enable HTML features that are not explicitly supported by any other dedicated CKEditor 5 plugins.

Some examples of HTML features that can be easily enabled using General HTML Support include:

* The `<section>`, `<article>`, and `<div>` elements.
* The `<audio>`, `<video>`, and `<iframe>` elements.
* The `<span>` and `<cite>` elements.
* Some of the attributes on existing dedicated CKEditor 5 features:
* `data-*` and `id` attributes on e.g. `<p>` and `<h1-h6>`,
* `style` and `classes` on e.g. `<strong>` and `<a>`.

The enabled HTML features can be loaded (e.g. via `editor.setData()`), pasted, output (e.g. via `editor.getData()`), and are visible in the editing area. Such content can also be edited in the editor, although, to a limited extent. Read more about it in the [Level of support](#level-of-support) section.

<info-box>
The General HTML Support feature is **experimental and not yet production-ready**.

Follow the ["Stabilize and release a production-ready General HTML Support feature"](https://github.com/ckeditor/ckeditor5/issues/9856) issue for more updates and related issues.
</info-box>

## Demo

The General HTML Support feature is configured via the `config.htmlSupport` property. In it, you need to list the HTML features that should be handled by GHS.

The demo below uses the following configuration:

```js
import SourceEditing from '@ckeditor/ckeditor5-source-editing/src/sourceediting';
import GeneralHtmlSupport from '@ckeditor/ckeditor5-html-support/src/generalhtmlsupport';

ClassicEditor
.create( document.querySelector( '#editor' ), {
plugins: [ SourceEditing, GeneralHtmlSupport, ... ],
toolbar: [ 'sourceEditing', ... ],
htmlSupport: {
allow: {
// Enables <div>, <details>, and <summary> elements with all kind of attributes.
{
name: /^(div|details|summary)$/,
styles: true,
classes: true,
attributes: true
},

// Extends the existing Paragraph and Heading features
// with classes and data-* attributes.
{
name: /^(p|h[2-4])$/,
classes: true,
attributes: /^data-/
},

// Enables <span>s with any inline styles.
{
name: 'span',
styles: true
},

// Enables <abbr>s with the title attribute.
{
name: 'abbr',
attributes: [ 'title' ]
}
}
}
} )
.then( ... )
.catch( ... );
```

{@snippet features/general-html-support}

## Level of support

The difference between specific CKEditor 5 features such as {@link features/basic-styles basic styles} or {@link features/headings headings} and the HTML features enabled by GHS is that a plugin that supports a specific HTML feature provides a complete user experience for that feature, whereas GHS ensures only that such a content is accepted by the editor.

For instance, the dedicated {@link features/basic-styles#available-text-styles bold} feature offers a toolbar button used to make the selected text bold. Together with the {@link features/autoformat autoformatting feature}, it also allows for applying bold style to content by typing a Markdown shortcode (`**foo**`) in the editor. The {@link features/headings headings} feature offers a dropdown from which the user can choose a heading level and ensures that pressing <kbd>Enter</kbd> at the end of a heading creates a new paragraph (and not another heading).

The General HTML Support does not offer any UI for the enabled features and takes only the basic semantics of a given feature into account. If you enable support for `<div>`s via GHS, the user will not be able to create `<div>`s from the editor UI. The GHS will know that a `<div>` is a container element, so it can wrap other blocks (like paragraphs) but cannot be used inline (next to e.g. a `<strong>` element).

Therefore, GHS's main use cases would be:

* Ensuring backwards content compatibility with legacy systems.
* Introducing basic support for missing HTML features at a low cost.

<info-box>
Taken the nature of GHS, you may consider installing the {@link features/source-editing source editing} feature alongside with it.
</info-box>

## Installation

To add this feature to your rich-text editor, install the [`@ckeditor/ckeditor5-html-support`](https://www.npmjs.com/package/@ckeditor/ckeditor5-html-support) package:

```plaintext
npm install --save @ckeditor/ckeditor5-html-support
```

And add it to your plugin list configuration:

```js
import GeneralHtmlSupport from '@ckeditor/ckeditor5-html-support/src/generalhtmlsupport';

ClassicEditor
.create( document.querySelector( '#editor' ), {
plugins: [ GeneralHtmlSupport, ... ],
} )
.then( ... )
.catch( ... );
```

<info-box info>
Read more about {@link builds/guides/integration/installing-plugins installing plugins}.
</info-box>

## Configuration

By default, enabling the {@link module:html-support/generalhtmlsupport~GeneralHtmlSupport} plugin does not enable support for any given element. The elements the user wants to be supported, need to be configured via the {@link module:core/editor/editorconfig~EditorConfig#htmlSupport `config.htmlSupport`} option:

```js
ClassicEditor.create( document.querySelector( '#editor' ), {
htmlSupport: {
allow: [ /* HTML features to allow */ ]
disallow: [ /* HTML features to disallow */ ]
}
} )
```

The notation of the `allow` and `disallow` rules looks as follows:

```js
[
{
// The element name to enable and/or extend with
// the following styles, classes and other attributes.
name: string|regexp,

// Styles to allow (by name, name and value or just all).
styles: object<string=>true|string|regexp>|array<string>|true,

// Classes to allow (by name or just all).
classes: array<string|regexp>|true,

// Other attributes to allow (by name, name and value or just all).
attributes: object<string=>true|string|regexp>|array<string>|true,
}
]
```

Several implementation examples:

```js
htmlSupport: {
allow: [
// Enables plain <div> elements.
{
name: 'div'
},

// Enables plain <div>, <section> and <article> elements.
{
name: /^(div|section|article)$/
},

// Enables <div>s with all inline styles (but no other attributes).
{
name: 'div',
styles: true
},

// Enables <div>s with foo and bar classes.
{
name: 'div',
classes: [ 'foo', 'bar' ]
},

// Adds support for `foo` and `bar` classes to the already supported
// <p> elements (those are enabled by the dedicated paragraph feature).
{
name: 'p',
classes: [ 'foo', 'bar' ]
},

// Enables <div>s with foo="true" attribute and bar attribute that
// can accept any value (boolean `true` value works as an asterisk).
{
name: 'div',
attributes: {
foo: 'true',
bar: true
}
},

// Adds support for style="color: *" to the already supported
// <p> and <h2-h4> elements.
{
name: /^(p|h[2-4])$/',
styles: { 'color': true }
},
}
```

The General HTML Support feature distinguishes several content types, each treated a bit differently:

* Container elements (e.g. `<section>`, `<div>`).
* Inline elements (e.g. `<span>`, `<a>`).
* Object elements (e.g. `<iframe>`, `<video>`).

The enabled elements will not just be available "anywhere" in the content, as they still need to adhere to certain rules derived from the HTML schema and from common sense. Also, the behavior of specific types of elements in the editing area will be different. For instance, the object elements will only be selectable as a whole, and the inline elements will work the same as other formatting features supported by CKEditor 5 (e.g. bold, italic) do.

## Known issues

It is possible to add support for arbitrary styles, classes and other attributes to existing CKEditor 5 features (such as paragraphs, headings, list items, etc.).

Most of the existing CKEditor 5 features can already be extended this way, however, some cannot yet. This includes:

* Some of the table markup [#9914](https://github.com/ckeditor/ckeditor5/issues/9914).
* Some of the image features' markup [#9916](https://github.com/ckeditor/ckeditor5/issues/9916).
* Some of the media embed features' markup [#9918](https://github.com/ckeditor/ckeditor5/issues/9918).
* The `<ul>` and `<ol>` elements of the list feature [#9917](https://github.com/ckeditor/ckeditor5/issues/9917).

We're open for feedback, so if you find any issue, feel free to report it in the [main CKEditor 5 repository](https://github.com/ckeditor/ckeditor5/issues/).

## Related features

There are other HTML editing related CKEditor 5 features you may want to check:

* {@link features/source-editing Source editing} &ndash; Provides the ability for viewing and editing the source of the document.
* {@link features/html-embed HTML embed} &ndash; Allows embedding an arbitrary HTML snippet in the editor. It is a more constrained and controllable approach to arbitrary HTML than GHS.

## Contribute

The source code of the feature is available on GitHub in https://github.com/ckeditor/ckeditor5/tree/master/packages/ckeditor5-html-support.
Loading