]> BookStack Code Mirror - bookstack/blobdiff - app/Http/Controllers/BookExportController.php
support exporting WYSIWYG pages as Markdown
[bookstack] / app / Http / Controllers / BookExportController.php
index ae3f56b816f5dc4368ec9a4242c6ed03346f2b25..40eec69fe9e90e01b1e5029d0fc8c09b76ec6a16 100644 (file)
@@ -4,25 +4,16 @@ namespace BookStack\Http\Controllers;
 
 use BookStack\Entities\ExportService;
 use BookStack\Entities\Repos\BookRepo;
-use BookStack\Exceptions\NotFoundException;
 use Throwable;
 
 class BookExportController extends Controller
 {
-    /**
-     * @var BookRepo
-     */
-    protected $bookRepo;
 
-    /**
-     * @var ExportService
-     */
+    protected $bookRepo;
     protected $exportService;
 
     /**
      * BookExportController constructor.
-     * @param BookRepo $bookRepo
-     * @param ExportService $exportService
      */
     public function __construct(BookRepo $bookRepo, ExportService $exportService)
     {
@@ -33,9 +24,6 @@ class BookExportController extends Controller
 
     /**
      * Export a book as a PDF file.
-     * @param string $bookSlug
-     * @return mixed
-     * @throws NotFoundException
      * @throws Throwable
      */
     public function pdf(string $bookSlug)
@@ -47,9 +35,6 @@ class BookExportController extends Controller
 
     /**
      * Export a book as a contained HTML file.
-     * @param string $bookSlug
-     * @return mixed
-     * @throws NotFoundException
      * @throws Throwable
      */
     public function html(string $bookSlug)
@@ -61,9 +46,6 @@ class BookExportController extends Controller
 
     /**
      * Export a book as a plain text file.
-     * @param $bookSlug
-     * @return mixed
-     * @throws NotFoundException
      */
     public function plainText(string $bookSlug)
     {
@@ -71,4 +53,15 @@ class BookExportController extends Controller
         $textContent = $this->exportService->bookToPlainText($book);
         return $this->downloadResponse($textContent, $bookSlug . '.txt');
     }
+
+    /**
+     * Export a book as a markdown file.
+     */
+    public function markdown(string $bookSlug)
+    {
+        // TODO: This should probably export to a zip file.
+        $book = $this->bookRepo->getBySlug($bookSlug);
+        $textContent = $this->exportService->bookToMarkdown($book);
+        return $this->downloadResponse($textContent, $bookSlug . '.md');
+    }
 }