? collapse_text_opt_title_patch.txt Index: collapse_text.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/collapse_text/collapse_text.module,v retrieving revision 1.4.2.2 diff -u -p -r1.4.2.2 collapse_text.module --- collapse_text.module 15 Dec 2008 15:20:52 -0000 1.4.2.2 +++ collapse_text.module 15 Dec 2008 15:46:08 -0000 @@ -12,7 +12,7 @@ */ function collapse_text_filter_tips($delta, $format, $long = false) { if ($long) { - return t('Enclose sections of text in [collapse] and [/collapse] to turn them into collapsible sections. If you use [collapse collapsed] and [/collapse], the section will start out collapsed. The legend for the section is taken from the first header (<h1>, <h2>, <h3>, ...) found. In the absence of a header, a default title is used.'); + return t('Enclose sections of text in [collapse] and [/collapse] to turn them into collapsible sections. If you use [collapse collapsed] and [/collapse], the section will start out collapsed. You may specify a title with [collapse title=some title] (or [collapse collapsed title=some title]). If no title is specified, the title will be taken from the first header (<h1>, <h2>, <h3>, ...) found. In the absence of a header, a default title is used.'); } else { return t('Make collapsible text blocks using [collapse] and [/collapse].'); @@ -56,22 +56,43 @@ function collapse_text_filter($op, $delt } } +/** + * Provides a layer of encapsulation for the regex call. + */ function collapse_text_process($text) { - $text = preg_replace_callback('/\[collapse( collapsed)?\](.+?)\[\/collapse\]/sm', "_collapse_text_replace_callback", $text); + // Per #259535 and #233877, add ability to specify title + // in collapse text. Thanks rivena, Justyn + $text = preg_replace_callback('/ + \[ # look for an opening bracket + collapse # followed by the word `collapse` + (\ collapsed)? # followed by (optionally) a space and the word `collapsed` (captured) + (?:\ title=([^\]]*))? # followed by (optionally) a space and a title, consisting of any + # characters except a close bracket (captured) + \] # followed by a closing bracket + (.+?) # then capture as few characters as possible until + \[\/collapse\] # a closing "tag", which is a slash followed by `collapse` in brackets + /smx', + "_collapse_text_replace_callback", $text); return $text; } function _collapse_text_replace_callback($matches) { - $collapsed = ($matches[1] == 'collapsed'); - $interior = $matches[2]; + // 2008-12-15 REMorse (no issue number) added space to make + // $collapsed work + $collapsed = ($matches[1] == ' collapsed'); + $title = trim($matches[2]); + $interior = $matches[3]; - // find the first heading tag in the interior text, and use that - // heading for the legend of the fieldset. - $h_matches = array(); - preg_match('/]*>(.+?)<\/h\d>/smi', $interior, $h_matches); - $title = strip_tags($h_matches[1]); + if (empty($title)) { + // If a title is not supplied, look for a header (

,

...) + // and use it as the title. + $h_matches = array(); + preg_match('/]*>(.+?)<\/h\d>/smi', $interior, $h_matches); + $title = strip_tags($h_matches[1]); + } if (empty($title)) { + // If there is still no title, provide some default text. // Added call to t() per #256176 yngens $title = t('Use the arrow to expand or collapse this section'); }