1 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
4 For licensing, see LICENSE.html or http://ckeditor.com/license
6 <html xmlns=
"http://www.w3.org/1999/xhtml">
8 <title>HTML Compliant Output
— CKEditor Sample
</title>
9 <meta content=
"text/html; charset=utf-8" http-equiv=
"content-type" />
10 <script type=
"text/javascript" src=
"../ckeditor.js"></script>
11 <script src=
"sample.js" type=
"text/javascript"></script>
12 <link href=
"sample.css" rel=
"stylesheet" type=
"text/css" />
16 CKEditor Sample
— Producing HTML Compliant Output
18 <div class=
"description">
20 This sample shows how to configure CKEditor to output valid
21 <a class=
"samples" href=
"http://www.w3.org/TR/html401/">HTML
4.01</a> code.
22 Traditional HTML elements like
<code><b
></code>,
23 <code><i
></code>, and
<code><font
></code> are used in place of
24 <code><strong
></code>,
<code><em
></code>, and CSS styles.
27 To add a CKEditor instance outputting legacy HTML
4.01 code, load the editor using a standard
28 JavaScript call, and define CKEditor features to use the HTML compliant elements and attributes.
31 A snippet of the configuration code can be seen below; check the source of this page for
34 <pre class=
"samples">CKEDITOR.replace( '
<em>textarea_id
</em>',
36 coreStyles_bold : { element : 'b' },
37 coreStyles_italic : { element : 'i' },
42 attributes : { 'size' : '#(size)' }
45 // More definitions follow.
49 <!-- This <div> holds alert messages to be display in the sample page. -->
53 <strong>CKEditor requires JavaScript to run
</strong>. In a browser with no JavaScript
54 support, like yours, you should still see the contents (HTML data) and you should
55 be able to edit it normally, without a rich editor interface.
59 <form action=
"sample_posteddata.php" method=
"post">
63 <textarea cols=
"80" id=
"editor1" name=
"editor1" rows=
"10"><p
>This is some
<b
>sample text
</b
>. You are using
<a
href=
"http://ckeditor.com/">CKEditor
</a
>.
</p
></textarea>
64 <script type=
"text/javascript">
67 CKEDITOR.replace( 'editor1',
70 * Style sheet for the contents
72 contentsCss : 'body {color:#
000; background-color#:FFF;}',
75 * Simple HTML5 doctype
77 docType : '
<!DOCTYPE HTML
>',
82 coreStyles_bold : { element : 'b' },
83 coreStyles_italic : { element : 'i' },
84 coreStyles_underline : { element : 'u'},
85 coreStyles_strike : { element : 'strike' },
90 // Define the way font elements will be applied to the document. The
"font"
91 // element will be used.
95 attributes : { 'face' : '#(family)' }
101 fontSize_sizes : 'xx-small/
1;x-small/
2;small/
3;medium/
4;large/
5;x-large/
6;xx-large/
7',
105 attributes : { 'size' : '#(size)' }
111 colorButton_enableMore : true,
113 colorButton_foreStyle :
116 attributes : { 'color' : '#(color)' }
119 colorButton_backStyle :
122 styles : { 'background-color' : '#(color)' }
130 { name : 'Computer Code', element : 'code' },
131 { name : 'Keyboard Phrase', element : 'kbd' },
132 { name : 'Sample Text', element : 'samp' },
133 { name : 'Variable', element : 'var' },
135 { name : 'Deleted Text', element : 'del' },
136 { name : 'Inserted Text', element : 'ins' },
138 { name : 'Cited Work', element : 'cite' },
139 { name : 'Inline Quotation', element : 'q' }
142 on : { 'instanceReady' : configureHtmlOutput }
146 * Adjust the behavior of the dataProcessor to avoid styles
147 * and make it look like FCKeditor HTML output.
149 function configureHtmlOutput( ev )
151 var editor = ev.editor,
152 dataProcessor = editor.dataProcessor,
153 htmlFilter = dataProcessor && dataProcessor.htmlFilter;
155 // Out self closing tags the HTML4 way, like
<br>.
156 dataProcessor.writer.selfClosingEnd = '
>';
158 // Make output formatting behave similar to FCKeditor
159 var dtd = CKEDITOR.dtd;
160 for ( var e in CKEDITOR.tools.extend( {}, dtd.$nonBodyContent, dtd.$block, dtd.$listItem, dtd.$tableContent ) )
162 dataProcessor.writer.setRules( e,
165 breakBeforeOpen : true,
166 breakAfterOpen : false,
167 breakBeforeClose : !dtd[ e ][ '#' ],
168 breakAfterClose : true
172 // Output properties as attributes, not styles.
177 $ : function( element )
179 // Output dimensions of images as width and height
180 if ( element.name == 'img' )
182 var style = element.attributes.style;
186 // Get the width from the style.
187 var match = /(?:^|\s)width\s*:\s*(\d+)px/i.exec( style ),
188 width = match && match[
1];
190 // Get the height from the style.
191 match = /(?:^|\s)height\s*:\s*(\d+)px/i.exec( style );
192 var height = match && match[
1];
196 element.attributes.style = element.attributes.style.replace( /(?:^|\s)width\s*:\s*(\d+)px;?/i , '' );
197 element.attributes.width = width;
202 element.attributes.style = element.attributes.style.replace( /(?:^|\s)height\s*:\s*(\d+)px;?/i , '' );
203 element.attributes.height = height;
208 // Output alignment of paragraphs using align
209 if ( element.name == 'p' )
211 style = element.attributes.style;
215 // Get the align from the style.
216 match = /(?:^|\s)text-align\s*:\s*(\w*);/i.exec( style );
217 var align = match && match[
1];
221 element.attributes.style = element.attributes.style.replace( /(?:^|\s)text-align\s*:\s*(\w*);?/i , '' );
222 element.attributes.align = align;
227 if ( !element.attributes.style )
228 delete element.attributes.style;
236 style : function( value, element )
238 // Return #RGB for background and border colors
239 return convertRGBToHex( value );
247 * Convert a CSS rgb(R, G, B) color back to #RRGGBB format.
248 * @param Css style string (can include more than one color
249 * @return Converted css style.
251 function convertRGBToHex( cssStyle )
253 return cssStyle.replace( /(?:rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\))/gi, function( match, red, green, blue )
255 red = parseInt( red,
10 ).toString(
16 );
256 green = parseInt( green,
10 ).toString(
16 );
257 blue = parseInt( blue,
10 ).toString(
16 );
258 var color = [red, green, blue] ;
260 // Add padding zeros if the hex value is less than
0x10.
261 for ( var i =
0 ; i < color.length ; i++ )
262 color[i] = String( '
0' + color[i] ).slice( -
2 ) ;
264 return '#' + color.join( '' ) ;
271 <input type=
"submit" value=
"Submit" />
277 CKEditor - The text editor for the Internet -
<a class=
"samples" href=
"http://ckeditor.com/">http://ckeditor.com
</a>
280 Copyright
© 2003-
2011,
<a class=
"samples" href=
"http://cksource.com/">CKSource
</a> - Frederico
281 Knabben. All rights reserved.