mirror of
				https://github.com/BookStackApp/BookStack.git
				synced 2025-11-03 02:13:16 +03:00 
			
		
		
		
	Updated PDF export to open detail blocks
This commit is contained in:
		@@ -147,10 +147,31 @@ class ExportFormatter
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        $html = $this->containHtml($html);
 | 
					        $html = $this->containHtml($html);
 | 
				
			||||||
        $html = $this->replaceIframesWithLinks($html);
 | 
					        $html = $this->replaceIframesWithLinks($html);
 | 
				
			||||||
 | 
					        $html = $this->openDetailElements($html);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return $this->pdfGenerator->fromHtml($html);
 | 
					        return $this->pdfGenerator->fromHtml($html);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Within the given HTML content, Open any detail blocks
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    protected function openDetailElements(string $html): string
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        libxml_use_internal_errors(true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $doc = new DOMDocument();
 | 
				
			||||||
 | 
					        $doc->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'));
 | 
				
			||||||
 | 
					        $xPath = new DOMXPath($doc);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $details = $xPath->query('//details');
 | 
				
			||||||
 | 
					        /** @var DOMElement $detail */
 | 
				
			||||||
 | 
					        foreach ($details as $detail) {
 | 
				
			||||||
 | 
					            $detail->setAttribute('open', 'open');
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return $doc->saveHTML();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Within the given HTML content, replace any iframe elements
 | 
					     * Within the given HTML content, replace any iframe elements
 | 
				
			||||||
     * with anchor links within paragraph blocks.
 | 
					     * with anchor links within paragraph blocks.
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -309,6 +309,24 @@ class ExportTest extends TestCase
 | 
				
			|||||||
        $this->assertStringContainsString('<p><a href="https://www.youtube.com/embed/ShqUjt33uOs">https://www.youtube.com/embed/ShqUjt33uOs</a></p>', $pdfHtml);
 | 
					        $this->assertStringContainsString('<p><a href="https://www.youtube.com/embed/ShqUjt33uOs">https://www.youtube.com/embed/ShqUjt33uOs</a></p>', $pdfHtml);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function test_page_pdf_export_opens_details_blocks()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $page = Page::query()->first()->forceFill([
 | 
				
			||||||
 | 
					            'html'     => '<details><summary>Hello</summary><p>Content!</p></details>',
 | 
				
			||||||
 | 
					        ]);
 | 
				
			||||||
 | 
					        $page->save();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $pdfHtml = '';
 | 
				
			||||||
 | 
					        $mockPdfGenerator = $this->mock(PdfGenerator::class);
 | 
				
			||||||
 | 
					        $mockPdfGenerator->shouldReceive('fromHtml')
 | 
				
			||||||
 | 
					            ->with(\Mockery::capture($pdfHtml))
 | 
				
			||||||
 | 
					            ->andReturn('');
 | 
				
			||||||
 | 
					        $mockPdfGenerator->shouldReceive('getActiveEngine')->andReturn(PdfGenerator::ENGINE_DOMPDF);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $this->asEditor()->get($page->getUrl('/export/pdf'));
 | 
				
			||||||
 | 
					        $this->assertStringContainsString('<details open="open"', $pdfHtml);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function test_page_markdown_export()
 | 
					    public function test_page_markdown_export()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $page = Page::query()->first();
 | 
					        $page = Page::query()->first();
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user