Opened 4 years ago

Closed 4 years ago

#8239 closed New Feature (invalid)

Don't break HTML comments out to separate lines

Reported by: fastballweb Owned by:
Priority: Normal Milestone:
Component: General Version: 3.6.1
Keywords: Cc:


The following is a convention I've seen used several places, including the default Wordpress theme:

<div id="divname">
</div><!-- #divname -->

The point is to make it clear which div element is being closed - very helpful in complicated markup where proper indenting cannot be maintained.

Occasionally I will use this convention in markup that makes it into CKEditor, whether through template snippets or pasted HTML. But the editor does this to it:

<div id="divname">
<!-- #divname -->

Now that the comment is on the next line, it is much more likely to get separated from the closing div tag it belongs to. It is also easier to miss it entirely.

I love everything about CKEditor source indenting except for this behavior of forced newlines for HTML comments.

My guess is that HTML comments by nature are almost always typed by hand. So it follows that:

  • Linebreaks, or lack thereof, may carry meaning
  • If the person wanted the comment on a new line, they easily could have entered it that way in the first place

In light of that, I suggest that this behavior be removed.

Change History (1)

comment:1 Changed 4 years ago by j.swiderski

  • Keywords HTML comments removed
  • Resolution set to invalid
  • Status changed from new to closed

One might like this convention the other might not.

For those who like it I would suggest to use the following code in config.js:

CKEDITOR.on( 'instanceReady', function( ev )
	var writer = ev.editor.dataProcessor.writer; 	
 	var dtd = CKEDITOR.dtd;	
	for ( var e in {}, dtd.$block, dtd.$inline ) )
		ev.editor.dataProcessor.writer.setRules( e, {					
			breakBeforeOpen : true,		
			breakAfterOpen : true,
			breakAfterClose : false,
			breakBeforeClose : true

Additional list of elements that can be used, can be found here:

Additional example:

Note: See TracTickets for help on using tickets.
© 2003 – 2015 CKSource – Frederico Knabben. All rights reserved. | Terms of use | Privacy policy