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
76 * Allowed content rules which beside limiting allowed HTML
\r
77 * will also take care of transforming styles to attributes
\r
78 * (currently only for img - see transformation rules defined below).
\r
80 * Read more: http://docs.ckeditor.com/#!/guide/dev_advanced_content_filter
\r
83 'h1 h2 h3 p pre[align]; ' +
\r
84 'blockquote code kbd samp var del ins cite q b i u strike ul ol li hr table tbody tr td th caption; ' +
\r
85 'img[!src,alt,align,width,height]; font[!face]; font[!family]; font[!color]; font[!size]; font{!background-color}; a[!href]; a[!name]',
\r
90 coreStyles_bold: { element: 'b' },
\r
91 coreStyles_italic: { element: 'i' },
\r
92 coreStyles_underline: { element: 'u' },
\r
93 coreStyles_strike: { element: 'strike' },
\r
99 // Define the way font elements will be applied to the document.
\r
100 // The "font" element will be used.
\r
103 attributes: { 'face': '#(family)' }
\r
109 fontSize_sizes: 'xx-small/1;x-small/2;small/3;medium/4;large/5;x-large/6;xx-large/7',
\r
112 attributes: { 'size': '#(size)' }
\r
119 colorButton_foreStyle: {
\r
121 attributes: { 'color': '#(color)' }
\r
124 colorButton_backStyle: {
\r
126 styles: { 'background-color': '#(color)' }
\r
133 { name: 'Computer Code', element: 'code' },
\r
134 { name: 'Keyboard Phrase', element: 'kbd' },
\r
135 { name: 'Sample Text', element: 'samp' },
\r
136 { name: 'Variable', element: 'var' },
\r
137 { name: 'Deleted Text', element: 'del' },
\r
138 { name: 'Inserted Text', element: 'ins' },
\r
139 { name: 'Cited Work', element: 'cite' },
\r
140 { name: 'Inline Quotation', element: 'q' }
\r
144 pluginsLoaded: configureTransformations,
\r
145 loaded: configureHtmlWriter
\r
150 * Add missing content transformations.
\r
152 function configureTransformations( evt ) {
\r
153 var editor = evt.editor;
\r
155 editor.dataProcessor.htmlFilter.addRules( {
\r
157 style: function( value, element ) {
\r
158 // Return #RGB for background and border colors
\r
159 return CKEDITOR.tools.convertRgbToHex( value );
\r
164 // Default automatic content transformations do not yet take care of
\r
165 // align attributes on blocks, so we need to add our own transformation rules.
\r
166 function alignToAttribute( element ) {
\r
167 if ( element.styles[ 'text-align' ] ) {
\r
168 element.attributes.align = element.styles[ 'text-align' ];
\r
169 delete element.styles[ 'text-align' ];
\r
172 editor.filter.addTransformations( [
\r
173 [ { element: 'p', right: alignToAttribute } ],
\r
174 [ { element: 'h1', right: alignToAttribute } ],
\r
175 [ { element: 'h2', right: alignToAttribute } ],
\r
176 [ { element: 'h3', right: alignToAttribute } ],
\r
177 [ { element: 'pre', right: alignToAttribute } ]
\r
182 * Adjust the behavior of htmlWriter to make it output HTML like FCKeditor.
\r
184 function configureHtmlWriter( evt ) {
\r
185 var editor = evt.editor,
\r
186 dataProcessor = editor.dataProcessor;
\r
188 // Out self closing tags the HTML4 way, like <br>.
\r
189 dataProcessor.writer.selfClosingEnd = '>';
\r
191 // Make output formatting behave similar to FCKeditor.
\r
192 var dtd = CKEDITOR.dtd;
\r
193 for ( var e in CKEDITOR.tools.extend( {}, dtd.$nonBodyContent, dtd.$block, dtd.$listItem, dtd.$tableContent ) ) {
\r
194 dataProcessor.writer.setRules( e, {
\r
196 breakBeforeOpen: true,
\r
197 breakAfterOpen: false,
\r
198 breakBeforeClose: !dtd[ e ][ '#' ],
\r
199 breakAfterClose: true
\r
207 <input type="submit" value="Submit">
\r
213 CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a>
\r
216 Copyright © 2003-2013, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico
\r
217 Knabben. All rights reserved.
\r