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.

237 lines
7.3 KiB

  1. <!DOCTYPE html>
  2. <!--
  3. Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
  4. For licensing, see LICENSE.html or http://ckeditor.com/license
  5. -->
  6. <html>
  7. <head>
  8. <title>HTML Compliant Output &mdash; CKEditor Sample</title>
  9. <meta charset="utf-8">
  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. * Core styles.
  71. */
  72. coreStyles_bold: { element: 'b' },
  73. coreStyles_italic: { element: 'i' },
  74. coreStyles_underline: { element: 'u' },
  75. coreStyles_strike: { element: 'strike' },
  76. /*
  77. * Font face.
  78. */
  79. // Define the way font elements will be applied to the document.
  80. // The "font" element will be used.
  81. font_style: {
  82. element: 'font',
  83. attributes: { 'face': '#(family)' }
  84. },
  85. /*
  86. * Font sizes.
  87. */
  88. fontSize_sizes: 'xx-small/1;x-small/2;small/3;medium/4;large/5;x-large/6;xx-large/7',
  89. fontSize_style: {
  90. element: 'font',
  91. attributes: { 'size': '#(size)' }
  92. } ,
  93. /*
  94. * Font colors.
  95. */
  96. colorButton_enableMore: true,
  97. colorButton_foreStyle: {
  98. element: 'font',
  99. attributes: { 'color': '#(color)' }
  100. },
  101. colorButton_backStyle: {
  102. element: 'font',
  103. styles: { 'background-color': '#(color)' }
  104. },
  105. /*
  106. * Styles combo.
  107. */
  108. stylesSet: [
  109. { name: 'Computer Code', element: 'code' },
  110. { name: 'Keyboard Phrase', element: 'kbd' },
  111. { name: 'Sample Text', element: 'samp' },
  112. { name: 'Variable', element: 'var' },
  113. { name: 'Deleted Text', element: 'del' },
  114. { name: 'Inserted Text', element: 'ins' },
  115. { name: 'Cited Work', element: 'cite' },
  116. { name: 'Inline Quotation', element: 'q' }
  117. ],
  118. on: { 'instanceReady': configureHtmlOutput }
  119. });
  120. /*
  121. * Adjust the behavior of the dataProcessor to avoid styles
  122. * and make it look like FCKeditor HTML output.
  123. */
  124. function configureHtmlOutput( ev ) {
  125. var editor = ev.editor,
  126. dataProcessor = editor.dataProcessor,
  127. htmlFilter = dataProcessor && dataProcessor.htmlFilter;
  128. // Out self closing tags the HTML4 way, like <br>.
  129. dataProcessor.writer.selfClosingEnd = '>';
  130. // Make output formatting behave similar to FCKeditor
  131. var dtd = CKEDITOR.dtd;
  132. for ( var e in CKEDITOR.tools.extend( {}, dtd.$nonBodyContent, dtd.$block, dtd.$listItem, dtd.$tableContent ) ) {
  133. dataProcessor.writer.setRules( e, {
  134. indent: true,
  135. breakBeforeOpen: true,
  136. breakAfterOpen: false,
  137. breakBeforeClose: !dtd[ e ][ '#' ],
  138. breakAfterClose: true
  139. });
  140. }
  141. // Output properties as attributes, not styles.
  142. htmlFilter.addRules( {
  143. elements: {
  144. $: function( element ) {
  145. // Output dimensions of images as width and height
  146. if ( element.name == 'img' ) {
  147. var style = element.attributes.style;
  148. if ( style ) {
  149. // Get the width from the style.
  150. var match = ( /(?:^|\s)width\s*:\s*(\d+)px/i ).exec( style ),
  151. width = match && match[ 1 ];
  152. // Get the height from the style.
  153. match = ( /(?:^|\s)height\s*:\s*(\d+)px/i ).exec( style );
  154. var height = match && match[ 1 ];
  155. if ( width ) {
  156. element.attributes.style = element.attributes.style.replace( /(?:^|\s)width\s*:\s*(\d+)px;?/i , '' );
  157. element.attributes.width = width;
  158. }
  159. if ( height ) {
  160. element.attributes.style = element.attributes.style.replace( /(?:^|\s)height\s*:\s*(\d+)px;?/i , '' );
  161. element.attributes.height = height;
  162. }
  163. }
  164. }
  165. // Output alignment of paragraphs using align
  166. if ( element.name == 'p' ) {
  167. style = element.attributes.style;
  168. if ( style ) {
  169. // Get the align from the style.
  170. match = ( /(?:^|\s)text-align\s*:\s*(\w*);/i ).exec( style );
  171. var align = match && match[ 1 ];
  172. if ( align ) {
  173. element.attributes.style = element.attributes.style.replace( /(?:^|\s)text-align\s*:\s*(\w*);?/i , '' );
  174. element.attributes.align = align;
  175. }
  176. }
  177. }
  178. if ( !element.attributes.style )
  179. delete element.attributes.style;
  180. return element;
  181. }
  182. },
  183. attributes: {
  184. style: function( value, element ) {
  185. // Return #RGB for background and border colors
  186. return CKEDITOR.tools.convertRgbToHex( value );
  187. }
  188. }
  189. });
  190. }
  191. </script>
  192. </p>
  193. <p>
  194. <input type="submit" value="Submit">
  195. </p>
  196. </form>
  197. <div id="footer">
  198. <hr>
  199. <p>
  200. CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a>
  201. </p>
  202. <p id="copy">
  203. Copyright &copy; 2003-2013, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico
  204. Knabben. All rights reserved.
  205. </p>
  206. </div>
  207. </body>
  208. </html>