Skip to content

Commit c2ccc9c

Browse files
committed
Moved header replacement after the parsing.
1 parent 8ac4b0b commit c2ccc9c

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/DocParser.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44

55
namespace Mistralys\MarkdownViewer;
66

7-
use AppUtils\ConvertHelper;
87
use AppUtils\FileHelper;
9-
use AppUtils\Highlighter;
108
use GeSHi;
119
use ParsedownExtra;
1210

@@ -15,11 +13,17 @@ class DocParser
1513
/**
1614
* @var DocHeader[]
1715
*/
18-
private array $headers = array();
16+
private $headers = array();
1917

20-
private string $html;
18+
/**
19+
* @var string
20+
*/
21+
private $html;
2122

22-
private DocFile $file;
23+
/**
24+
* @var DocFile
25+
*/
26+
private $file;
2327

2428
public function __construct(DocFile $file)
2529
{
@@ -88,24 +92,29 @@ private function parseHeaders() : void
8892
preg_match_all('%<h([0-9])\b[^>]*>(.*?)</h[0-9]>%si', $this->html, $result, PREG_PATTERN_ORDER);
8993

9094
$active = array();
95+
$headers = array();
9196

9297
foreach($result[2] as $idx => $title)
9398
{
9499
$header = new DocHeader($title, intval($result[1][$idx]), $result[0][$idx]);
95100

96101
$level = $header->getLevel();
97102

103+
$headers[] = $header;
98104
$active[$level] = $header;
99105

100-
$this->html = $header->replace($this->html, $this->file);
101-
102106
if($level === 1) {
103107
$this->headers[] = $header;
104108
continue;
105109
}
106110

107111
$active[($level-1)]->addSubheader($header);
108112
}
113+
114+
foreach ($headers as $header)
115+
{
116+
$this->html = $header->replace($this->html, $this->file);
117+
}
109118
}
110119

111120
private function parseCode() : void

0 commit comments

Comments
 (0)