How Do I Output HTML code in FCKeditor Style?

This website contains links to software which is either no longer maintained or will be supported only until the end of 2019 (CKFinder 2). For the latest documentation about current CKSource projects, including software like CKEditor 4/CKEditor 5, CKFinder 3, Cloud Services, Letters, Accessibility Checker, please visit the new documentation website.

If you look for an information about very old versions of CKEditor, FCKeditor and CKFinder check also the CKEditor forum, which was closed in 2015. If not, please head to StackOverflow for support.

 
(3 intermediate revisions by 2 users not shown)
Line 3: Line 3:
 
<source lang="html4strict">
 
<source lang="html4strict">
 
<p>Some text</p>
 
<p>Some text</p>
 
<p>First line<br />
 
Second line<br />
 
Third line</p>
 
  
 
<table width="200" cellspacing="1" cellpadding="1" border="1" height="100">
 
<table width="200" cellspacing="1" cellpadding="1" border="1" height="100">
Line 59: Line 55:
 
var writer = ev.editor.dataProcessor.writer;  
 
var writer = ev.editor.dataProcessor.writer;  
 
// The character sequence to use for every indentation step.
 
// The character sequence to use for every indentation step.
writer.indentationChars = '    ';
+
writer.indentationChars = '    ';
  
 
var dtd = CKEDITOR.dtd;
 
var dtd = CKEDITOR.dtd;
//Elements taken as an example are: block elements (div or p), list items (li, dd) and table elements (td, tbody).
+
// Elements taken as an example are: block-level elements (div or p), list items (li, dd), and table elements (td, tbody).
 
for ( var e in CKEDITOR.tools.extend( {}, dtd.$block, dtd.$listItem, dtd.$tableContent ) )
 
for ( var e in CKEDITOR.tools.extend( {}, dtd.$block, dtd.$listItem, dtd.$tableContent ) )
 
{
 
{
 
ev.editor.dataProcessor.writer.setRules( e, {
 
ev.editor.dataProcessor.writer.setRules( e, {
// Indicates that tag causes indentation on line breaks inside of it.
+
// Indicates that an element creates indentation on line breaks that it contains.
 
indent : false,
 
indent : false,
// Insert a line break before tag.
+
// Inserts a line break before a tag.
 
breakBeforeOpen : true,
 
breakBeforeOpen : true,
// Insert a line break after tag.
+
// Inserts a line break after a tag.
 
breakAfterOpen : false,
 
breakAfterOpen : false,
// Insert a line break before closing tag.
+
// Inserts a line break before the closing tag.
 
breakBeforeClose : false,
 
breakBeforeClose : false,
// Insert a line break after closing tag.
+
// Inserts a line break after the closing tag.
 
breakAfterClose : true
 
breakAfterClose : true
 
});
 
});
Line 86: Line 82:
 
}
 
}
  
//You can also apply the rules to the single elements.
+
// You can also apply the rules to a single element.
 
ev.editor.dataProcessor.writer.setRules( 'table',
 
ev.editor.dataProcessor.writer.setRules( 'table',
 
{
 
{
 
indent : true
 
indent : true
 
});
 
});
 +
 +
ev.editor.dataProcessor.writer.setRules( 'form',
 +
{
 +
indent : true
 +
});
 
});
 
});
 
</source>
 
</source>
  
 
More information about HTML source formatting can also be found in the [[CKEditor_3.x/Developers_Guide/Output_Formatting|Output Formatting]] article from the [[CKEditor_3.x/Developers_Guide|Developer's Guide]].
 
More information about HTML source formatting can also be found in the [[CKEditor_3.x/Developers_Guide/Output_Formatting|Output Formatting]] article from the [[CKEditor_3.x/Developers_Guide|Developer's Guide]].

Latest revision as of 09:14, 6 June 2011

In FCKeditor 2.x, the predecessor of CKEditor 3.x, HTML source was formatted in the following way, using spaces and placing the element tags and contents in one line:

<p>Some text</p>

<table width="200" cellspacing="1" cellpadding="1" border="1" height="100">
    <tbody>
        <tr>
            <td>&nbsp;cell_1.1</td>
            <td>&nbsp;cell_1.2</td>
        </tr> 
    </tbody>
</table>

<ul>
    <li>item_1</li>
    <li>item_2</li>
</ul>

CKEditor 3.x formats HTML source code in the following way, using tabs and indenting element contents:

<p>
	Some text</p>

<p>
	First line<br />
	Second line<br />
	Third line</p>

<table border="1" cellpadding="1" cellspacing="1" height="100" width="200">
	<tbody>
		<tr>
			<td>
				&nbsp;cell_1.1</td>
			<td>
				&nbsp;cell_1.2</td>
		</tr>
	</tbody>
</table>

<ul>
	<li>
		item_1</li>
	<li>
		item_2</li>
</ul>

If you would like to go back to FCKeditor formatting, you can achieve it by adding the following code to your config.js file:

CKEDITOR.on( 'instanceReady', function( ev )
{
	var writer = ev.editor.dataProcessor.writer; 
	// The character sequence to use for every indentation step.
	writer.indentationChars = '    ';

	var dtd = CKEDITOR.dtd;
	// Elements taken as an example are: block-level elements (div or p), list items (li, dd), and table elements (td, tbody).
	for ( var e in CKEDITOR.tools.extend( {}, dtd.$block, dtd.$listItem, dtd.$tableContent ) )
	{
		ev.editor.dataProcessor.writer.setRules( e, {
			// Indicates that an element creates indentation on line breaks that it contains.
			indent : false,
			// Inserts a line break before a tag.
			breakBeforeOpen : true,
			// Inserts a line break after a tag.
			breakAfterOpen : false,
			// Inserts a line break before the closing tag.
			breakBeforeClose : false,
			// Inserts a line break after the closing tag.
			breakAfterClose : true
		});
	}
	
	for ( var e in CKEDITOR.tools.extend( {}, dtd.$list, dtd.$listItem, dtd.$tableContent ) )
	{
		ev.editor.dataProcessor.writer.setRules( e, {			
			indent : true,
		});
	}

	// You can also apply the rules to a single element.
	ev.editor.dataProcessor.writer.setRules( 'table',
	{ 		
		indent : true
	});	
	
	ev.editor.dataProcessor.writer.setRules( 'form',
	{ 		
		indent : true
	});		
});

More information about HTML source formatting can also be found in the Output Formatting article from the Developer's Guide.

This page was last edited on 6 June 2011, at 09:14.