]> BookStack Code Mirror - bookstack/commitdiff
ExportFormatter: Add book description and check for empty book and chapter descriptio... 5313/head
authorczemu <redacted>
Sun, 10 Nov 2024 08:39:33 +0000 (09:39 +0100)
committerczemu <redacted>
Sun, 10 Nov 2024 08:39:33 +0000 (09:39 +0100)
app/Entities/Tools/ExportFormatter.php

index beddfe8e6e0f08cb6e0f373a6d46d202a9b6056e..e85992a9d70ef0909b1789b06e4b3d10c58102f3 100644 (file)
@@ -315,7 +315,11 @@ class ExportFormatter
     public function chapterToMarkdown(Chapter $chapter): string
     {
         $text = '# ' . $chapter->name . "\n\n";
     public function chapterToMarkdown(Chapter $chapter): string
     {
         $text = '# ' . $chapter->name . "\n\n";
-        $text .= $chapter->description . "\n\n";
+
+        if (!empty($chapter->description)) {
+            $text .= $chapter->description . "\n\n";
+        }
+
         foreach ($chapter->pages as $page) {
             $text .= $this->pageToMarkdown($page) . "\n\n";
         }
         foreach ($chapter->pages as $page) {
             $text .= $this->pageToMarkdown($page) . "\n\n";
         }
@@ -330,6 +334,11 @@ class ExportFormatter
     {
         $bookTree = (new BookContents($book))->getTree(false, true);
         $text = '# ' . $book->name . "\n\n";
     {
         $bookTree = (new BookContents($book))->getTree(false, true);
         $text = '# ' . $book->name . "\n\n";
+        
+        if (!empty($book->description)) {
+            $text .= $book->description . "\n\n";
+        }
+
         foreach ($bookTree as $bookChild) {
             if ($bookChild instanceof Chapter) {
                 $text .= $this->chapterToMarkdown($bookChild) . "\n\n";
         foreach ($bookTree as $bookChild) {
             if ($bookChild instanceof Chapter) {
                 $text .= $this->chapterToMarkdown($bookChild) . "\n\n";