function _tableofcontents_headers in Table of Contents 7.2
Same name and namespace in other branches
- 6.3 tableofcontents.pages.inc \_tableofcontents_headers()
- 7 tableofcontents.pages.inc \_tableofcontents_headers()
This function goes through all the headers found in the text.
@todo The pattern used assumes that you have at most ONE header per line AND that the whole header is defined on ONE line.
Parameters
$toc The table of content object:
$format The format being worked on:
$text The text to be parsed:
Return value
The text with headers transformed to include an identifier
2 calls to _tableofcontents_headers()
- tableofcontents_field_attach_view_alter in ./
tableofcontents.module - Implementation of hook_field_attach_view_alter(&$output, $context)
- _tableofcontents_process_text in ./
tableofcontents.module - Developer function to apply TOC to any text $body has two assumptions for this function to work 1. It must have [toc] located somewhere in the text 2. It has already been processed by an input filter with toc enabled
File
- ./
tableofcontents.inc, line 19 - Table of Contents - Versatile system for generating Tables of Contents for fields - processing.
Code
function _tableofcontents_headers($text) {
$toc =& tableofcontents_toc();
$toc['back_to_top']['link'] = theme('tableofcontents_back_to_top', array(
'toc' => $toc,
));
// note that the pattern below assumes that the headers
// are properly defined in your HTML (i.e. a header cannot
// include another)
//
// Note: we support having a [collapse] tag just before a header
// and even possibly a [/collapse] just before that!
$result = preg_replace_callback('%((?:(?:<p(?:\\s[^>]*)?' . '>\\s*)?\\[/collapse\\](?:</p\\s*>\\s*)?)?' . '(?:<p(?:\\s[^>]*)?' . '>\\s*)?\\[collapse[^]]*?\\](?:</p\\s*>\\s*)?)?' . '<h([1-6])(\\s+[^>]*?)?' . '>(.*?)</h[1-6]\\s*>%si', '_tableofcontents_replace_headers', $text);
return $result;
}