3 Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
\r
4 For licensing, see LICENSE.md or http://ckeditor.com/license
\r
8 <meta charset="utf-8">
\r
9 <title>HTML Compliant Output — CKEditor Sample</title>
\r
10 <script src="../../../ckeditor.js"></script>
\r
11 <script src="../../../samples/old/sample.js"></script>
\r
12 <link href="../../../samples/old/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/old/index.html">CKEditor Samples</a> » Producing HTML Compliant Output
\r
22 <div class="warning deprecated">
\r
23 This sample is not maintained anymore. Check out the <a href="http://sdk.ckeditor.com/">brand new samples in CKEditor SDK</a>.
\r
25 <div class="description">
\r
27 This sample shows how to configure CKEditor to output valid
\r
28 <a class="samples" href="http://www.w3.org/TR/html401/">HTML 4.01</a> code.
\r
29 Traditional HTML elements like <code><b></code>,
\r
30 <code><i></code>, and <code><font></code> are used in place of
\r
31 <code><strong></code>, <code><em></code>, and CSS styles.
\r
34 To add a CKEditor instance outputting legacy HTML 4.01 code, load the editor using a standard
\r
35 JavaScript call, and define CKEditor features to use the HTML compliant elements and attributes.
\r
38 A snippet of the configuration code can be seen below; check the source of this page for
\r
41 <pre class="samples">
\r
42 CKEDITOR.replace( '<em>textarea_id</em>', {
\r
43 coreStyles_bold: { element: 'b' },
\r
44 coreStyles_italic: { element: 'i' },
\r
48 attributes: { 'size': '#(size)' }
\r
54 <form action="../../../samples/sample_posteddata.php" method="post">
\r
56 <label for="editor1">
\r
59 <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
62 CKEDITOR.replace( 'editor1', {
\r
64 * Ensure that htmlwriter plugin, which is required for this sample, is loaded.
\r
66 extraPlugins: 'htmlwriter',
\r
69 * Style sheet for the contents
\r
71 contentsCss: 'body {color:#000; background-color#:FFF;}',
\r
74 * Simple HTML5 doctype
\r
76 docType: '<!DOCTYPE HTML>',
\r
79 * Allowed content rules which beside limiting allowed HTML
\r
80 * will also take care of transforming styles to attributes
\r
81 * (currently only for img - see transformation rules defined below).
\r
83 * Read more: http://docs.ckeditor.com/#!/guide/dev_advanced_content_filter
\r
86 'h1 h2 h3 p pre[align]; ' +
\r
87 'blockquote code kbd samp var del ins cite q b i u strike ul ol li hr table tbody tr td th caption; ' +
\r
88 'img[!src,alt,align,width,height]; font[!face]; font[!family]; font[!color]; font[!size]; font{!background-color}; a[!href]; a[!name]',
\r
93 coreStyles_bold: { element: 'b' },
\r
94 coreStyles_italic: { element: 'i' },
\r
95 coreStyles_underline: { element: 'u' },
\r
96 coreStyles_strike: { element: 'strike' },
\r
102 // Define the way font elements will be applied to the document.
\r
103 // The "font" element will be used.
\r
106 attributes: { 'face': '#(family)' }
\r
112 fontSize_sizes: 'xx-small/1;x-small/2;small/3;medium/4;large/5;x-large/6;xx-large/7',
\r
115 attributes: { 'size': '#(size)' }
\r
122 colorButton_foreStyle: {
\r
124 attributes: { 'color': '#(color)' }
\r
127 colorButton_backStyle: {
\r
129 styles: { 'background-color': '#(color)' }
\r
136 { name: 'Computer Code', element: 'code' },
\r
137 { name: 'Keyboard Phrase', element: 'kbd' },
\r
138 { name: 'Sample Text', element: 'samp' },
\r
139 { name: 'Variable', element: 'var' },
\r
140 { name: 'Deleted Text', element: 'del' },
\r
141 { name: 'Inserted Text', element: 'ins' },
\r
142 { name: 'Cited Work', element: 'cite' },
\r
143 { name: 'Inline Quotation', element: 'q' }
\r
147 pluginsLoaded: configureTransformations,
\r
148 loaded: configureHtmlWriter
\r
153 * Add missing content transformations.
\r
155 function configureTransformations( evt ) {
\r
156 var editor = evt.editor;
\r
158 editor.dataProcessor.htmlFilter.addRules( {
\r
160 style: function( value, element ) {
\r
161 // Return #RGB for background and border colors
\r
162 return CKEDITOR.tools.convertRgbToHex( value );
\r
167 // Default automatic content transformations do not yet take care of
\r
168 // align attributes on blocks, so we need to add our own transformation rules.
\r
169 function alignToAttribute( element ) {
\r
170 if ( element.styles[ 'text-align' ] ) {
\r
171 element.attributes.align = element.styles[ 'text-align' ];
\r
172 delete element.styles[ 'text-align' ];
\r
175 editor.filter.addTransformations( [
\r
176 [ { element: 'p', right: alignToAttribute } ],
\r
177 [ { element: 'h1', right: alignToAttribute } ],
\r
178 [ { element: 'h2', right: alignToAttribute } ],
\r
179 [ { element: 'h3', right: alignToAttribute } ],
\r
180 [ { element: 'pre', right: alignToAttribute } ]
\r
185 * Adjust the behavior of htmlWriter to make it output HTML like FCKeditor.
\r
187 function configureHtmlWriter( evt ) {
\r
188 var editor = evt.editor,
\r
189 dataProcessor = editor.dataProcessor;
\r
191 // Out self closing tags the HTML4 way, like <br>.
\r
192 dataProcessor.writer.selfClosingEnd = '>';
\r
194 // Make output formatting behave similar to FCKeditor.
\r
195 var dtd = CKEDITOR.dtd;
\r
196 for ( var e in CKEDITOR.tools.extend( {}, dtd.$nonBodyContent, dtd.$block, dtd.$listItem, dtd.$tableContent ) ) {
\r
197 dataProcessor.writer.setRules( e, {
\r
199 breakBeforeOpen: true,
\r
200 breakAfterOpen: false,
\r
201 breakBeforeClose: !dtd[ e ][ '#' ],
\r
202 breakAfterClose: true
\r
210 <input type="submit" value="Submit">
\r
216 CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a>
\r
219 Copyright © 2003-2015, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico
\r
220 Knabben. All rights reserved.
\r