/** * @return void */ public function afterParse(Texy\Texy $texy, Texy\HtmlElement $DOM, $isSingleLine) { if ($isSingleLine) { return; } if ($this->balancing === self::DYNAMIC) { $top = $this->top; $map = []; $min = 100; foreach ($this->TOC as $item) { $level = $item['level']; if ($item['type'] === 'surrounded') { $min = min($level, $min); $top = $this->top - $min; } elseif ($item['type'] === 'underlined') { $map[$level] = $level; } } asort($map); $map = array_flip(array_values($map)); } foreach ($this->TOC as $key => $item) { if ($this->balancing === self::DYNAMIC) { if ($item['type'] === 'surrounded') { $level = $item['level'] + $top; } elseif ($item['type'] === 'underlined') { $level = $map[$item['level']] + $this->top; } else { $level = $item['level']; } $item['el']->setName('h' . min(6, max(1, $level))); $this->TOC[$key]['level'] = $level; } if ($this->generateID) { if (!empty($item['el']->style['toc']) && is_array($item['el']->style)) { $title = $item['el']->style['toc']; unset($item['el']->style['toc']); } else { $title = trim($item['el']->toText($this->texy)); } $this->TOC[$key]['title'] = $title; if (empty($item['el']->attrs['id'])) { $id = $this->idPrefix . Texy\Helpers::webalize($title); $counter = ''; if (isset($this->usedID[$id . $counter])) { $counter = 2; while (isset($this->usedID[$id . '-' . $counter])) { $counter++; } $id .= '-' . $counter; } $this->usedID[$id] = TRUE; $item['el']->attrs['id'] = $id; } } } // document title if ($this->title === NULL && count($this->TOC)) { $item = reset($this->TOC); $this->title = isset($item['title']) ? $item['title'] : trim($item['el']->toText($this->texy)); } }