Support » Plugins » [Plugin: Hackadelic Table Of Contents Boxes] Incorrect (out of order) bullets and fix

  • Resolved archon810



    here’s the fix for the out of order TOC bullets. The problem, to recap, was that on some posts, some of the bullets jumped to the top, in particular in my case it was the h2 tag ones.

    After examining the code the problem turned out to be that there are 2 separate regexes being applied to the post content, one by one. So if one of the regexes matches and then the other one matches as well, the order of matches is not guaranteed. In my case, the h2 tags had additional params, like align=’center’, which was causing the 1st regex to match, while the other tags were matched by the 2nd regex.

    Here’s the patch for v 1.5.1:

    Index: wp-content/plugins/hackadelic-table-of-content-boxes/hackadelic-toc.php
    --- wp-content/plugins/hackadelic-table-of-content-boxes/hackadelic-toc.php	(revision 109810)
    +++ wp-content/plugins/hackadelic-table-of-content-boxes/hackadelic-toc.php	(working copy)
    @@ -157,16 +157,14 @@
     		if ( !is_single() && !is_page() ) return $content;
     		$n = $this->MAX_LEVEL;
    -		$regex1 = '@<h([1-'.$n.'])\s+.*?>(.+?)</h\1>@i';
    -		$regex2 = '@<h([1-'.$n.'])>(.+)</h\1>@i';
    -		$pattern = array($regex1, $regex2);
    +		$regex = '@<h([1-'.$n.'])(?:\s+.*?)?>(.+?)</h\1>@i';
     		$callback = array(&amp;$this, 'doHeader');
     		global $multipage, $numpages, $pages, $page;
     		for ($i = 1; $i <= $numpages; $i++) {
     			if ($i == $page) { $in = $content; $out =&amp; $content; $this->url = ''; }
     			else { $in = $pages[$i-1]; unset($out); $this->url = $this->urlToPageNr($i); }
    -			$out = preg_replace_callback($pattern, $callback, $in);
    +			$out = preg_replace_callback($regex, $callback, $in);
     		return $content;

    The solution is to use a single regex. The 2 regexes were superfluous anyway.


Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘[Plugin: Hackadelic Table Of Contents Boxes] Incorrect (out of order) bullets and fix’ is closed to new replies.