Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
01d4b86
updated mpdf to 8.2 (requires php 8.0 now)
splitbrain Sep 2, 2025
c5c184f
first start at refactoring
splitbrain Nov 17, 2025
b883aec
add toc handling
splitbrain Nov 17, 2025
1d334a8
handle debug writing
splitbrain Nov 17, 2025
8c4b141
remove a few now unused methods
splitbrain Nov 17, 2025
081fc33
Handle styles
splitbrain Nov 17, 2025
2bef96e
move page collecting into separate classes
splitbrain Nov 20, 2025
ac65d8f
remove some moved methods
splitbrain Nov 20, 2025
6afd336
remove obsolete template event
splitbrain Nov 20, 2025
293d84e
more refactoring
splitbrain Nov 24, 2025
0eefd8f
decouple renderer
splitbrain Nov 25, 2025
ab12f14
removed more obsolete methods from action plugin
splitbrain Nov 25, 2025
f77f381
fixed issues from first real run
splitbrain Nov 26, 2025
decfd8d
extract $INPUT dependencies out of Collector classes
splitbrain Nov 26, 2025
4c3a95e
reimplement ImageProcessor differently
splitbrain Nov 26, 2025
38ca8b2
updated tests for Media resolving
splitbrain Nov 26, 2025
c617724
update general test
splitbrain Nov 26, 2025
8f1c137
removed unneeded custom exception
splitbrain Nov 26, 2025
bbcdb3f
rewrite internal links. implements #526
splitbrain Nov 26, 2025
4526935
address some of the remaining FIXMEs
splitbrain Nov 26, 2025
5eabda9
fix additional blank page at the end
splitbrain Nov 26, 2025
b706c93
fixed remaining sort test
splitbrain Nov 26, 2025
32d393a
have collectors check for page existance
splitbrain Nov 26, 2025
b23d7b8
for exporting single pages do not rely on $ID
splitbrain Nov 26, 2025
9220075
Added tests
splitbrain Nov 26, 2025
5340eaf
rector and codesnifffer fixes
splitbrain Nov 26, 2025
fbe4e9d
remove obsolete book chapter handling in action
splitbrain Nov 26, 2025
7002812
extracted PDF generation and sending out of action
splitbrain Nov 26, 2025
7542e5b
some minor fixes based on PR feedback
splitbrain Nov 27, 2025
01a7083
Use attributes in config class to denote how to initialize them
splitbrain Nov 27, 2025
f200011
make PdfExportService reusable in debug mode
splitbrain Nov 27, 2025
a9e9f33
introduce a first test for rendering - testing numbered headlines
splitbrain Nov 27, 2025
bee95f0
Overhaul chapter/header counting in renderer
splitbrain Nov 27, 2025
b08d547
pass the Config object into the renderer
splitbrain Nov 27, 2025
c124fc5
Some more tests testing rendering functionality
splitbrain Nov 28, 2025
212a1ea
fix config attrbutes and extend tests
splitbrain Nov 28, 2025
837fcad
update MPDF downgrade log/psr
splitbrain Dec 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 38 additions & 10 deletions _test/EndToEndTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace dokuwiki\plugin\dw2pdf\test;

use dokuwiki\plugin\dw2pdf\src\BookCreatorLiveSelectionCollector;
use dokuwiki\plugin\dw2pdf\src\Cache;
use dokuwiki\plugin\dw2pdf\src\Config;
use dokuwiki\plugin\dw2pdf\src\PageCollector;
Expand All @@ -26,28 +27,36 @@ public function setUp(): void


/**
* Create the page, render it through the PdfExportService in debug mode and return the resulting HTML.
* Create the pages, render them through the PdfExportService in debug mode and return the resulting HTML.
*
* @param string $pageId
* @return string
* @throws \Mpdf\MpdfException
* @param string|string[] $pages One or more pages to be included in the export
* @return string Rendered HTML output
*/
protected function getDebugHTML(string $pageId, $conf = []): string
protected function getDebugHTML($pages, $conf = []): string
{
$data = file_get_contents(__DIR__ . '/pages/' . $pageId . '.txt');
saveWikiText($pageId, $data, 'dw2pdf end-to-end test');
$pages = (array)$pages;

foreach ($pages as $page) {
$data = file_get_contents(__DIR__ . '/pages/' . $page . '.txt');
saveWikiText($page, $data, 'dw2pdf end-to-end test');
}

$config = new Config(array_merge(
$conf,
['debug' => 1, 'exportid' => $pageId]
[
'debug' => 1,
'liveselection' => json_encode($pages)
]
));
$collector = new PageCollector($config);
$collector = new BookCreatorLiveSelectionCollector($config);
$cache = new Cache($config, $collector);
$service = new PdfExportService($config, $collector, $cache, 'Contents', 'tester');
return $service->getDebugHtml();
}


