use BookStack\Entities\Models\Chapter;
use BookStack\Entities\Tools\ExportFormatter;
-use BookStack\Entities\Repos\BookRepo;
use Throwable;
class ChapterExportApiController extends ApiController
{
- protected $chapterRepo;
protected $exportFormatter;
/**
* ChapterExportController constructor.
*/
- public function __construct(BookRepo $chapterRepo, ExportFormatter $exportFormatter)
+ public function __construct(ExportFormatter $exportFormatter)
{
- $this->chapterRepo = $chapterRepo;
$this->exportFormatter = $exportFormatter;
}
$textContent = $this->exportFormatter->chapterToPlainText($chapter);
return $this->downloadResponse($textContent, $chapter->slug . '.txt');
}
+
+ /**
+ * Export a chapter as a markdown file.
+ */
+ public function exportMarkdown(int $id)
+ {
+ $chapter = Chapter::visible()->findOrFail($id);
+ $markdown = $this->exportFormatter->chapterToMarkdown($chapter);
+ return $this->downloadResponse($markdown, $chapter->slug . '.md');
+ }
}