mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-06-01 22:39:13 +08:00
Added markdown export endpoints to API
- Added tests to cover. - Added slight extra spaces at content joins.
This commit is contained in:
@ -44,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');
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
use BookStack\Entities\Models\Chapter;
|
||||
use BookStack\Entities\Tools\ExportFormatter;
|
||||
use BookStack\Entities\Repos\BookRepo;
|
||||
use Throwable;
|
||||
|
||||
class ChapterExportApiController extends ApiController
|
||||
@ -48,4 +47,14 @@ class ChapterExportApiController extends ApiController
|
||||
$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');
|
||||
}
|
||||
}
|
||||
|
@ -44,4 +44,14 @@ class PageExportApiController extends ApiController
|
||||
$textContent = $this->exportFormatter->pageToPlainText($page);
|
||||
return $this->downloadResponse($textContent, $page->slug . '.txt');
|
||||
}
|
||||
|
||||
/**
|
||||
* Export a page as a markdown file.
|
||||
*/
|
||||
public function exportMarkdown(int $id)
|
||||
{
|
||||
$page = Page::visible()->findOrFail($id);
|
||||
$markdown = $this->exportFormatter->pageToMarkdown($page);
|
||||
return $this->downloadResponse($markdown, $page->slug . '.md');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user