You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

221 lines
7.0 KiB

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