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