ckeditor/samples/old/htmlwriter/outputhtml.html
author indvd00m (gotoindvdum[at]gmail[dot]com)
Thu, 15 Dec 2016 18:10:20 +0300
changeset 0 44d330dccc59
permissions -rw-r--r--
Init sample
indvd00m@0
     1
<!DOCTYPE html>
indvd00m@0
     2
<!--
indvd00m@0
     3
Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
indvd00m@0
     4
For licensing, see LICENSE.md or http://ckeditor.com/license
indvd00m@0
     5
-->
indvd00m@0
     6
<html>
indvd00m@0
     7
<head>
indvd00m@0
     8
	<meta charset="utf-8">
indvd00m@0
     9
	<title>HTML Compliant Output &mdash; CKEditor Sample</title>
indvd00m@0
    10
	<script src="../../../ckeditor.js"></script>
indvd00m@0
    11
	<script src="../../../samples/old/sample.js"></script>
indvd00m@0
    12
	<link href="../../../samples/old/sample.css" rel="stylesheet">
indvd00m@0
    13
	<meta name="ckeditor-sample-required-plugins" content="sourcearea">
indvd00m@0
    14
	<meta name="ckeditor-sample-name" content="Output HTML">
indvd00m@0
    15
	<meta name="ckeditor-sample-group" content="Advanced Samples">
indvd00m@0
    16
	<meta name="ckeditor-sample-description" content="Configuring CKEditor to produce legacy HTML 4 code.">
indvd00m@0
    17
</head>
indvd00m@0
    18
<body>
indvd00m@0
    19
	<h1 class="samples">
indvd00m@0
    20
		<a href="../../../samples/old/index.html">CKEditor Samples</a> &raquo; Producing HTML Compliant Output
indvd00m@0
    21
	</h1>
indvd00m@0
    22
	<div class="warning deprecated">
indvd00m@0
    23
		This sample is not maintained anymore. Check out the <a href="http://sdk.ckeditor.com/">brand new samples in CKEditor SDK</a>.
indvd00m@0
    24
	</div>
indvd00m@0
    25
	<div class="description">
indvd00m@0
    26
		<p>
indvd00m@0
    27
			This sample shows how to configure CKEditor to output valid
indvd00m@0
    28
			<a class="samples" href="http://www.w3.org/TR/html401/">HTML 4.01</a> code.
indvd00m@0
    29
			Traditional HTML elements like <code>&lt;b&gt;</code>,
indvd00m@0
    30
			<code>&lt;i&gt;</code>, and <code>&lt;font&gt;</code> are used in place of
indvd00m@0
    31
			<code>&lt;strong&gt;</code>, <code>&lt;em&gt;</code>, and CSS styles.
indvd00m@0
    32
		</p>
indvd00m@0
    33
		<p>
indvd00m@0
    34
			To add a CKEditor instance outputting legacy HTML 4.01 code, load the editor using a standard
indvd00m@0
    35
			JavaScript call, and define CKEditor features to use the HTML compliant elements and attributes.
indvd00m@0
    36
		</p>
indvd00m@0
    37
		<p>
indvd00m@0
    38
			A snippet of the configuration code can be seen below; check the source of this page for
indvd00m@0
    39
			full definition:
indvd00m@0
    40
		</p>
indvd00m@0
    41
<pre class="samples">
indvd00m@0
    42
CKEDITOR.replace( '<em>textarea_id</em>', {
indvd00m@0
    43
	coreStyles_bold: { element: 'b' },
indvd00m@0
    44
	coreStyles_italic: { element: 'i' },
indvd00m@0
    45
indvd00m@0
    46
	fontSize_style: {
indvd00m@0
    47
		element: 'font',
indvd00m@0
    48
		attributes: { 'size': '#(size)' }
indvd00m@0
    49
	}
indvd00m@0
    50
indvd00m@0
    51
	...
indvd00m@0
    52
});</pre>
indvd00m@0
    53
	</div>
indvd00m@0
    54
	<form action="../../../samples/sample_posteddata.php" method="post">
indvd00m@0
    55
		<p>
indvd00m@0
    56
			<label for="editor1">
indvd00m@0
    57
				Editor 1:
indvd00m@0
    58
			</label>
indvd00m@0
    59
			<textarea cols="80" id="editor1" name="editor1" rows="10">&lt;p&gt;This is some &lt;b&gt;sample text&lt;/b&gt;. You are using &lt;a href="http://ckeditor.com/"&gt;CKEditor&lt;/a&gt;.&lt;/p&gt;</textarea>
indvd00m@0
    60
			<script>
indvd00m@0
    61
