function _collapse_text_process_text_item in Collapse Text 7.2
Same name and namespace in other branches
- 6.2 collapse_text.module \_collapse_text_process_text_item()
process a text item.
1 call to _collapse_text_process_text_item()
- _collapse_text_process_recurse_tree in ./collapse_text.module 
- Take a nested tree and turn it into a string.
File
- ./collapse_text.module, line 469 
- collapse_text is an input filter that allows text to be collapsible
Code
function _collapse_text_process_text_item($item, $options) {
  // remove any leftover [collapse] or [/collapse] tags, such as might be caused by the teaser
  // leaving out the closing tag. Note that a backslash before the collapse tag will act
  // as an escape.
  $item = preg_replace('/(?<!\\\\)\\[\\/?collapse[^\\]]*\\]/', '', $item);
  // remove the first backslash before any collapse tags. This allows collapse tags to be
  // escaped.
  $item = str_replace(array(
    '\\[collapse',
    '\\[/collapse',
  ), array(
    '[collapse',
    '[/collapse',
  ), $item);
  // clear out some miscellaneous tags that are introduced by visual editors...
  $item = preg_replace('/^<\\/p>/', '', $item);
  // close paragraph right at the start
  $item = preg_replace('/<p(?:\\s[^>]*)?>$/', '', $item);
  // open paragraph right at the end
  // clear out cruft introduced by the html line ending filter
  // these are probably more controversial, since they may actually be intended...
  $item = preg_replace('/^<br ?\\/?>/', '', $item);
  // <br> at the very start
  $item = preg_replace('/<br ?\\/?>$/', '', $item);
  // <br> at the very end
  // only return a value if there is something besides whitespace.
  if (preg_match('/\\S/', $item)) {
    return array(
      '#type' => 'markup',
      '#markup' => $item,
      '#prefix' => '<div class="collapse-text-text">',
      '#suffix' => '</div>',
    );
  }
  else {
    return NULL;
  }
}