How to add Code Snippet to Drupal Content - wrong way!

This has been superceded by How to add Code Snippet to Drupal Content - the correct way!

Opted to go with the ckeditor codesnippet libraries.

Install the following modules:

  • wysiwyg (dev version)
  • wysiwyg_codesnippet
  • libraries

At this point do NOT download the ckeditor js library files.

Enable the wysiwyg module.  Go to admin/config/content/wysiwyg.  You will be presented with installation instructions for several libraries.

It is stressed that you MUST download the FULL version of the CKEDITOR library. Drupal 7 wysiwyg module only supports upto version CKEditor 4.6.2.20af917. However, the ckeditor site http://ckeditor.com/download only provides the STANDARD version for version 4.6.2.  This will not contain all the necessary plugins required.

Download the 4.6.2 version and place it into ./sites/all/libraries/ckeditor.

 This leaves us short of a few plugins.  For our purpose here (getting code snippets) the important ones are:

  • codesnippet
  • widget
  • widgetselection
  • lineutils

Download these plugins from http://ckeditor.com/addons/plugins/all and install into ./sites/all/libraries/ckeditor/plugins.

You should now be able to add Wysiwyg profiles.

After doing all this you should then be able to add code snippets like these:

 

PHP

/**
 * Page callback for the 'user/%/magic tab.
 */
function menu_magic_user_tab($wildcard) {
  if (is_numeric($wildcard) && ($account = user_load($wildcard))) {
    return array(
      '#type'   => 'markup',
      '#markup' => t("%username is totally awesome.", array('%username' => $account->name)),
    );
  }
  else {
    return drupal_not_found();
  }
}

 

SQL

SELECT * FROM
( SELECT
    ROW_NUMBER() OVER (ORDER BY sort_key ASC) AS row_number,
    columns
  FROM tablename
) AS foo
WHERE row_number <= 11
    
    var i;
    var fib = []; //Initialize array!
    
    fib[0] = 0;
    fib[1] = 1;
    for(i=2; i<=10; i++)
    {
        // Next fibonacci number = previous + one before previous
        // Translated to JavaScript:
        fib[i] = fib[i-2] + fib[i-1];
        alert(fib[i]);
    }