]> BookStack Code Mirror - bookstack/blobdiff - app/Http/Controllers/Api/BookExportApiController.php
Reviewed #2393, Removed image guessing and added testing
[bookstack] / app / Http / Controllers / Api / BookExportApiController.php
index a290d89e7fb2d2fe62341775408a4ef3a81eb4e7..24cba9df374a83ba00f1aa9fbefb43594f8d7499 100644 (file)
@@ -2,20 +2,14 @@
 
 use BookStack\Entities\Models\Book;
 use BookStack\Entities\Tools\ExportFormatter;
-use BookStack\Entities\Repos\BookRepo;
 use Throwable;
 
 class BookExportApiController extends ApiController
 {
-    protected $bookRepo;
     protected $exportFormatter;
 
-    /**
-     * BookExportController constructor.
-     */
-    public function __construct(BookRepo $bookRepo, ExportFormatter $exportFormatter)
+    public function __construct(ExportFormatter $exportFormatter)
     {
-        $this->bookRepo = $bookRepo;
         $this->exportFormatter = $exportFormatter;
     }
 
@@ -50,4 +44,14 @@ class BookExportApiController extends ApiController
         $textContent = $this->exportFormatter->bookToPlainText($book);
         return $this->downloadResponse($textContent, $book->slug . '.txt');
     }
+
+    /**
+     * Export a book as a markdown file.
+     */
+    public function exportMarkdown(int $id)
+    {
+        $book = Book::visible()->findOrFail($id);
+        $markdown = $this->exportFormatter->bookToMarkdown($book);
+        return $this->downloadResponse($markdown, $book->slug . '.md');
+    }
 }