|
|
|
@ -516,4 +516,25 @@ Class DirScanner {
@@ -516,4 +516,25 @@ Class DirScanner {
|
|
|
|
|
return $menus; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//获取.md文件中的h1-h6标题 |
|
|
|
|
public function getMDTitles($id) { |
|
|
|
|
$file = $this->scanResults[$id]; |
|
|
|
|
if (empty($file)) {return [];} |
|
|
|
|
|
|
|
|
|
$titles = []; |
|
|
|
|
$content = file_get_contents($file['realpath']); |
|
|
|
|
preg_match_all('/#(.+)/u', $content, $matches); |
|
|
|
|
if (!empty($matches[1])) { |
|
|
|
|
foreach($matches[1] as $title) { |
|
|
|
|
$num = substr_count($title, '#'); |
|
|
|
|
$titles[] = [ |
|
|
|
|
'name' => trim(str_replace('#', '', $title)), |
|
|
|
|
'heading' => 'h' . ($num+1), |
|
|
|
|
]; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $titles; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|