mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-08-25 03:35:35 +00:00
html diff in revision view
This commit is contained in:
parent
10418323ef
commit
9537e2ae95
@ -12,6 +12,7 @@ use BookStack\Repos\ChapterRepo;
|
|||||||
use BookStack\Repos\PageRepo;
|
use BookStack\Repos\PageRepo;
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
use Views;
|
use Views;
|
||||||
|
use Icap\HtmlDiff\HtmlDiff;
|
||||||
|
|
||||||
class PageController extends Controller
|
class PageController extends Controller
|
||||||
{
|
{
|
||||||
@ -332,9 +333,19 @@ class PageController extends Controller
|
|||||||
$book = $this->bookRepo->getBySlug($bookSlug);
|
$book = $this->bookRepo->getBySlug($bookSlug);
|
||||||
$page = $this->pageRepo->getBySlug($pageSlug, $book->id);
|
$page = $this->pageRepo->getBySlug($pageSlug, $book->id);
|
||||||
$revision = $this->pageRepo->getRevisionById($revisionId);
|
$revision = $this->pageRepo->getRevisionById($revisionId);
|
||||||
|
|
||||||
|
$next = $revision->getNext() ?: $page;
|
||||||
|
$htmlDiff = new HtmlDiff($revision->html, $next->html, true);
|
||||||
|
$diff = $htmlDiff->outputDiff()->toString();
|
||||||
|
|
||||||
$page->fill($revision->toArray());
|
$page->fill($revision->toArray());
|
||||||
$this->setPageTitle('Page Revision For ' . $page->getShortName());
|
$this->setPageTitle('Page Revision For ' . $page->getShortName());
|
||||||
return view('pages/revision', ['page' => $page, 'book' => $book]);
|
|
||||||
|
return view('pages/revision', [
|
||||||
|
'page' => $page,
|
||||||
|
'book' => $book,
|
||||||
|
'diff' => $diff,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -32,4 +32,25 @@ class PageRevision extends Model
|
|||||||
return $this->page->getUrl() . '/revisions/' . $this->id;
|
return $this->page->getUrl() . '/revisions/' . $this->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get previous revision
|
||||||
|
* @return \BookStack\PageRevision
|
||||||
|
*/
|
||||||
|
public function getPrevious()
|
||||||
|
{
|
||||||
|
if ($id = PageRevision::where('id', '<', $this->id)->max('id')) {
|
||||||
|
return PageRevision::find($id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get next revision
|
||||||
|
* @return \BookStack\PageRevision
|
||||||
|
*/
|
||||||
|
public function getNext()
|
||||||
|
{
|
||||||
|
if ($id = PageRevision::where('id', '>', $this->id)->min('id')) {
|
||||||
|
return PageRevision::find($id);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,8 @@
|
|||||||
"barryvdh/laravel-debugbar": "^2.0",
|
"barryvdh/laravel-debugbar": "^2.0",
|
||||||
"league/flysystem-aws-s3-v3": "^1.0",
|
"league/flysystem-aws-s3-v3": "^1.0",
|
||||||
"barryvdh/laravel-dompdf": "0.6.*",
|
"barryvdh/laravel-dompdf": "0.6.*",
|
||||||
"predis/predis": "^1.0"
|
"predis/predis": "^1.0",
|
||||||
|
"icap/html-diff": "^1.1"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"fzaninotto/faker": "~1.4",
|
"fzaninotto/faker": "~1.4",
|
||||||
|
831
composer.lock
generated
831
composer.lock
generated
File diff suppressed because it is too large
Load Diff
12
resources/assets/sass/_pages.scss
Normal file → Executable file
12
resources/assets/sass/_pages.scss
Normal file → Executable file
@ -60,6 +60,18 @@
|
|||||||
word-break: break-word;
|
word-break: break-word;
|
||||||
hyphens: auto;
|
hyphens: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// diffs
|
||||||
|
.diff-html-removed,
|
||||||
|
.diff-html-added {
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
.diff-html-added {
|
||||||
|
background: rgba(45, 255, 0, 0.2);
|
||||||
|
}
|
||||||
|
.diff-html-removed {
|
||||||
|
background: rgba(255, 0, 0, 0.2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Page content pointers
|
// Page content pointers
|
||||||
|
@ -18,5 +18,9 @@
|
|||||||
|
|
||||||
<div style="clear:left;"></div>
|
<div style="clear:left;"></div>
|
||||||
|
|
||||||
|
@if (isset($diff) && $diff)
|
||||||
|
{!! $diff !!}
|
||||||
|
@else
|
||||||
{!! $page->html !!}
|
{!! $page->html !!}
|
||||||
|
@endif
|
||||||
</div>
|
</div>
|
Loading…
Reference in New Issue
Block a user