From c9dec3b8b13c00808cbec898124c16aa5580dc6d Mon Sep 17 00:00:00 2001 From: "DESKTOP-4RNDQIC\\29019" <290198252@qq.com> Date: Wed, 13 Jan 2021 21:13:27 +0800 Subject: [PATCH] add markdown toc --- App/Controllers/Blog.php | 19 +++++++++++++++---- App/Controllers/NewUi.php | 12 +++++++----- App/Views/blog/article.html | 20 +++++++++++++++++--- App/Views/blog/index.html | 6 ++++++ composer.json | 9 +++++---- 5 files changed, 50 insertions(+), 16 deletions(-) diff --git a/App/Controllers/Blog.php b/App/Controllers/Blog.php index 9e3ef24..8fd420f 100644 --- a/App/Controllers/Blog.php +++ b/App/Controllers/Blog.php @@ -23,8 +23,13 @@ class Blog extends Controller $obj['content'] = $value['content']; $obj['type'] = $value['type']; //数据加工 - $markdown = new Parsedown; - $content = $markdown->text($value['content']); +// $markdown = new Parsedown; +// $content = $markdown->text($value['content']); + + $Parsedown = new \ParsedownToC(); + $content = $Parsedown->body($value['content']); +// $content = $Parsedown->contentsList(); + $obj['content'] = $content; array_push($firstpagedocs,$obj); } @@ -57,8 +62,12 @@ class Blog extends Controller $commentModel = new Models\DocComment(); $doc = $docModel->titleDoc(rawurldecode( $this->querys['title'])); $id = $doc[0]["id"]; - $markdown = new Parsedown; - $content = $markdown->text($doc[0]['content']); +// $markdown = new Parsedown; +// $content = $markdown->text($doc[0]['content']); + $Parsedown = new \ParsedownToC(); + $content = $Parsedown->body($doc[0]['content']); + $toc = $Parsedown->contentsList(); + $typedocs = $docModel->getAllTypeDocs(); $doccoment = $commentModel->DocComments($id); $titles = $docModel->AllTitle(); @@ -71,6 +80,7 @@ class Blog extends Controller 'title'=>rawurldecode($this->querys['title']), 'index'=>false, 'content'=>$content, + 'toc'=>$toc, 'type' => $this->querys['type'], 'debug' => true, 'article'=>true, @@ -87,6 +97,7 @@ class Blog extends Controller 'title'=>rawurldecode($this->querys['title']), 'article'=>true, 'content'=>$content, + 'toc'=>$toc, 'type' => $this->querys['type'], "typedocs" => $typedocs, "comments" => $doccoment, diff --git a/App/Controllers/NewUi.php b/App/Controllers/NewUi.php index 6551f6a..ec7e55e 100644 --- a/App/Controllers/NewUi.php +++ b/App/Controllers/NewUi.php @@ -82,8 +82,9 @@ class NewUi extends Controller $groupstype = $docModel->GetAllGroupType(); $fisrtpage = $docModel->pageDoc(5,0,55); - $markdown = new Parsedown; - $doc[0]['content'] = $markdown->text($doc[0]['content']); + $markdown = new \ParsedownToC(); + $doc[0]['content'] = $markdown->body($doc[0]['content']); + $doc[0]['toc'] = $markdown->contentsList(); $top5 = $docModel->top5Doc(); foreach ($fisrtpage as $key => $value) { @@ -92,7 +93,7 @@ class NewUi extends Controller $obj['content'] = $value['content']; $obj['type'] = $value['type']; //数据加工 - $content = $markdown->text($value['content']); + $content = $markdown->body($value['content']); $obj['content'] = $content; array_push($firstpagedocs,$obj); } @@ -141,8 +142,9 @@ class NewUi extends Controller $commentModel = new Models\DocComment(); $doc = $docModel->titleDoc(rawurldecode($this->querys['title'])); $id = $doc[0]["id"]; - $markdown = new Parsedown; - $doc[0]['content'] = $markdown->text($doc[0]['content']); + $markdown = new \ParsedownToC(); + $doc[0]['content'] = $markdown->body($doc[0]['content']); + $typedocs = $docModel->getAllTypeDocs(); $doccoment = $commentModel->DocComments($id); $titles = $docModel->AllTitle(); diff --git a/App/Views/blog/article.html b/App/Views/blog/article.html index 0730c1d..7957b4c 100644 --- a/App/Views/blog/article.html +++ b/App/Views/blog/article.html @@ -1,5 +1,5 @@ - + {{ title }} @@ -13,6 +13,14 @@ + @@ -148,7 +156,11 @@ +
+ {{ doc.toc| raw }} +
+