3 Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
4 For licensing, see LICENSE.md or http://ckeditor.com/license
9 <title>Code Snippet — 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">
28 <a href="../../../samples/old/index.html">CKEditor Samples</a> » Code Snippet Plugin
30 <div class="warning deprecated">
31 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>.
34 <div class="description">
36 This editor is using the <strong><a href="http://ckeditor.com/addon/codesnippet">Code Snippet</a></strong> plugin which introduces beautiful code snippets.
37 By default the <code>codesnippet</code> plugin depends on the built-in client-side syntax highlighting
38 library <a href="http://highlightjs.org">highlight.js</a>.
41 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
42 (see <a href="http://highlightjs.org/static/test.html">available themes</a>).
45 Select theme: <select id="select"></select>
48 The CKEditor instance below was created by using the following configuration settings:
51 <pre class="samples" id="sampleConfig">
52 CKEDITOR.replace( 'editor1', {
53 <strong>extraPlugins: 'codesnippet',</strong>
54 codeSnippet_theme: 'monokai_sublime'
59 Please note that this plugin is not compatible with Internet Explorer 8.
63 <textarea id="editor1">
64 <p>JavaScript code:</p>
67 <code class="language-javascript">function isEmpty( object ) {
68 for ( var i in object ) {
69 if ( object.hasOwnProperty( i ) )
73 }</code></pre>
75 <p>SQL query:</p>
78 <code class="language-sql">SELECT cust.id FROM cust LEFT JOIN loc ON ( cust.loc_id = loc.id ) WHERE cust.type IN ( 1, 2 );</code></pre>
80 <p>Unknown markup:</p>
83 <code> ________________
85 | How about moo? | ^__^
86 \________________/ (oo)\_______
90 </code></pre>
93 <h2>Inline editor</h2>
95 <div class="description">
97 The following sample shows the <strong>Code Snippet</strong> plugin running inside
98 an inline CKEditor instance. The CKEditor instance below was created by using the following configuration settings:
101 <pre class="samples">
102 CKEDITOR.inline( 'editable', {
103 <strong>extraPlugins: 'codesnippet'</strong>
108 <strong>Note</strong>: The <a href="http://highlightjs.org/static/test.html">highlight.js themes</a>
109 must be loaded manually to be applied inside an inline editor instance, as the
110 <code>codeSnippet_theme</code> setting will not work in that case.
111 You need to include the stylesheet in the <code><head></code> section of the page, for example:
114 <pre class="samples">
117 <link href="path/to/highlight.js/styles/monokai_sublime.css" rel="stylesheet">
123 <div id="editable" contenteditable="true">
125 <p>JavaScript code:</p>
127 <pre><code class="language-javascript">function isEmpty( object ) {
128 for ( var i in object ) {
129 if ( object.hasOwnProperty( i ) )
137 <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>
139 <p>Unknown markup:</p>
141 <pre><code> ________________
143 | How about moo? | ^__^
144 \________________/ (oo)\_______
151 <h2>Server-side Highlighting and Custom Highlighting Engines</h2>
154 The <a href="http://ckeditor.com/addon/codesnippetgeshi"><strong>Code Snippet GeSHi</strong></a> plugin is an
155 extension of the <strong>Code Snippet</strong> plugin which uses a server-side highligter.
159 It also is possible to replace the default highlighter with any library using
160 the <a href="http://docs.ckeditor.com/#!/api/CKEDITOR.plugins.codesnippet.highlighter">Highlighter API</a>
161 and the <a href="http://docs.ckeditor.com/#!/api/CKEDITOR.plugins.codesnippet-method-setHighlighter"><code>editor.plugins.codesnippet.setHighlighter()</code></a> method.
166 CKEDITOR.disableAutoInline = true;
169 extraPlugins: 'codesnippet',
171 [ 'Source' ], [ 'Undo', 'Redo' ], [ 'Bold', 'Italic', 'Underline' ], [ 'CodeSnippet' ]
173 codeSnippet_theme: 'monokai_sublime',
177 CKEDITOR.replace( 'editor1', config );
179 CKEDITOR.inline( 'editable', CKEDITOR.tools.extend( {}, config, {
180 extraPlugins: 'codesnippet'
185 function initThemeChange() {
187 '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'
189 pre = CKEDITOR.document.getById( 'sampleConfig' ),
190 select = CKEDITOR.document.getById( 'select' ),
191 codeTemplate = 'CKEDITOR.replace( \'editor1\', {\n' +
192 ' <strong>extraPlugins: \'codesnippet\',</strong>\n' +
193 ' codeSnippet_theme: \'{tpl}\'\n' +
197 while ( ( name = templates.shift() ) ) {
198 option = CKEDITOR.document.createElement( 'option', {
204 option.setText( name );
205 select.append( option );
208 select.$.onchange = function() {
209 if ( CKEDITOR.instances.editor1 )
210 CKEDITOR.instances.editor1.destroy();
212 CKEDITOR.replace( 'editor1', CKEDITOR.tools.extend( {}, config, {
213 codeSnippet_theme: this.value
216 pre.setHtml( codeTemplate.replace( '{tpl}', this.value ) );
220 if ( CKEDITOR.env.ie && CKEDITOR.env.version == 8 )
221 CKEDITOR.document.getById( 'ie8-warning' ).addClass( 'warning' );
228 CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a>
231 Copyright © 2003-2016, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico
232 Knabben. All rights reserved.