-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Why is h1 element not supported? #2443
Comments
I'm trying to implement it but getting this error in console:
My whole code:
|
Mmm... We have a test for this, but I can see the test is poor. It does use a different schema name (model name) than any of the default ones, so there's no collision. OTOH, I can see that the code looks good... I need to check it deeper. |
This worked for me just fine: import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classic';
import Enter from '@ckeditor/ckeditor5-enter/src/enter';
import Typing from '@ckeditor/ckeditor5-typing/src/typing';
import Heading from '../../src/heading';
import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
import Undo from '@ckeditor/ckeditor5-undo/src/undo';
ClassicEditor.create( document.querySelector( '#editor' ), {
plugins: [ Enter, Typing, Undo, Heading, Paragraph ],
toolbar: [ 'headings', 'undo', 'redo' ],
heading: {
options: [
{ modelElement : 'paragraph', title: 'Paragraph', class : 'ck-heading_paragraph' },
{ modelElement : 'heading1', viewElement : 'h1', title : 'Heading 1', class : 'ck-heading_heading1' },
{ modelElement : 'heading2', viewElement : 'h2', title : 'Heading 2', class : 'ck-heading_heading2' },
{ modelElement : 'heading3', viewElement : 'h3', title : 'Heading 3', class : 'ck-heading_heading3' }
]
},
} )
.then( editor => {
window.editor = editor;
} )
.catch( err => {
console.error( err.stack );
} ); Maybe you need to update your dependencies? Heading package was refactored in 0.9.0 so if you're on 0.8.0 it may not work. Check out the changelog: https://github.com/ckeditor/ckeditor5-heading/blob/master/CHANGELOG.md |
Hi, I think that converting
Personally, I just experienced the second case, then I ended up quite quickly on this post and understood what happened. |
This seems to be a lot better option. Most of the users won't know whether the headings in the original content they copied were h1 or h2. I wouldn't know myself (unless I checked :D). |
It has a small impact on styling. On my page, I have a |
I agree that converting them automatically is a must... but let's make it more complicate, ofc... Should we sniff the pasted content and, if it has any Then, if there is no |
For my part, I think it's indeed a good idea. |
Sounds reasonable but in some situations might be confusing as well. Suppose you are copying content from the same source. First you copy the beginning of the article, including H1, then you start copying other parts from the same article (e.g. because you want to place it in different order or just want to copy selected parts of the article, because its too long, contains internal notes or sth). As a result one ends up with H2 used in place of "H1" and then H2 used in the middle of content again. In any case, this is nothing that cannot be fixed manually later, just wanted to point out some downsides. |
In #638 (comment) I proposed a cofig format which would allow everyone to easily configure which elements should be handled by which heading option. |
Enhancement: Added support for `ConverterDefinition` in the heading options configuration. Closes #72. Closes ckeditor/ckeditor5#651. BREAKING CHANGE: `config.heading.options` format has changed. The valid `HeadingOption` syntax is now compatible with `ConverterDefinition`: `{ model: 'heading1', view: 'h2', title: 'Heading 1' }`.
Hm... I mistakenly closed this ticket with ckeditor/ckeditor5-heading#92. I reported this ticket to explain why "heading 1" option uses |
Currently, when you try to load
<h1>
into the editor (e.g. bysetData()
, but also by pasting), then it will be converted to a paragraph.This happens because the heading feature is by default configured to handle
h2
-h4
elements only ("Heading 1" means<h2>
, "Heading 2" means<h3>
and so on). You can find the default config here: https://github.com/ckeditor/ckeditor5-heading/blob/74559bb09f97c9272ba3c19ee2599fbd56b0b5e9/src/headingengine.js#L34-L41. And you can, of course, pass a different configuration toEditor.create()
– one which will also handle<h1>
elements:Why doesn't the heading feature handle
<h1>
? Why does "Heading 1" mean<h2>
?You can find the answer in Editor recommendations:
That's why the default setting is to start with
<h2>
which means that<h1>
features are not handled by the heading feature so they get converted to<p>
.Further considerations
When pasting content into the editor you will, currently, lose all
<h1>
elements. I wonder whether it wouldn't be better if they were converted to<h2>
automatically. That may be still confusing for developers (that's why I decided to create this ticket), but at least it will be more useful from the user perspective.WDYT?
The text was updated successfully, but these errors were encountered: