codesnippet.html 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <!DOCTYPE html>
  2. <!--
  3. Copyright (c) 2003-2017, 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>Code Snippet &mdash; CKEditor Sample</title>
  10. <script src="../../../ckeditor.js"></script>
  11. <link href="../../../samples/old/sample.css" rel="stylesheet">
  12. <link href="../../../plugins/codesnippet/lib/highlight/styles/monokai_sublime.css" rel="stylesheet">
  13. <meta name="ckeditor-sample-name" content="Code Snippet plugin">
  14. <meta name="ckeditor-sample-group" content="Plugins">
  15. <meta name="ckeditor-sample-description" content="View and modify code using the Code Snippet plugin.">
  16. <meta name="ckeditor-sample-isnew" content="1">
  17. <style>
  18. #editable
  19. {
  20. padding: 10px 20px;
  21. }
  22. </style>
  23. </head>
  24. <body>
  25. <h1 class="samples">
  26. <a href="../../../samples/old/index.html">CKEditor Samples</a> &raquo; Code Snippet Plugin
  27. </h1>
  28. <div class="warning deprecated">
  29. This sample is not maintained anymore. Check out its <a href="http://sdk.ckeditor.com/samples/codesnippet.html">brand new version in CKEditor SDK</a>.
  30. </div>
  31. <div class="description">
  32. <p>
  33. This editor is using the <strong><a href="http://ckeditor.com/addon/codesnippet">Code Snippet</a></strong> plugin which introduces beautiful code snippets.
  34. By default the <code>codesnippet</code> plugin depends on the built-in client-side syntax highlighting
  35. library <a href="http://highlightjs.org">highlight.js</a>.
  36. </p>
  37. <p>
  38. You can adjust the appearance of code snippets using the <code><a href="http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-codeSnippet_theme">codeSnippet_theme</a></code> configuration variable
  39. (see <a href="http://highlightjs.org/static/test.html">available themes</a>).
  40. </p>
  41. <p>
  42. Select theme: <select id="select"></select>
  43. </p>
  44. <p>
  45. The CKEditor instance below was created by using the following configuration settings:
  46. </p>
  47. <pre class="samples" id="sampleConfig">
  48. CKEDITOR.replace( 'editor1', {
  49. <strong>extraPlugins: 'codesnippet',</strong>
  50. codeSnippet_theme: 'monokai_sublime'
  51. } );
  52. </pre>
  53. <p id="ie8-warning">
  54. Please note that this plugin is not compatible with Internet Explorer 8.
  55. </p>
  56. </div>
  57. <textarea id="editor1">
  58. &lt;p&gt;JavaScript code:&lt;/p&gt;
  59. &lt;pre&gt;
  60. &lt;code class="language-javascript"&gt;function isEmpty( object ) {
  61. for ( var i in object ) {
  62. if ( object.hasOwnProperty( i ) )
  63. return false;
  64. }
  65. return true;
  66. }&lt;/code&gt;&lt;/pre&gt;
  67. &lt;p&gt;SQL query:&lt;/p&gt;
  68. &lt;pre&gt;
  69. &lt;code class="language-sql"&gt;SELECT cust.id FROM cust LEFT JOIN loc ON ( cust.loc_id = loc.id ) WHERE cust.type IN ( 1, 2 );&lt;/code&gt;&lt;/pre&gt;
  70. &lt;p&gt;Unknown markup:&lt;/p&gt;
  71. &lt;pre&gt;
  72. &lt;code&gt; ________________
  73. / \
  74. | How about moo? | ^__^
  75. \________________/ (oo)\_______
  76. \ (__)\ )\/\
  77. ||----w |
  78. || ||
  79. &lt;/code&gt;&lt;/pre&gt;
  80. </textarea>
  81. <h2>Inline editor</h2>
  82. <div class="description">
  83. <p>
  84. The following sample shows the <strong>Code Snippet</strong> plugin running inside
  85. an inline CKEditor instance. The CKEditor instance below was created by using the following configuration settings:
  86. </p>
  87. <pre class="samples">
  88. CKEDITOR.inline( 'editable', {
  89. <strong>extraPlugins: 'codesnippet'</strong>
  90. } );
  91. </pre>
  92. <p>
  93. <strong>Note</strong>: The <a href="http://highlightjs.org/static/test.html">highlight.js themes</a>
  94. must be loaded manually to be applied inside an inline editor instance, as the
  95. <code>codeSnippet_theme</code> setting will not work in that case.
  96. You need to include the stylesheet in the <code>&lt;head&gt;</code> section of the page, for example:
  97. </p>
  98. <pre class="samples">
  99. &lt;head&gt;
  100. ...
  101. &lt;link href="path/to/highlight.js/styles/monokai_sublime.css" rel="stylesheet"&gt;
  102. &lt;/head&gt;
  103. </pre>
  104. </div>
  105. <div id="editable" contenteditable="true">
  106. <p>JavaScript code:</p>
  107. <pre><code class="language-javascript">function isEmpty( object ) {
  108. for ( var i in object ) {
  109. if ( object.hasOwnProperty( i ) )
  110. return false;
  111. }
  112. return true;
  113. }</code></pre>
  114. <p>SQL query:</p>
  115. <pre><code class="language-sql">SELECT cust.id, cust.name, loc.city FROM cust LEFT JOIN loc ON ( cust.loc_id = loc.id ) WHERE cust.type IN ( 1, 2 );</code></pre>
  116. <p>Unknown markup:</p>
  117. <pre><code> ________________
  118. / \
  119. | How about moo? | ^__^
  120. \________________/ (oo)\_______
  121. \ (__)\ )\/\
  122. ||----w |
  123. || ||
  124. </code></pre>
  125. </div>
  126. <h2>Server-side Highlighting and Custom Highlighting Engines</h2>
  127. <p>
  128. The <a href="http://ckeditor.com/addon/codesnippetgeshi"><strong>Code Snippet GeSHi</strong></a> plugin is an
  129. extension of the <strong>Code Snippet</strong> plugin which uses a server-side highligter.
  130. </p>
  131. <p>
  132. It also is possible to replace the default highlighter with any library using
  133. the <a href="http://docs.ckeditor.com/#!/api/CKEDITOR.plugins.codesnippet.highlighter">Highlighter API</a>
  134. and the <a href="http://docs.ckeditor.com/#!/api/CKEDITOR.plugins.codesnippet-method-setHighlighter"><code>editor.plugins.codesnippet.setHighlighter()</code></a> method.
  135. </p>
  136. <script>
  137. ( function() {
  138. CKEDITOR.disableAutoInline = true;
  139. var config = {
  140. extraPlugins: 'codesnippet',
  141. toolbar: [
  142. [ 'Source' ], [ 'Undo', 'Redo' ], [ 'Bold', 'Italic', 'Underline' ], [ 'CodeSnippet' ]
  143. ],
  144. codeSnippet_theme: 'monokai_sublime',
  145. height: 400
  146. };
  147. CKEDITOR.replace( 'editor1', config );
  148. CKEDITOR.inline( 'editable', CKEDITOR.tools.extend( {}, config, {
  149. extraPlugins: 'codesnippet'
  150. }, true ) );
  151. initThemeChange();
  152. function initThemeChange() {
  153. var templates = [
  154. 'monokai_sublime', 'default', 'arta', 'ascetic', 'atelier-dune.dark', 'atelier-dune.light', 'atelier-forest.dark', 'atelier-forest.light', 'atelier-heath.dark', 'atelier-heath.light', 'atelier-lakeside.dark', 'atelier-lakeside.light', 'atelier-seaside.dark', 'atelier-seaside.light', 'brown_paper', 'dark', 'docco', 'far', 'foundation', 'github', 'googlecode', 'idea', 'ir_black', 'magula', 'mono-blue', 'monokai', 'obsidian', 'paraiso.dark', 'paraiso.light', 'pojoaque', 'railscasts', 'rainbow', 'school_book', 'solarized_dark', 'solarized_light', 'sunburst', 'tomorrow-night-blue', 'tomorrow-night-bright', 'tomorrow-night-eighties', 'tomorrow-night', 'tomorrow', 'vs', 'xcode', 'zenburn'
  155. ],
  156. pre = CKEDITOR.document.getById( 'sampleConfig' ),
  157. select = CKEDITOR.document.getById( 'select' ),
  158. codeTemplate = 'CKEDITOR.replace( \'editor1\', {\n' +
  159. ' <strong>extraPlugins: \'codesnippet\',</strong>\n' +
  160. ' codeSnippet_theme: \'{tpl}\'\n' +
  161. '} );',
  162. name, option;
  163. while ( ( name = templates.shift() ) ) {
  164. option = CKEDITOR.document.createElement( 'option', {
  165. attributes: {
  166. value: name
  167. }
  168. } );
  169. option.setText( name );
  170. select.append( option );
  171. }
  172. select.$.onchange = function() {
  173. if ( CKEDITOR.instances.editor1 )
  174. CKEDITOR.instances.editor1.destroy();
  175. CKEDITOR.replace( 'editor1', CKEDITOR.tools.extend( {}, config, {
  176. codeSnippet_theme: this.value
  177. }, true ) );
  178. pre.setHtml( codeTemplate.replace( '{tpl}', this.value ) );
  179. };
  180. }
  181. if ( CKEDITOR.env.ie && CKEDITOR.env.version == 8 )
  182. CKEDITOR.document.getById( 'ie8-warning' ).addClass( 'warning' );
  183. }() );
  184. </script>
  185. <div id="footer">
  186. <hr>
  187. <p>
  188. CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a>
  189. </p>
  190. <p id="copy">
  191. Copyright &copy; 2003-2017, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico
  192. Knabben. All rights reserved.
  193. </p>
  194. </div>
  195. </body>
  196. </html>