/**
* Test that numbered headers are rendered correctly
*/
public function testNumberedHeaders(): void
{
global $conf;
Expand All @@ -68,4 +77,23 @@ public function testNumberedHeaders(): void
$this->assertMatchesRegularExpression('/^\d\.\d\.\d\. Header/', $h->text());
});
}

/**
* Test that numbered headers are rendered correctly across multiple pages
*
* Each new page should increase the top-level header number
*/
public function testNumberedHeadersMultipage(): void
{
global $conf;
$conf['plugin']['dw2pdf']['headernumber'] = 1; // Currently Config values are not passed to the renderer
$html = $this->getDebugHTML(['headers', 'simple'], ['headernumber' => 1]);

$dom = (new Document())->html($html);

$count = 1;
$dom->find('h1')->each(function ($h) use (&$count) {
$this->assertMatchesRegularExpression('/^' . ($count++) . '\. /', $h->text());
});
}
}
3 changes: 3 additions & 0 deletions _test/pages/simple.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
====== A Simple Page ======

This is a simple page with simple text for simple testing.
33 changes: 22 additions & 11 deletions renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,19 @@ class renderer_plugin_dw2pdf extends Doku_Renderer_xhtml
private $lastHeaderLevel = -1;
private $originalHeaderLevel = 0;
private $difference = 0;
private static $header_count = [];
private static $previous_level = 0;
private $header_count = [];
private $previous_level = 0;
private int $chapter = 0;

/**
* The Writer will reinitialize the renderer for each export, but the object will be reused within one export.
*
* @inheritdoc
*/
public function isSingleton()
{
return true;
}

public function document_start()
{
Expand All @@ -33,9 +44,9 @@ public function document_start()
$this->doc .= "<a name=\"{$pid}__\">";
$this->doc .= "</a>";

static $chapter = 0; // FIXME we can probably do without a static here and use a class property
self::$header_count[1] = $chapter;
$chapter++;

$this->header_count[1] = $this->chapter;
$this->chapter++;
}

/**
Expand Down Expand Up @@ -83,17 +94,17 @@ public function header($text, $level, $pos, $returnonly = false)
$header_prefix = '';
if ($isnumberedheadings) {
if ($level > 0) {
if (self::$previous_level > $level) {
for ($i = $level + 1; $i <= self::$previous_level; $i++) {
self::$header_count[$i] = 0;
if ($this->previous_level > $level) {
for ($i = $level + 1; $i <= $this->previous_level; $i++) {
$this->header_count[$i] = 0;
}
}
}
self::$header_count[$level] = (self::$header_count[$level] ?? 0) + 1;
$this->header_count[$level] = ($this->header_count[$level] ?? 0) + 1;

// $header_prefix = "";
for ($i = 1; $i <= $level; $i++) {
$header_prefix .= self::$header_count[$i] . ".";
$header_prefix .= $this->header_count[$i] . ".";
}
}
if($header_prefix !== '') {
Expand All @@ -120,7 +131,7 @@ public function header($text, $level, $pos, $returnonly = false)
$this->doc .= $this->_xmlEntities($text);
$this->doc .= "</a>";
$this->doc .= "</h$level>" . DOKU_LF;
self::$previous_level = $level;
$this->previous_level = $level;
}

/**
Expand Down
4 changes: 4 additions & 0 deletions src/Writer.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public function __construct(DokuPdf $mpdf, Config $config, Template $template, S
$this->template = $template;
$this->styles = $styles;
$this->debug = $config->isDebugEnabled();

// initialize a new renderer instance (singleton instance will be reused in later p_* calls)
$renderer = plugin_load('renderer', 'dw2pdf', true);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this have influence on rendering included page by Include plugin? Or other render specialities?

Copy link
Owner Author

@splitbrain splitbrain Nov 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. This should not be too different from the combination of a reference to the (singleton) action plugin and class static variables that were used before.

// FIXME set configuration on the renderer here
}

/**
Expand Down