From 86168e77a6e2aa3de006952bcdb646819f41fbf1 Mon Sep 17 00:00:00 2001 From: BigCoke233 Date: Thu, 16 Jul 2020 23:38:54 +0800 Subject: =?UTF-8?q?:zap:=20Add:=20=E5=88=9D=E6=AD=A5=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?=E6=96=87=E7=AB=A0=E7=9B=AE=E5=BD=95=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/Contents.php | 24 +++++++++++++++++++++++- libs/TableContents.php | 0 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 libs/TableContents.php (limited to 'libs') diff --git a/libs/Contents.php b/libs/Contents.php index da7d321..567c3b2 100644 --- a/libs/Contents.php +++ b/libs/Contents.php @@ -30,7 +30,9 @@ class Contents //owo $text = Contents::parseEmo($text); //Links - $text = Contents::parseLink($text); + $text = Contents::parseLink($text); + //toc + $text = preg_replace('/{:toc:}/s',Contents::tableOfContents($text),$text); } return $text; } @@ -230,6 +232,8 @@ class Contents return $text; } + /* == 文章目录 == */ + /** * 解析章节链接 */ @@ -250,6 +254,24 @@ class Contents return ''.$matchs[3].''; } + /** + * 文章目录 + */ + public static function tableOfContents($html) { + $pattern = '/(.*?)<\/h\1>/'; + preg_match_all($pattern, $html, $matches, PREG_SET_ORDER); + $output = ""; + foreach ($matches as $item) { + $output .= ' +
  • + ' . $item[3] . ' +
  • '; + } + return (!empty($output)) ? + "
      " . $output . "
    " : + ""; + } + /* == 其他内容 == */ /** diff --git a/libs/TableContents.php b/libs/TableContents.php new file mode 100644 index 0000000..e69de29 -- cgit v1.2.3