diff --git a/app/Entities/ExportService.php b/app/Entities/ExportService.php index 3ec867959..f945dfbe4 100644 --- a/app/Entities/ExportService.php +++ b/app/Entities/ExportService.php @@ -29,8 +29,9 @@ class ExportService public function pageToContainedHtml(Page $page) { $page->html = (new PageContent($page))->render(); - $pageHtml = view('pages/export', [ - 'page' => $page + $pageHtml = view('pages.export', [ + 'page' => $page, + 'format' => 'html', ])->render(); return $this->containHtml($pageHtml); } @@ -45,9 +46,10 @@ class ExportService $pages->each(function ($page) { $page->html = (new PageContent($page))->render(); }); - $html = view('chapters/export', [ + $html = view('chapters.export', [ 'chapter' => $chapter, - 'pages' => $pages + 'pages' => $pages, + 'format' => 'html', ])->render(); return $this->containHtml($html); } @@ -59,9 +61,10 @@ class ExportService public function bookToContainedHtml(Book $book) { $bookTree = (new BookContents($book))->getTree(false, true); - $html = view('books/export', [ + $html = view('books.export', [ 'book' => $book, - 'bookChildren' => $bookTree + 'bookChildren' => $bookTree, + 'format' => 'html', ])->render(); return $this->containHtml($html); } @@ -73,8 +76,9 @@ class ExportService public function pageToPdf(Page $page) { $page->html = (new PageContent($page))->render(); - $html = view('pages/pdf', [ - 'page' => $page + $html = view('pages.export', [ + 'page' => $page, + 'format' => 'pdf', ])->render(); return $this->htmlToPdf($html); } @@ -90,9 +94,10 @@ class ExportService $page->html = (new PageContent($page))->render(); }); - $html = view('chapters/export', [ + $html = view('chapters.export', [ 'chapter' => $chapter, - 'pages' => $pages + 'pages' => $pages, + 'format' => 'pdf', ])->render(); return $this->htmlToPdf($html); @@ -105,9 +110,10 @@ class ExportService public function bookToPdf(Book $book) { $bookTree = (new BookContents($book))->getTree(false, true); - $html = view('books/export', [ + $html = view('books.export', [ 'book' => $book, - 'bookChildren' => $bookTree + 'bookChildren' => $bookTree, + 'format' => 'pdf', ])->render(); return $this->htmlToPdf($html); } diff --git a/resources/sass/export-styles.scss b/resources/sass/export-styles.scss index 958b78807..6d9a1a718 100644 --- a/resources/sass/export-styles.scss +++ b/resources/sass/export-styles.scss @@ -5,7 +5,6 @@ @import "text"; @import "layout"; @import "blocks"; -@import "forms"; @import "tables"; @import "header"; @import "lists"; diff --git a/resources/views/books/export.blade.php b/resources/views/books/export.blade.php index 1cf91046d..e86a24e81 100644 --- a/resources/views/books/export.blade.php +++ b/resources/views/books/export.blade.php @@ -4,10 +4,9 @@ <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>{{ $book->name }}</title> + @include('partials.export-styles', ['format' => $format]) + <style> - @if (!app()->environment('testing')) - {!! file_get_contents(public_path('/dist/export-styles.css')) !!} - @endif .page-break { page-break-after: always; } diff --git a/resources/views/chapters/export.blade.php b/resources/views/chapters/export.blade.php index 580c123cc..506e8db3d 100644 --- a/resources/views/chapters/export.blade.php +++ b/resources/views/chapters/export.blade.php @@ -4,10 +4,9 @@ <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>{{ $chapter->name }}</title> + @include('partials.export-styles', ['format' => $format]) + <style> - @if (!app()->environment('testing')) - {!! file_get_contents(public_path('/dist/export-styles.css')) !!} - @endif .page-break { page-break-after: always; } @@ -20,7 +19,6 @@ } } </style> - @yield('head') @include('partials.custom-head') </head> <body> diff --git a/resources/views/pages/export.blade.php b/resources/views/pages/export.blade.php index 4746a56f3..47a4d870a 100644 --- a/resources/views/pages/export.blade.php +++ b/resources/views/pages/export.blade.php @@ -4,12 +4,31 @@ <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>{{ $page->name }}</title> - <style> - @if (!app()->environment('testing')) - {!! file_get_contents(public_path('/dist/export-styles.css')) !!} - @endif - </style> - @yield('head') + @include('partials.export-styles', ['format' => $format]) + + @if($format === 'pdf') + <style> + body { + font-size: 14px; + line-height: 1.2; + } + + h1, h2, h3, h4, h5, h6 { + line-height: 1.2; + } + + table { + max-width: 800px !important; + font-size: 0.8em; + width: 100% !important; + } + + table td { + width: auto !important; + } + </style> + @endif + @include('partials.custom-head') </head> <body> diff --git a/resources/views/pages/pdf.blade.php b/resources/views/pages/pdf.blade.php deleted file mode 100644 index 33a009fee..000000000 --- a/resources/views/pages/pdf.blade.php +++ /dev/null @@ -1,34 +0,0 @@ -@extends('pages/export') - -@section('head') - <style> - body { - font-size: 14px; - line-height: 1.2; - } - - h1, h2, h3, h4, h5, h6 { - line-height: 1.2; - } - - table { - max-width: 800px !important; - font-size: 0.8em; - width: 100% !important; - } - - table td { - width: auto !important; - } - - .page-content .float { - float: none !important; - } - - .page-content img.align-left, .page-content img.align-right { - float: none !important; - clear: both; - display: block; - } - </style> -@stop \ No newline at end of file diff --git a/resources/views/partials/export-styles.blade.php b/resources/views/partials/export-styles.blade.php new file mode 100644 index 000000000..52bfda2a6 --- /dev/null +++ b/resources/views/partials/export-styles.blade.php @@ -0,0 +1,29 @@ +<style> + @if (!app()->environment('testing')) + {!! file_get_contents(public_path('/dist/export-styles.css')) !!} + @endif +</style> + +@if ($format === 'pdf') + <style> + /* Patches for CSS variable colors */ + a { + color: {{ setting('app-color') }}; + } + + blockquote { + border-left-color: {{ setting('app-color') }}; + } + + /* Patches for content layout */ + .page-content .float { + float: none !important; + } + + .page-content img.align-left, .page-content img.align-right { + float: none !important; + clear: both; + display: block; + } + </style> +@endif \ No newline at end of file