Skip navigation

Recipe for Adding Wiki Format Buttons Using Quicktags

The quicktags module provides a tinymce-button-style solution for formatting wiki posts. Quicktags adds buttons to the textarea and uses on-the-fly generated javascript. It is not a wysiwyg editor, but something far simpler: It simply inserts the basic code into your textarea.

Here is a screenshot of quicktags in action:

You can download quicktags here: http://drupal.org/project/quicktags
Don't forget to enable users who will need this in Access Control

Here is some modified code (from quicktags.module) that creates quicktags buttons for italic, bold, wiki heading 1,2,3 and url. Note: The tag close function - the checkmark icon - is added automatically at the end of the list.

$items = array(
'ed_italic' => array(
'name' => 'Italic',
'prefix' => "\'\'",
'suffix' => "\'\'",
'accesskey' => 'i',
'weight' => 10,
'icon' => $path .'ed_italic.png',
),
'ed_bold' => array(
'name' => 'Bold',
'prefix' => "\'\'\'",
'suffix' => "\'\'\'",
'accesskey' => 'b',
'weight' => 20,
'icon' => $path .'ed_bold.png',
),
'ed_header' => array(
'name' => 'Header Level One',
'prefix' => '==',
'suffix' => '==',
'accesskey' => '1',
'weight' => 30,
'icon' => $path .'button_headline.png',

),
'ed_block' => array(
'name' => 'Header Level Two',
'prefix' =>'===',
'suffix' => '===',
'accesskey' => '2',
'weight' => 40,
'icon' => $path .'button_headline2.png',
),
'ed_blocka' => array(
'name' => 'Header Level Three',
'prefix' =>'=====',
'suffix' => '=====',
'accesskey' => '3',
'weight' => 42,
'icon' => $path .'button_headline3.png',
),
'ed_link' => array(
'name' => 'link',
'prefix' =>'[',
'suffix' => ']',
'accesskey' => 'l',
'weight' => 50,
'icon' => $path .'ed_link.png',
),

The module requires a patch to add functionality to determine which content types the quicktags will appear on: http://drupal.org/node/62100#comment-403430

Once you apply the patch, do the following here: /admin/settings/quicktags
Under 'Show quicktags on specific pages', insert the following code so that the quicktags only appear on wiki pages:

<?php
$match = FALSE;

/* this section controls visibility on EXISTING content */

$types = array('wiki' => 1,);
if (arg(0) == 'node' && is_numeric(arg(1))) {
$nid = arg(1);
$node = node_load(array('nid' => $nid));
$type = $node->type;
if (isset($types[$type])) {
$match = TRUE;
}
}

/* this section controls visibility on NEW content */

if (strpos(request_uri(),"node/add/wiki"))
{ $match = TRUE;}

return $match;
?>

This is important since the buttons you are creating are for wikis formatting only and not for HTML WYSIWYG.

AttachmentSize
quicktags_1.patch (needs to be modified)3.41 KB
quicktags.module.modified.txt (patched - remove modified.txt to use)10.11 KB