diff --git a/Extension.php b/Extension.php index ed80508..f0a6a78 100644 --- a/Extension.php +++ b/Extension.php @@ -50,11 +50,23 @@ protected function setContentsList($Content) $text = $this->fetchText($Content['text']); $link = "[${text}](#${id})"; $level = (integer) trim($Content['level'],'h'); + + if ($this->firstHeadLevel === 0) { + $this->firstHeadLevel = $level; + } + $cutIndent = $this->firstHeadLevel - 1; + if ($cutIndent > $level) { + $level = 1; + } else { + $level = $level - $cutIndent; + } + $indent = str_repeat(' ', $level); $this->contentsListString .= "${indent}- ${link}\n"; } protected $contentsListString = ''; + protected $firstHeadLevel = 0; # # Header