outputhtml.html 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <!DOCTYPE html>
  2. <!--
  3. Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
  4. For licensing, see LICENSE.md or http://ckeditor.com/license
  5. -->
  6. <html>
  7. <head>
  8. <meta charset="utf-8">
  9. <title>HTML Compliant Output &mdash; 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.">
  17. </head>
  18. <body>
  19. <h1 class="samples">
  20. <a href="../../../samples/old/index.html">CKEditor Samples</a> &raquo; Producing HTML Compliant Output
  21. </h1>
  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>.
  24. </div>
  25. <div class="description">
  26. <p>
  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>&lt;b&gt;</code>,
  30. <code>&lt;i&gt;</code>, and <code>&lt;font&gt;</code> are used in place of
  31. <code>&lt;strong&gt;</code>, <code>&lt;em&gt;</code>, and CSS styles.
  32. </p>
  33. <p>
  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.
  36. </p>
  37. <p>
  38. A snippet of the configuration code can be seen below; check the source of this page for
  39. full definition:
  40. </p>
  41. <pre class="samples">
  42. CKEDITOR.replace( '<em>textarea_id</em>', {
  43. coreStyles_bold: { element: 'b' },
  44. coreStyles_italic: { element: 'i' },
  45. fontSize_style: {
  46. element: 'font',
  47. attributes: { 'size': '#(size)' }
  48. }
  49. ...
  50. });</pre>
  51. </div>
  52. <form action="../../../samples/sample_posteddata.php" method="post">
  53. <p>
  54. <label for="editor1">
  55. Editor 1:
  56. </label>
  57. <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>
  58. <script>
  59. CKEDITOR.replace( 'editor1', {
  60. /*
  61. * Ensure that htmlwriter plugin, which is required for this sample, is loaded.
  62. */
  63. extraPlugins: 'htmlwriter',
  64. /*
  65. * Style sheet for the contents
  66. */
  67. contentsCss: 'body {color:#000; background-color#:FFF;}',
  68. /*
  69. * Simple HTML5 doctype
  70. */
  71. docType: '<!DOCTYPE HTML>',
  72. /*
  73. * Allowed content rules which beside limiting allowed HTML
  74. * will also take care of transforming styles to attributes
  75. * (currently only for img - see transformation rules defined below).
  76. *
  77. * Read more: http://docs.ckeditor.com/#!/guide/dev_advanced_content_filter
  78. */
  79. allowedContent:
  80. 'h1 h2 h3 p pre[align]; ' +
  81. 'blockquote code kbd samp var del ins cite q b i u strike ul ol li hr table tbody tr td th caption; ' +
  82. 'img[!src,alt,align,width,height]; font[!face]; font[!family]; font[!color]; font[!size]; font{!background-color}; a[!href]; a[!name]',
  83. /*
  84. * Core styles.
  85. */
  86. coreStyles_bold: { element: 'b' },
  87. coreStyles_italic: { element: 'i' },
  88. coreStyles_underline: { element: 'u' },
  89. coreStyles_strike: { element: 'strike' },
  90. /*
  91. * Font face.
  92. */
  93. // Define the way font elements will be applied to the document.
  94. // The "font" element will be used.
  95. font_style: {
  96. element: 'font',
  97. attributes: { 'face': '#(family)' }
  98. },
  99. /*
  100. * Font sizes.
  101. */
  102. fontSize_sizes: 'xx-small/1;x-small/2;small/3;medium/4;large/5;x-large/6;xx-large/7',
  103. fontSize_style: {
  104. element: 'font',
  105. attributes: { 'size': '#(size)' }
  106. },
  107. /*
  108. * Font colors.
  109. */
  110. colorButton_foreStyle: {
  111. element: 'font',
  112. attributes: { 'color': '#(color)' }
  113. },
  114. colorButton_backStyle: {
  115. element: 'font',
  116. styles: { 'background-color': '#(color)' }
  117. },
  118. /*
  119. * Styles combo.
  120. */
  121. stylesSet: [
  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' }
  130. ],
  131. on: {
  132. pluginsLoaded: configureTransformations,
  133. loaded: configureHtmlWriter
  134. }
  135. });
  136. /*
  137. * Add missing content transformations.
  138. */
  139. function configureTransformations( evt ) {
  140. var editor = evt.editor;
  141. editor.dataProcessor.htmlFilter.addRules( {
  142. attributes: {
  143. style: function( value, element ) {
  144. // Return #RGB for background and border colors
  145. return CKEDITOR.tools.convertRgbToHex( value );
  146. }
  147. }
  148. } );
  149. // Default automatic content transformations do not yet take care of
  150. // align attributes on blocks, so we need to add our own transformation rules.
  151. function alignToAttribute( element ) {
  152. if ( element.styles[ 'text-align' ] ) {
  153. element.attributes.align = element.styles[ 'text-align' ];
  154. delete element.styles[ 'text-align' ];
  155. }
  156. }
  157. editor.filter.addTransformations( [
  158. [ { element: 'p', right: alignToAttribute } ],
  159. [ { element: 'h1', right: alignToAttribute } ],
  160. [ { element: 'h2', right: alignToAttribute } ],
  161. [ { element: 'h3', right: alignToAttribute } ],
  162. [ { element: 'pre', right: alignToAttribute } ]
  163. ] );
  164. }
  165. /*
  166. * Adjust the behavior of htmlWriter to make it output HTML like FCKeditor.
  167. */
  168. function configureHtmlWriter( evt ) {
  169. var editor = evt.editor,
  170. dataProcessor = editor.dataProcessor;
  171. // Out self closing tags the HTML4 way, like <br>.
  172. dataProcessor.writer.selfClosingEnd = '>';
  173. // Make output formatting behave similar to FCKeditor.
  174. var dtd = CKEDITOR.dtd;
  175. for ( var e in CKEDITOR.tools.extend( {}, dtd.$nonBodyContent, dtd.$block, dtd.$listItem, dtd.$tableContent ) ) {
  176. dataProcessor.writer.setRules( e, {
  177. indent: true,
  178. breakBeforeOpen: true,
  179. breakAfterOpen: false,
  180. breakBeforeClose: !dtd[ e ][ '#' ],
  181. breakAfterClose: true
  182. });
  183. }
  184. }
  185. </script>
  186. </p>
  187. <p>
  188. <input type="submit" value="Submit">
  189. </p>
  190. </form>
  191. <div id="footer">
  192. <hr>
  193. <p>
  194. CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a>
  195. </p>
  196. <p id="copy">
  197. Copyright &copy; 2003-2015, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico
  198. Knabben. All rights reserved.
  199. </p>
  200. </div>
  201. </body>
  202. </html>