You are here

function _tableofcontents_toc_extract in Table of Contents 7.2

Extract a [toc] encoding from the text

3 calls to _tableofcontents_toc_extract()
_tableofcontents_apply_toc in ./tableofcontents.module
_tableofcontents_filter_process in ./tableofcontents.filters.inc
Process the text for the table of content.
_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.module, line 162
This is a filter module to generate a collapsible jquery enabled mediawiki style table of contents based on <h[1-6]> tags. Transforms header tags into named anchors.

Code

function _tableofcontents_toc_extract($text) {
  $matches = array();
  if (!preg_match('%\\[toc ([^\\]]*)\\]%', $text, $matches)) {
    return array();
  }
  $new_toc = array();
  foreach (explode(' ', $matches[1]) as $part) {
    $tmp =& $new_toc;
    while ($part) {
      if (strpos($part, '::') === FALSE) {
        list($k, $v) = explode('=', $part);
        $tmp[$k] = urldecode($v);
        break;
      }
      else {
        list($k, $part) = explode('::', $part, 2);
        if (!isset($tmp[$k])) {
          $tmp[$k] = array();
        }
        $tmp =& $tmp[$k];
      }
    }
  }
  return $new_toc;
}