';
231 | $toc .= '';
232 | $last_level = 0;
233 | $count_h2 = 0;
234 | $new = $html->find('h2,h3');
235 |
236 | if (count($new) < 3) return $content;
237 |
238 | foreach ($new as $h) {
239 | $innerTEXT = trim($h->innertext);
240 | $id = str_replace(' ', '_', $innerTEXT);
241 | $level = intval($h->tag[1]);
242 |
243 | if ($level == 2) {
244 | $count_h2++;
245 | $innerTEXT = self::dec2roman($count_h2) . ' ' . $innerTEXT;
246 | }
247 | $h->id = $id; // add id attribute so we can jump to this element
248 |
249 | $h->innertext = $innerTEXT; // add id attribute so we can jump to this element
250 |
251 | if ($level > $last_level)
252 | // add class
253 | $toc .= '
';
254 | else {
255 | $toc .= str_repeat('
', $last_level - $level);
256 | $toc .= '';
257 | }
258 | if ($level >= $last_level) {
259 | $toc .= "
{$innerTEXT}";
260 | } else {
261 | $toc .= "{$innerTEXT}";
262 | }
263 |
264 |
265 | $last_level = $level;
266 | }
267 |
268 | $toc .= str_repeat('', $last_level);
269 | $toc .= '