indvd00m@0
    62
				CKEDITOR.replace( 'editor1', {
indvd00m@0
    63
					/*
indvd00m@0
    64
					 * Ensure that htmlwriter plugin, which is required for this sample, is loaded.
indvd00m@0
    65
					 */
indvd00m@0
    66
					extraPlugins: 'htmlwriter',
indvd00m@0
    67
indvd00m@0
    68
					/*
indvd00m@0
    69
					 * Style sheet for the contents
indvd00m@0
    70
					 */
indvd00m@0
    71
					contentsCss: 'body {color:#000; background-color#:FFF;}',
indvd00m@0
    72
indvd00m@0
    73
					/*
indvd00m@0
    74
					 * Simple HTML5 doctype
indvd00m@0
    75
					 */
indvd00m@0
    76
					docType: '<!DOCTYPE HTML>',
indvd00m@0
    77
indvd00m@0
    78
					/*
indvd00m@0
    79
					 * Allowed content rules which beside limiting allowed HTML
indvd00m@0
    80
					 * will also take care of transforming styles to attributes
indvd00m@0
    81
					 * (currently only for img - see transformation rules defined below).
indvd00m@0
    82
					 *
indvd00m@0
    83
					 * Read more: http://docs.ckeditor.com/#!/guide/dev_advanced_content_filter
indvd00m@0
    84
					 */
indvd00m@0
    85
					allowedContent:
indvd00m@0
    86
						'h1 h2 h3 p pre[align]; ' +
indvd00m@0
    87
						'blockquote code kbd samp var del ins cite q b i u strike ul ol li hr table tbody tr td th caption; ' +
indvd00m@0
    88
						'img[!src,alt,align,width,height]; font[!face]; font[!family]; font[!color]; font[!size]; font{!background-color}; a[!href]; a[!name]',
indvd00m@0
    89
indvd00m@0
    90
					/*
indvd00m@0
    91
					 * Core styles.
indvd00m@0
    92
					 */
indvd00m@0
    93
					coreStyles_bold: { element: 'b' },
indvd00m@0
    94
					coreStyles_italic: { element: 'i' },
indvd00m@0
    95
					coreStyles_underline: { element: 'u' },
indvd00m@0
    96
					coreStyles_strike: { element: 'strike' },
indvd00m@0
    97
indvd00m@0
    98
					/*
indvd00m@0
    99
					 * Font face.
indvd00m@0
   100
					 */
indvd00m@0
   101
indvd00m@0
   102
					// Define the way font elements will be applied to the document.
indvd00m@0
   103
					// The "font" element will be used.
indvd00m@0
   104
					font_style: {
indvd00m@0
   105
						element: 'font',
indvd00m@0
   106
						attributes: { 'face': '#(family)' }
indvd00m@0
   107
					},
indvd00m@0
   108
indvd00m@0
   109
					/*
indvd00m@0
   110
					 * Font sizes.
indvd00m@0
   111
					 */
indvd00m@0
   112
					fontSize_sizes: 'xx-small/1;x-small/2;small/3;medium/4;large/5;x-large/6;xx-large/7',
indvd00m@0
   113
					fontSize_style: {
indvd00m@0
   114
						element: 'font',
indvd00m@0
   115
						attributes: { 'size': '#(size)' }
indvd00m@0
   116
					},
indvd00m@0
   117
indvd00m@0
   118
					/*
indvd00m@0
   119
					 * Font colors.
indvd00m@0
   120
					 */
indvd00m@0
   121
indvd00m@0
   122
					colorButton_foreStyle: {
indvd00m@0
   123
						element: 'font',
indvd00m@0
   124
						attributes: { 'color': '#(color)' }
indvd00m@0
   125
					},
indvd00m@0
   126
indvd00m@0
   127
					colorButton_backStyle: {
indvd00m@0
   128
						element: 'font',
indvd00m@0
   129
						styles: { 'background-color': '#(color)' }
indvd00m@0
   130
					},
indvd00m@0
   131
indvd00m@0
   132
					/*
indvd00m@0
   133
					 * Styles combo.
indvd00m@0
   134
					 */
indvd00m@0
   135
					stylesSet: [
indvd00m@0
   136
						{ name: 'Computer Code', element: 'code' },
indvd00m@0
   137
						{ name: 'Keyboard Phrase', element: 'kbd' },
indvd00m@0
   138
						{ name: 'Sample Text', element: 'samp' },
indvd00m@0
   139
						{ name: 'Variable', element: 'var' },
indvd00m@0
   140
						{ name: 'Deleted Text', element: 'del' },
indvd00m@0
   141
						{ name: 'Inserted Text', element: 'ins' },
indvd00m@0
   142
						{ name: 'Cited Work', element: 'cite' },
indvd00m@0
   143
						{ name: 'Inline Quotation', element: 'q' }
indvd00m@0
   144
					],
indvd00m@0
   145
indvd00m@0
   146
					on: {
indvd00m@0
   147
						pluginsLoaded: configureTransformations,
indvd00m@0
   148
						loaded: configureHtmlWriter
indvd00m@0
   149
					}
indvd00m@0
   150
				});
