';
$content = str_replace($h,'',$content);
}else{
! $toc = '
目次';
}
$toc .= apply_filters('Simple_TOC_before_items','',$post).'
';
$toc .= apply_filters('Simple_TOC_before_first_item','',$post);
+
//tag is?
$start = $end = '';
$start = strpos($content, "[---TAG:");
***************
*** 177,201 ****
$tag = str_replace('[---TAG:','',$tag_c);
$tag = str_replace('---]','',$tag);
$content = str_replace($tag_c,'',$content);
!
!
$doc = new DOMDocument();
@$doc->loadHTML(''.$content);
! $headings = $doc->getElementsByTagName($tag);
! foreach ($headings as $heading){
! $h = $heading_slug = $anchor = '';
! $h = $heading->nodeValue;
! $heading_slug = str_replace (" ",'-',$h);
! $heading_slug = apply_filters('Simple_TOC_Heading_Slugs',sanitize_title($heading_slug),$post);
! $anchor = ' ';
! $toc .= '- '.$h.'
';
! $content = str_replace($h, $h.$anchor ,$content);
}
$toc .= apply_filters('Simple_TOC_After_Last_item','',$post);
$toc .= '
';
$content = str_replace("[---ATOC---]", $toc,$content);
return $content;
}
--- 178,286 ----
$tag = str_replace('[---TAG:','',$tag_c);
$tag = str_replace('---]','',$tag);
$content = str_replace($tag_c,'',$content);
+ $tags = preg_split('/,/', $tag);
+
+ $heading_numbering = false;
+ if ( strpos($content, '[---AUTO_SECTION_NUMBER---]') != false )
+ {
+ $heading_numbering = true;
+ $content = str_replace('[---AUTO_SECTION_NUMBER---]', '', $content);
+ }//if
+
! $heading_tags = array('h1' => 0, 'h2' => 1, 'h3' => 2, 'h4' => 3, 'h5' => 4, 'h6' => 5);
!
$doc = new DOMDocument();
@$doc->loadHTML(''.$content);
!
! $hole_headings = array();
! $excludes = array();
! $min_level = 99999;
! foreach($tags as $hoge)
! {
! $headings = $doc->getElementsByTagName($hoge);
! foreach($headings as $heading)
! {
! $hole_headings[$heading->getLineNo()] = $heading;
! $min_level = min($heading_tags[$heading->nodeName], $min_level);
!
! if ( preg_match("/\[---EXCLUDE---\]/u", $heading->nodeValue) )
! {
! $excludes[spl_object_hash($heading)] = true;
! } //if
! }
! }//foreach
!
! ksort($hole_headings);
!
! if ( $heading_numbering )
! {
! $indices = array('h1' => 0, 'h2' => 0, 'h3' => 0, 'h4' => 0, 'h5' => 0, 'h6' => 0);
! $heading_order = array('h1', 'h2', 'h3', 'h4', 'h5', 'h6');
! $exclude_level = -1;
! foreach ($hole_headings as $heading) // numbering
! {
! if ( $exclude_level == -1 )
! {
! if ( array_key_exists(spl_object_hash($heading), $excludes) )
! {
! $exclude_level = $heading_tags[$heading->nodeName];
! continue;
! }
! }//if
! else
! {
! if ( $heading_tags[$heading->nodeName] > $exclude_level )
! {
! continue;
! }
! else
! {
! $exclude_level = -1;
! }
! }//else
!
!
! ++$indices[$heading->nodeName];
! foreach($heading_order as $h)
! {
! if ( $heading_tags[$h] > $heading_tags[$heading->nodeName] )
! $indices[$h] = 0;
! }//foreach
!
! $label = '';
! foreach($heading_order as $h)
! {
! if ( $indices[$h] != 0 )
! $label .= $indices[$h] . '.';
! }//foreach
!
! $content = str_replace('<'.$heading->nodeName.'>'.$heading->nodeValue,
! '<'.$heading->nodeName.'>'.$label.' '.$heading->nodeValue,$content);
! $heading->nodeValue = $label . ' ' . $heading->nodeValue;
! }//foreach
!
! }//if ( $heading_numbering )
!
! foreach ($hole_headings as $heading){
! $additonal_style = '';
! if ( array_key_exists($heading->nodeName, $heading_tags) )
! $additional_style = 'style="margin-left:'.(($heading_tags[$heading->nodeName]-$min_level)*1.5).'em"';
!
! $h = $heading_slug = $anchor = '';
! $h = $heading->nodeValue;
! $heading_slug = str_replace (" ",'-',$h);
! $heading_slug = apply_filters('Simple_TOC_Heading_Slugs',sanitize_title($heading_slug),$post);
! $anchor = '
';
! $toc .= '
'.$h.'';
! $content = str_replace($h, $h.$anchor ,$content);
}
+
$toc .= apply_filters('Simple_TOC_After_Last_item','',$post);
$toc .= '