Download & Extend

Add filter to convert tabs to non-breaking spaces

Project:Textarea Tabs
Version:6.x-0.2
Component:Code
Category:feature request
Priority:normal
Assigned:smokris
Status:closed (fixed)

Issue Summary

I love this module. But, the tabs do not appear. Here is a filter to convert tabs into non-breaking spaces or the characters of your choice. Add this code to the module. Then configure the "input format" settings.

<?php
/**
* Adding a filter to replace tabs with non-breaking spaces.
*/

function textareatabs_filter($op, $delta = 0, $format = -1, $text = '') {
  switch (
$op) {
    case
'list':
      return array(
0 => t('Replace tabs with non-breaking spaces (or characters of your choice).'));
    case
'no cache':
      return
$delta == 1; // No caching for the PHP evaluator.
   
case 'description':
      switch (
$delta) {
        case
0:
          return
t('Replace tabs with non-breaking spaces (or characters of your choice).');
        default:
          return;
      }
    case
'process':
      switch (
$delta) {
        case
0:
          return
textareatabs_process($text, $format);
        default:
          return
$text;
      }
    case
'settings':
      switch (
$delta) {
        case
0:
          return
textareatabs_settings($format);
        default:
          return;
      }
    default:
      return
$text;
  }
}

function
textareatabs_process($text, $format) {

 
$replace = variable_get('filter_url_length_'. $format, '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;');
  return
str_replace("\t", $replace, $text);
}

function
textareatabs_settings($format) {
 
$form['filter_tabs'] = array(
   
'#type' => 'fieldset',
   
'#title' => t('URL filter'),
   
'#collapsible' => TRUE,
  );
 
$form['filter_tabs']['textareatabs_character_'. $format] = array(
   
'#type' => 'textfield',
   
'#title' => t('Replacement string for each tab'),
   
'#default_value' => variable_get('filter_url_length_'. $format, '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'),
   
'#maxlength' => 4,
  );
  return
$form;
}
?>

Comments

#1

Sorry - I pasted in unfinished code. Here is the update.

<?php
function textareatabs_filter($op, $delta = 0, $format = -1, $text = '') {
  switch (
$op) {
    case
'list':
      return array(
0 => t('Replace tabs with non-breaking spaces.'));
    case
'no cache':
      return
$delta == 1; // No caching for the PHP evaluator.
   
case 'description':
      switch (
$delta) {
        case
0:
          return
t('Replace tabs with non-breaking spaces.');
        default:
          return;
      }
    case
'process':
      switch (
$delta) {
        case
0:
          return
textareatabs_process($text, $format);
        default:
          return
$text;
      }
    case
'settings':
      switch (
$delta) {
        case
0:
          return
textareatabs_filter_settings($format);
        default:
          return;
      }
    default:
      return
$text;
  }
}

function
textareatabs_process($text, $format) {

 
$replace = variable_get('textareatabs_character_'. $format, '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;');
  return
str_replace("\t", $replace, $text);
}

function
textareatabs_filter_settings($format) {
 
$form['filter_tabs'] = array(
   
'#type' => 'fieldset',
   
'#title' => t('Replace tabs with characters'),
   
'#collapsible' => TRUE,
  );
 
$form['filter_tabs']['textareatabs_character_'. $format] = array(
   
'#type' => 'textfield',
   
'#title' => t('Replacement string for each tab'),
   
'#default_value' => variable_get('textareatabs_character_'. $format, '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'),
   
'#maxlength' => 4,
  );
  return
$form;
}
?>

#2

Version:5.x-0.1» 6.x-0.2
Assigned to:Anonymous» smokris
Status:active» fixed

Eek. Sorry this sat in the queue for so long.

Thanks. I've committed this to the 6.x branch. It's in the 6.x-0.2 release.

#3

Status:fixed» closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.