indvd00m@0
   151
indvd00m@0
   152
				/*
indvd00m@0
   153
				 * Add missing content transformations.
indvd00m@0
   154
				 */
indvd00m@0
   155
				function configureTransformations( evt ) {
indvd00m@0
   156
					var editor = evt.editor;
indvd00m@0
   157
indvd00m@0
   158
					editor.dataProcessor.htmlFilter.addRules( {
indvd00m@0
   159
						attributes: {
indvd00m@0
   160
							style: function( value, element ) {
indvd00m@0
   161
								// Return #RGB for background and border colors
indvd00m@0
   162
								return CKEDITOR.tools.convertRgbToHex( value );
indvd00m@0
   163
							}
indvd00m@0
   164
						}
indvd00m@0
   165
					} );
indvd00m@0
   166
indvd00m@0
   167
					// Default automatic content transformations do not yet take care of
indvd00m@0
   168
					// align attributes on blocks, so we need to add our own transformation rules.
indvd00m@0
   169
					function alignToAttribute( element ) {
indvd00m@0
   170
						if ( element.styles[ 'text-align' ] ) {
indvd00m@0
   171
							element.attributes.align = element.styles[ 'text-align' ];
indvd00m@0
   172
							delete element.styles[ 'text-align' ];
indvd00m@0
   173
						}
indvd00m@0
   174
					}
indvd00m@0
   175
					editor.filter.addTransformations( [
indvd00m@0
   176
						[ { element: 'p',	right: alignToAttribute } ],
indvd00m@0
   177
						[ { element: 'h1',	right: alignToAttribute } ],
indvd00m@0
   178
						[ { element: 'h2',	right: alignToAttribute } ],
indvd00m@0
   179
						[ { element: 'h3',	right: alignToAttribute } ],
indvd00m@0
   180
						[ { element: 'pre',	right: alignToAttribute } ]
indvd00m@0
   181
					] );
indvd00m@0
   182
				}
indvd00m@0
   183
indvd00m@0
   184
				/*
indvd00m@0
   185
				 * Adjust the behavior of htmlWriter to make it output HTML like FCKeditor.
indvd00m@0
   186
				 */
indvd00m@0
   187
				function configureHtmlWriter( evt ) {
indvd00m@0
   188
					var editor = evt.editor,
indvd00m@0
   189
						dataProcessor = editor.dataProcessor;
indvd00m@0
   190
indvd00m@0
   191
					// Out self closing tags the HTML4 way, like <br>.
indvd00m@0
   192
					dataProcessor.writer.selfClosingEnd = '>';
indvd00m@0
   193
indvd00m@0
   194
					// Make output formatting behave similar to FCKeditor.
indvd00m@0
   195
					var dtd = CKEDITOR.dtd;
indvd00m@0
   196
					for ( var e in CKEDITOR.tools.extend( {}, dtd.$nonBodyContent, dtd.$block, dtd.$listItem, dtd.$tableContent ) ) {
indvd00m@0
   197
						dataProcessor.writer.setRules( e, {
indvd00m@0
   198
							indent: true,
indvd00m@0
   199
							breakBeforeOpen: true,
indvd00m@0
   200
							breakAfterOpen: false,
indvd00m@0
   201
							breakBeforeClose: !dtd[ e ][ '#' ],
indvd00m@0
   202
							breakAfterClose: true
indvd00m@0
   203
						});
indvd00m@0
   204
					}
indvd00m@0
   205
				}
indvd00m@0
   206
indvd00m@0
   207
			</script>
indvd00m@0
   208
		</p>
indvd00m@0
   209
		<p>
indvd00m@0
   210
			<input type="submit" value="Submit">
indvd00m@0
   211
		</p>
indvd00m@0
   212
	</form>
indvd00m@0
   213
	<div id="footer">
indvd00m@0
   214
		<hr>
indvd00m@0
   215
		<p>
indvd00m@0
   216
			CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a>
indvd00m@0
   217
		</p>
indvd00m@0
   218
		<p id="copy">
indvd00m@0
   219
			Copyright &copy; 2003-2016, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico
indvd00m@0
   220
			Knabben. All rights reserved.
indvd00m@0
   221
		</p>
indvd00m@0
   222
	</div>
indvd00m@0
   223
</body>
indvd00m@0
   224
</html>