Opened 12 years ago

Last modified 11 years ago

#8726 closed New Feature

Allow for filtering HTML data — at Initial Version

Reported by: Jakub Ś Owned by:
Priority: Normal Milestone:
Component: Core : Parser Version: 3.0
Keywords: Cc:

Description

This ticket is related to - #588

Some clients ask about possibility to filter/block/modify certain HTML elements E.g.

  1. Remove all elements except strong and u tags and text nodes that are inside forbidden elements.
  2. Delete all a tags but leave their contents
  3. Wrap all images in spans

Below are some incomplete solutions:

on :{
					'pluginsLoaded' : function( evt ){ //it must be done before "instanceReady" to make the tag blocking in effect
						evt.editor.dataProcessor.dataFilter.addRules({
							elements :{
								span : function( element ) {
									//the rule for img is dumm as it keeps adding span tags the idea is to remove span and let img add it
									if ( element._processed )
										return;
									if(element.attributes.id == 'cke_image_s_wrapper')
										delete element.name;
								},
								img : function( element )
								{
									if ( element._processed )
										return;
									element._processed = 1;
									element.alt = (!element.attributes.alt ? element.attributes.alt : 'An image');

									var parent = new CKEDITOR.htmlParser.element('span');
									parent.attributes.style='border:10px solid #f00;display: inline-block;';
									parent.attributes.id='cke_image_s_wrapper';
									parent.add(element);
									parent._processed = 1
									return parent;
								}
							}
						});
					}
				}
on :
					  {
						  'pluginsLoaded' : function( evt )  //it must be done before "instanceReady" to make the tag blocking in effect
						  {							  
							  evt.editor.dataProcessor.dataFilter.addRules(
									  {
										  elements :
										  {
											a : function( element ) 
											{													
												delete element.name												
											}								
										  }
									  } );
						  }
					  }

Why incomplete?
This works on initial data, when switching to source and back, when pasting but it does not work with plugins (for the above with image and link plugins).

The solution here might be some plugin-filter through which all data would have to go through when it is enabled in configuration options.

For such plugin used could define a set of rules according to his needs (perhaps again in configuration option?).

Change History (0)

Note: See TracTickets for help on using tickets.
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy