Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8962777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:12:32+00:00 2026-06-15T16:12:32+00:00

What I am ultimately trying to do is to implement some simple code highlighter

  • 0

What I am ultimately trying to do is to implement some simple code highlighter (/Syntax Highlighter) since there was nothing available in ckEditor. For this reason I am thinking to add a new button ( or modify one of the existing buttons) by clicking which the selected text changes in the following manner:
1- gets mono-space font to preserve indentations in source code (e.g. “Courier New”)
2- the font color changes to blue

Since I don’t know how to add a new button I was thinking to use one of the existing buttons, say block quote button, to do the job.

added note:
by the way I just noticed that the ckEditor 4 is out too: ckeditor 4
where the plugins are customizable too:ckeditor 4 builder

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T16:12:34+00:00Added an answer on June 15, 2026 at 4:12 pm

    You can consider the following plugin I created from scratch in hurry (this is not a full solution but it shows the right direction):

    (function() {
        'use strict';
    
        CKEDITOR.plugins.add( 'prettify', {
            icons: 'prettify',
            init: function( editor ) {
                editor.on( 'mode', function( event ) {
                    if( editor.mode == 'wysiwyg' )
                        insertResources( editor );
                });
    
                editor.addCommand( 'prettify', {
                    exec: function( editor ) {
                        var selection = editor.getSelection(),
                            startElement = selection.getStartElement();
    
                        if ( startElement.hasClass( 'prettyprint' ) )
                            return;
    
                        var contents = startElement.getText();
    
                        // Naive pre-processing.
                        contents = contents.replace( /\n/g ,'<br>' );
                        contents = contents.replace( /\t/g ,'&nbsp;&nbsp;&nbsp;&nbsp;' );
                        contents = contents.replace( / /g ,'&nbsp;' );
    
                        startElement.setHtml( prettyPrintOne( contents, 'js', 0 ) );
                        startElement.addClass( 'prettyprint' );
                    }
                });
    
                editor.ui.addButton( 'Prettify', {
                    label: 'Prettify',
                    command: 'prettify',
                    toolbar: 'insert'
                });
            }
        });
    
        function insertResources( editor ) {
            var outerHead = CKEDITOR.document.getHead(),
                innerHead = editor.document.getHead(),
                path = CKEDITOR.plugins.getPath( 'prettify' );
    
            outerHead.append( CKEDITOR.document.createElement( 'script', {
                attributes: {
                    type: 'text/javascript',
                    async: 'true',
                    src: path + 'lib/prettify.js'
                }
            }));
    
            innerHead.append( CKEDITOR.document.createElement( 'link', {
                attributes: {
                    rel: 'stylesheet',
                    href: path + 'lib/prettify.css'
                }
            }));
        }
    })();
    

    To run it, extract Google Prettify library into lib directory of prettify plugin. Then try the following HTML and use the button in the toolbar to prettify pre:

    <textarea cols="80" id="editor1" name="editor1" rows="10">
    <pre>function insertResources( editor ) {
        var outerHead = CKEDITOR.document.getHead(),
            innerHead = editor.document.getHead(),
            path = CKEDITOR.plugins.getPath( 'prettify' );
    </pre>
    
    <p>Foo:</p>
    
    <pre>outerHead.append( CKEDITOR.document.createElement( 'script', {
            attributes: {
                type: 'text/javascript',
                async: 'true',
                src: path + 'lib/prettify.js'
            }
        }));</pre>
    
    <p>Bar:</p>
    
    <pre>innerHead.append( CKEDITOR.document.createElement( 'link', {
            attributes: {
                rel: 'stylesheet',
                href: path + 'lib/prettify.css'
            }
        }));
    }</pre>
    </textarea>
    <script>
    
        CKEDITOR.replace( 'editor1', {
            extraPlugins: 'prettify',
            toolbar: [
                [ 'Source', '-', 'NewPage', 'Preview', '-', 'Templates' ],
                [ 'Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo' ],
                [ 'Bold', 'Italic' ],
                '/',
                [ 'Prettify']
            ]
        } );
    
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ultimately I am trying to run some code which depends on the value (or
So what I am trying to do ultimately is read a line, do some
I've been trying to implement this example using C# and Monodroid, but am having
Trying to implement an autocomplete box ultimately. For now im following php academy's lead.
using Visual.Web.Developer.2010.Express; using SQL.Server.Management.Studio.2008.R2; What I'm ultimately trying to do is update a sql
Ultimately I'm trying to write out a range into a text file. When I
I am trying to use FileHelper library for parsing a text file. Ultimately the
edit4: wikified, since this seems to have morphed more into a discussion than a
Looking to see if there is any way to implement the kind of functionality
I am trying to implement TabLayout in an Activity, and I keep on getting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.