国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
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.

238 lines
8.2KB

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