X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/eded8abdedf71ce6fca552a310e04d0cbe9c3827..refs/pull/474/head:/app/Services/ExportService.php diff --git a/app/Services/ExportService.php b/app/Services/ExportService.php index 3ac698718..78cef41a4 100644 --- a/app/Services/ExportService.php +++ b/app/Services/ExportService.php @@ -1,6 +1,7 @@ containHtml($pageHtml); } + /** + * Convert a chapter to a self-contained HTML file. + * @param Chapter $chapter + * @return mixed|string + */ + public function chapterToContainedHtml(Chapter $chapter) + { + $pages = $this->entityRepo->getChapterChildren($chapter); + $pages->each(function($page) { + $page->html = $this->entityRepo->renderPage($page); + }); + $html = view('chapters/export', [ + 'chapter' => $chapter, + 'pages' => $pages + ])->render(); + return $this->containHtml($html); + } + /** * Convert a book to a self-contained HTML file. * @param Book $book @@ -62,6 +81,24 @@ class ExportService return $this->htmlToPdf($html); } + /** + * Convert a chapter to a PDF file. + * @param Chapter $chapter + * @return mixed|string + */ + public function chapterToPdf(Chapter $chapter) + { + $pages = $this->entityRepo->getChapterChildren($chapter); + $pages->each(function($page) { + $page->html = $this->entityRepo->renderPage($page); + }); + $html = view('chapters/export', [ + 'chapter' => $chapter, + 'pages' => $pages + ])->render(); + return $this->htmlToPdf($html); + } + /** * Convert a book to a PDF file * @param Book $book @@ -168,6 +205,21 @@ class ExportService return $text; } + /** + * Convert a chapter into a plain text string. + * @param Chapter $chapter + * @return string + */ + public function chapterToPlainText(Chapter $chapter) + { + $text = $chapter->name . "\n\n"; + $text .= $chapter->description . "\n\n"; + foreach ($chapter->pages as $page) { + $text .= $this->pageToPlainText($page); + } + return $text; + } + /** * Convert a book into a plain text string. * @param Book $book @@ -179,11 +231,7 @@ class ExportService $text = $book->name . "\n\n"; foreach ($bookTree as $bookChild) { if ($bookChild->isA('chapter')) { - $text .= $bookChild->name . "\n\n"; - $text .= $bookChild->description . "\n\n"; - foreach ($bookChild->pages as $page) { - $text .= $this->pageToPlainText($page); - } + $text .= $this->chapterToPlainText($bookChild); } else { $text .= $this->pageToPlainText($bookChild); }