Issue
AlloyEditor/CKEditor will not allow to use anchor (<a>) tags to surround other HTML elements like headings (<h1>, <h2>, etc...). For example, an HTML markup like this in the source tab:
<a class="test" href="web"> <h1><span>This is a test header <img alt="test" scr="https://test.com" /></span></h1> </a>
Will become
<h1>
<a class="test" href="web"><span>This is a test header <img alt="test" scr="https://test.com" /> </span></a>
</h1>
after switching to the Rich Text Editor tab or publishing the content.
Environment
- Liferay DXP 7.0, 7.1, 7.2
Resolution
Override your editor's configuration so that such HTML structure is allowed.
For example, in a module that overrides the CKEditor, one line has to be added in the file: /src/main/resources/META-INF/resources/ckeditor/dtd_definition.js
CKEDITOR.dtd.a.h1 = 1;
The source code of a sample module is attached here for convenience
Additional Information
- https://help.liferay.com/hc/en-us/articles/360017882652-Modifying-an-Editor-s-Configuration
- https://ckeditor.com/docs/ckeditor4/latest/guide/dev_allowed_content_rules.html
- https://ckeditor.com/old/forums/Support/CKEditor-wont-allow-inside
- https://ckeditor.com/old/forums/Support/What-is-the-syntax-to-allow-all-content-html-a-h1-p-in-the-config.js-page.
Note: CKEditor and Alloy Editor are provided as WYSIWYG Content Editors and are not intended to be HTML Editors. These editors' Source Modes are provided for convenience and are only intended for minor markup adjustments. Any markup entered into Source Mode is not guaranteed to remain unmodified nor intact.