]> BookStack Code Mirror - bookstack/commitdiff
Aligned export styles a little better and fixed potential DOMPDF css error
authorDan Brown <redacted>
Sat, 15 Feb 2020 15:34:06 +0000 (15:34 +0000)
committerDan Brown <redacted>
Sat, 15 Feb 2020 15:34:06 +0000 (15:34 +0000)
- Removed different PDF template used on pages.
- Updated export view files to have the intended format passed.
- Shared the export CSS amoung the export templates.

Should hopefully address #1886

app/Entities/ExportService.php
resources/sass/export-styles.scss
resources/views/books/export.blade.php
resources/views/chapters/export.blade.php
resources/views/pages/export.blade.php
resources/views/pages/pdf.blade.php [deleted file]
resources/views/partials/export-styles.blade.php [new file with mode: 0644]

index 3ec867959a7d8b1046127e90534bff5050ca73f6..f945dfbe4afe1d17246ca7119c6e776c4acf0455 100644 (file)
@@ -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);
     }
index 958b788075cb50b788685345bfbe9d9b40b111ff..6d9a1a7182afb7aa734175ee4c2bdc898f32a6f7 100644 (file)
@@ -5,7 +5,6 @@
 @import "text";
 @import "layout";
 @import "blocks";
-@import "forms";
 @import "tables";
 @import "header";
 @import "lists";
index 1cf91046df1b5ab2043c5e7072ed265c9a9c5a89..e86a24e816a339e0a443bffef08bbf28b7ab6685 100644 (file)
@@ -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;
         }
index 580c123ccf6d7901491f80e943ff03a264ae3bb6..506e8db3d40f7c18b5c7ca60fefb3ca4fe0c5ff6 100644 (file)
@@ -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>
index 4746a56f37842a5f54dfe13cc1c4a1a4d6586b96..47a4d870a041be8e10d4a11704e5b2bd9a4bb1d2 100644 (file)
@@ -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 (file)
index 33a009f..0000000
+++ /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 (file)
index 0000000..52bfda2
--- /dev/null
@@ -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