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