From: Dan Brown Date: Sat, 22 Jul 2017 13:21:56 +0000 (+0100) Subject: Added included content into page's text view X-Git-Tag: v0.17.2~1^2~4 X-Git-Url: http://source.bookstackapp.com/bookstack/commitdiff_plain/b12e2ceada9b1b8a382b76c896fc392adcdf5b84 Added included content into page's text view Allows rendered content to be shown in listings and used in searches. Also prevented angular tags in content being parsed in listings. Fixes #442 --- diff --git a/app/Repos/EntityRepo.php b/app/Repos/EntityRepo.php index 7bc5fc4fc..7865de772 100644 --- a/app/Repos/EntityRepo.php +++ b/app/Repos/EntityRepo.php @@ -571,7 +571,7 @@ class EntityRepo $draftPage->slug = $this->findSuitableSlug('page', $draftPage->name, false, $draftPage->book->id); $draftPage->html = $this->formatHtml($input['html']); - $draftPage->text = strip_tags($draftPage->html); + $draftPage->text = $this->pageToPlainText($draftPage->html); $draftPage->draft = false; $draftPage->revision_count = 1; @@ -713,6 +713,17 @@ class EntityRepo return $content; } + /** + * Get the plain text version of a page's content. + * @param Page $page + * @return string + */ + public function pageToPlainText(Page $page) + { + $html = $this->renderPage($page); + return strip_tags($html); + } + /** * Get a new draft page instance. * @param Book $book @@ -816,7 +827,7 @@ class EntityRepo $userId = user()->id; $page->fill($input); $page->html = $this->formatHtml($input['html']); - $page->text = strip_tags($page->html); + $page->text = $this->pageToPlainText($page); if (setting('app-editor') !== 'markdown') $page->markdown = ''; $page->updated_by = $userId; $page->revision_count++; @@ -933,7 +944,7 @@ class EntityRepo $revision = $page->revisions()->where('id', '=', $revisionId)->first(); $page->fill($revision->toArray()); $page->slug = $this->findSuitableSlug('page', $page->name, $page->id, $book->id); - $page->text = strip_tags($page->html); + $page->text = $this->pageToPlainText($page->html); $page->updated_by = user()->id; $page->save(); $this->searchService->indexEntity($page); @@ -953,7 +964,7 @@ class EntityRepo if ($page->draft) { $page->fill($data); if (isset($data['html'])) { - $page->text = strip_tags($data['html']); + $page->text = $this->pageToPlainText($data['html']); } $page->save(); return $page; diff --git a/resources/views/books/show.blade.php b/resources/views/books/show.blade.php index ddbe7a0a4..353018dbc 100644 --- a/resources/views/books/show.blade.php +++ b/resources/views/books/show.blade.php @@ -50,7 +50,7 @@ -
+
@@ -112,7 +112,7 @@ @endif -
+

{{ $chapter->name }}

@@ -116,7 +116,7 @@ @endif