namespace BookStack\Http\Controllers;
+use BookStack\Entities\Managers\BookContents;
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)
{
/**
* Export a book as a PDF file.
- * @param string $bookSlug
- * @return mixed
- * @throws NotFoundException
* @throws Throwable
*/
public function pdf(string $bookSlug)
/**
* Export a book as a contained HTML file.
- * @param string $bookSlug
- * @return mixed
- * @throws NotFoundException
* @throws Throwable
*/
public function html(string $bookSlug)
/**
* Export a book as a plain text file.
- * @param $bookSlug
- * @return mixed
- * @throws NotFoundException
*/
public function plainText(string $bookSlug)
{
$textContent = $this->exportService->bookToPlainText($book);
return $this->downloadResponse($textContent, $bookSlug . '.txt');
}
+
+ /**
+ * Export a book as a markdown file.
+ */
+ public function markdown(string $bookSlug)
+ {
+ $book = $this->bookRepo->getBySlug($bookSlug);
+ $textContent = $this->exportService->bookToMarkdown($book);
+ return $this->downloadResponse($textContent, $bookSlug . '.md');
+ }
+
+ /**
+ * Export a book as a zip file, made of markdown files.
+ */
+ public function zip(string $bookSlug)
+ {
+ $book = $this->bookRepo->getBySlug($bookSlug);
+ $filename = $this->exportService->bookToZip($book);
+ return response()->download($filename);
+ }
}