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