3 Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
\r
4 For licensing, see LICENSE.html or http://ckeditor.com/license
\r
8 <title>HTML Compliant Output — CKEditor Sample</title>
\r
9 <meta charset="utf-8">
\r
10 <script src="../../../ckeditor.js"></script>
\r
11 <script src="../../../samples/sample.js"></script>
\r
12 <link href="../../../samples/sample.css" rel="stylesheet">
\r
13 <meta name="ckeditor-sample-required-plugins" content="sourcearea">
\r
14 <meta name="ckeditor-sample-name" content="Output HTML">
\r
15 <meta name="ckeditor-sample-group" content="Advanced Samples">
\r
16 <meta name="ckeditor-sample-description" content="Configuring CKEditor to produce legacy HTML 4 code.">
\r
19 <h1 class="samples">
\r
20 <a href="../../../samples/index.html">CKEditor Samples</a> » Producing HTML Compliant Output
\r
22 <div class="description">
\r
24 This sample shows how to configure CKEditor to output valid
\r
25 <a class="samples" href="http://www.w3.org/TR/html401/">HTML 4.01</a> code.
\r
26 Traditional HTML elements like <code><b></code>,
\r
27 <code><i></code>, and <code><font></code> are used in place of
\r
28 <code><strong></code>, <code><em></code>, and CSS styles.
\r
31 To add a CKEditor instance outputting legacy HTML 4.01 code, load the editor using a standard
\r
32 JavaScript call, and define CKEditor features to use the HTML compliant elements and attributes.
\r
35 A snippet of the configuration code can be seen below; check the source of this page for
\r
38 <pre class="samples">
\r
39 CKEDITOR.replace( '<em>textarea_id</em>', {
\r
40 coreStyles_bold: { element: 'b' },
\r
41 coreStyles_italic: { element: 'i' },
\r
45 attributes: { 'size': '#(size)' }
\r
51 <form action="../../../samples/sample_posteddata.php" method="post">
\r
53 <label for="editor1">
\r
56 <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
59 CKEDITOR.replace( 'editor1', {
\r
61 * Ensure that htmlwriter plugin, which is required for this sample, is loaded.
\r
63 extraPlugins: 'htmlwriter',
\r
66 * Style sheet for the contents
\r
68 contentsCss: 'body {color:#000; background-color#:FFF;}',
\r
71 * Simple HTML5 doctype
\r
73 docType: '<!DOCTYPE HTML>',
\r
78 coreStyles_bold: { element: 'b' },
\r
79 coreStyles_italic: { element: 'i' },
\r
80 coreStyles_underline: { element: 'u' },
\r
81 coreStyles_strike: { element: 'strike' },
\r
87 // Define the way font elements will be applied to the document.
\r
88 // The "font" element will be used.
\r
91 attributes: { 'face': '#(family)' }
\r
97 fontSize_sizes: 'xx-small/1;x-small/2;small/3;medium/4;large/5;x-large/6;xx-large/7',
\r
100 attributes: { 'size': '#(size)' }
\r
106 colorButton_enableMore: true,
\r
108 colorButton_foreStyle: {
\r
110 attributes: { 'color': '#(color)' }
\r
113 colorButton_backStyle: {
\r
115 styles: { 'background-color': '#(color)' }
\r
122 { name: 'Computer Code', element: 'code' },
\r
123 { name: 'Keyboard Phrase', element: 'kbd' },
\r
124 { name: 'Sample Text', element: 'samp' },
\r
125 { name: 'Variable', element: 'var' },
\r
126 { name: 'Deleted Text', element: 'del' },
\r
127 { name: 'Inserted Text', element: 'ins' },
\r
128 { name: 'Cited Work', element: 'cite' },
\r
129 { name: 'Inline Quotation', element: 'q' }
\r
132 on: { 'instanceReady': configureHtmlOutput }
\r
136 * Adjust the behavior of the dataProcessor to avoid styles
\r
137 * and make it look like FCKeditor HTML output.
\r
139 function configureHtmlOutput( ev ) {
\r
140 var editor = ev.editor,
\r
141 dataProcessor = editor.dataProcessor,
\r
142 htmlFilter = dataProcessor && dataProcessor.htmlFilter;
\r
144 // Out self closing tags the HTML4 way, like <br>.
\r
145 dataProcessor.writer.selfClosingEnd = '>';
\r
147 // Make output formatting behave similar to FCKeditor
\r
148 var dtd = CKEDITOR.dtd;
\r
149 for ( var e in CKEDITOR.tools.extend( {}, dtd.$nonBodyContent, dtd.$block, dtd.$listItem, dtd.$tableContent ) ) {
\r
150 dataProcessor.writer.setRules( e, {
\r
152 breakBeforeOpen: true,
\r
153 breakAfterOpen: false,
\r
154 breakBeforeClose: !dtd[ e ][ '#' ],
\r
155 breakAfterClose: true
\r
159 // Output properties as attributes, not styles.
\r
160 htmlFilter.addRules( {
\r
162 $: function( element ) {
\r
163 // Output dimensions of images as width and height
\r
164 if ( element.name == 'img' ) {
\r
165 var style = element.attributes.style;
\r
168 // Get the width from the style.
\r
169 var match = ( /(?:^|\s)width\s*:\s*(\d+)px/i ).exec( style ),
\r
170 width = match && match[ 1 ];
\r
172 // Get the height from the style.
\r
173 match = ( /(?:^|\s)height\s*:\s*(\d+)px/i ).exec( style );
\r
174 var height = match && match[ 1 ];
\r
177 element.attributes.style = element.attributes.style.replace( /(?:^|\s)width\s*:\s*(\d+)px;?/i , '' );
\r
178 element.attributes.width = width;
\r
182 element.attributes.style = element.attributes.style.replace( /(?:^|\s)height\s*:\s*(\d+)px;?/i , '' );
\r
183 element.attributes.height = height;
\r
188 // Output alignment of paragraphs using align
\r
189 if ( element.name == 'p' ) {
\r
190 style = element.attributes.style;
\r
193 // Get the align from the style.
\r
194 match = ( /(?:^|\s)text-align\s*:\s*(\w*);/i ).exec( style );
\r
195 var align = match && match[ 1 ];
\r
198 element.attributes.style = element.attributes.style.replace( /(?:^|\s)text-align\s*:\s*(\w*);?/i , '' );
\r
199 element.attributes.align = align;
\r
204 if ( !element.attributes.style )
\r
205 delete element.attributes.style;
\r
212 style: function( value, element ) {
\r
213 // Return #RGB for background and border colors
\r
214 return CKEDITOR.tools.convertRgbToHex( value );
\r
223 <input type="submit" value="Submit">
\r
229 CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a>
\r
232 Copyright © 2003-2013, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico
\r
233 Knabben. All rights reserved.
\r