ckeditor5 icon indicating copy to clipboard operation
ckeditor5 copied to clipboard

upcast 'p' element with attribute/class (?)

Open kuku711 opened this issue 2 years ago • 1 comments

📝 Provide detailed reproduction steps (if any)

I created conversion for upcast element to element

editor.conversion.for('upcast').elementToElement({
    view: { name: 'p', attributes: ['abcd']},
    model: .....
}

then i insert html <p abcd>aaa</p> (allowed attributes in schema 'paragraph') and debug the code, its no go through the upcasting

i checked it with div/ other elements and its works, just with 'p' isnt working... checked also with classes instead of attributes

✔️ Expected result

elementToElement function called and do the job

❌ Actual result

elementToElement function not called

📃 Other details

  • Browser: …
  • OS: …
  • First affected CKEditor version: …
  • Installed CKEditor plugins: …

If you'd like to see this fixed sooner, add a 👍 reaction to this post.

kuku711 avatar Mar 23 '22 10:03 kuku711

I'm also having the same issue. I have a model element that is block element type which basically gets downcasted to a paragraph with a special class attribute. I've found that the upcast process in filtering for p-tag elements with that special class to convert back to my model element does not work. I've tried setting priority to the highest, and still does not work.

Instead of downcasting/upcasting using paragraphs, I've tried "div" elements, but still, for some reason these just get automatically converted to paragraphs without any attributes at all. I've tried setting breakpoints in the upcast handler, and looks like it is never hit.

urbanspr1nter avatar Aug 08 '22 20:08 urbanspr1nter

Any news about this bug resolution?

fmauri-sumologic avatar Oct 03 '22 10:10 fmauri-sumologic

I'm not able to reproduce this issue. The following code works:

editor.model.schema.register( 'xyz', {
	inheritAllFrom: '$block',
	allowAttributes: [ 'foo' ]
} );

editor.conversion.for( 'upcast' ).elementToElement( {
	view: { 
		name: 'p', 
		attributes: [ 'abcd' ] 
	},
	model: ( viewElement, { writer } ) => {
		return writer.createElement( 'xyz', {
			foo: viewElement.getAttribute( 'abcd' )
		} );
	},
	converterPriority: 'high'
} );

editor.conversion.for( 'downcast' ).elementToElement( {
	model: {
		name: 'xyz',
		attributes: [ 'foo' ]
	},
	view: ( modelElement, { writer } ) => {
		return writer.createContainerElement( 'p', {
			abcd: modelElement.getAttribute( 'foo' )
		} );
	}
} );

niegowski avatar Oct 03 '22 14:10 niegowski