You are here

function _collapse_text_filter_prepare_regex_callback in Collapse Text 7.2

Same name and namespace in other branches
  1. 6.2 collapse_text.module \_collapse_text_filter_prepare_regex_callback()

callback function for the prepare replacement. attempt to clean up poorly formatted tags

1 string reference to '_collapse_text_filter_prepare_regex_callback'
_collapse_text_filter_prepare in ./collapse_text.module
Implements hook_filter_FILTER_prepare().

File

./collapse_text.module, line 128
collapse_text is an input filter that allows text to be collapsible

Code

function _collapse_text_filter_prepare_regex_callback($matches) {

  // all regexes here are running against an already extracted tag
  $tag = $matches[0];

  // allow the [collapsed] open tag
  $tag = preg_replace('/^                  # start of tag
      \\[                 # open bracket
      (                  # start capture
        collapsed        # the string collapsed
        (?: |\\])         # either a space or a close bracket
      )                  # end capture
    /ix', '[collapse $1', $tag);

  // fix the collapsed element
  $tag = preg_replace('/^\\[collapse collapsed( |\\])/i', '[collapse collapsed="collapsed"$1', $tag);

  // fix the style element. going forward, we prefer "class=".
  $tag = preg_replace('/ style=([^"].*?)(?= collapsed=| title=|\\])/i', ' class="$1"', $tag);
  $tag = preg_replace('/ style="/i', ' class="', $tag);

  // fix the title element
  // not sufficient if title includes double-quotes
  $tag = preg_replace('/ title=([^"].*?)(?= collapsed=| class=|\\])/i', ' title="$1"', $tag);
  return $tag;
}