From db71f82b8dafb328c9d09aaf7a2cbf17ecd76855 Mon Sep 17 00:00:00 2001 From: lacatoire Date: Mon, 16 Feb 2026 09:36:27 +0100 Subject: [PATCH] Make not produce a new page by default Preface elements are now rendered inline in the parent page instead of being chunked into separate pages. Explicit annotations like chunk:true or phd:chunk="true" can still force chunking. --- phpdotnet/phd/Index.php | 2 +- phpdotnet/phd/Package/PHP/XHTML.php | 12 +++---- tests/index/data/preface_no_chunk.xml | 30 ++++++++++++++++ tests/index/preface_no_chunk.phpt | 50 +++++++++++++++++++++++++++ 4 files changed, 87 insertions(+), 7 deletions(-) create mode 100644 tests/index/data/preface_no_chunk.xml create mode 100644 tests/index/preface_no_chunk.phpt diff --git a/phpdotnet/phd/Index.php b/phpdotnet/phd/Index.php index e377ed09..8b3a6d36 100644 --- a/phpdotnet/phd/Index.php +++ b/phpdotnet/phd/Index.php @@ -330,7 +330,7 @@ public function format_chunk($open, $name, $attrs, $props) { } elseif (isset($attrs[Reader::XMLNS_DOCBOOK]['annotations'])) { $this->isChunk[] = !str_contains($attrs[Reader::XMLNS_DOCBOOK]['annotations'], 'chunk:false'); } else { - $this->isChunk[] = true; + $this->isChunk[] = ($name !== 'preface'); } if (end($this->isChunk)) { diff --git a/phpdotnet/phd/Package/PHP/XHTML.php b/phpdotnet/phd/Package/PHP/XHTML.php index 878afb83..fce9f6f7 100644 --- a/phpdotnet/phd/Package/PHP/XHTML.php +++ b/phpdotnet/phd/Package/PHP/XHTML.php @@ -935,7 +935,7 @@ public function format_enumidentifier_text($value, $tag) { /*Chunk Functions*/ - private function isChunkedByAttributes(array $attributes): bool { + private function isChunkedByAttributes(array $attributes, string $name = ''): bool { /* Legacy way to mark chunks */ if (isset($attributes[Reader::XMLNS_PHD]['chunk'])) { return $attributes[Reader::XMLNS_PHD]['chunk'] != 'false'; @@ -943,8 +943,8 @@ private function isChunkedByAttributes(array $attributes): bool { /** Annotations attribute is a standard DocBook attribute and could be used for various things */ return !str_contains($attributes[Reader::XMLNS_DOCBOOK]['annotations'], 'chunk:false'); } else { - /* Chunked by default */ - return true; + /* Chunked by default, except preface */ + return $name !== 'preface'; } } @@ -953,7 +953,7 @@ public function format_container_chunk($open, $name, $attrs, $props) { $this->CURRENT_CHUNK = $this->CURRENT_ID = $id = $attrs[Reader::XMLNS_XML]["id"] ?? ''; - if ($this->isChunkedByAttributes($attrs)) { + if ($this->isChunkedByAttributes($attrs, $name)) { $this->cchunk = $this->dchunk; } @@ -1063,7 +1063,7 @@ public function format_chunk($open, $name, $attrs, $props) { } $this->CURRENT_CHUNK = $this->CURRENT_ID = $id; - if ($this->isChunkedByAttributes($attrs)) { + if ($this->isChunkedByAttributes($attrs, $name)) { $this->cchunk = $this->dchunk; $this->notify(Render::CHUNK, Render::OPEN); } @@ -1078,7 +1078,7 @@ public function format_chunk($open, $name, $attrs, $props) { } return '
'; } - if ($this->isChunkedByAttributes($attrs)) { + if ($this->isChunkedByAttributes($attrs, $name)) { $this->notify(Render::CHUNK, Render::CLOSE); } return '
'; diff --git a/tests/index/data/preface_no_chunk.xml b/tests/index/data/preface_no_chunk.xml new file mode 100644 index 00000000..0d6bfc9f --- /dev/null +++ b/tests/index/data/preface_no_chunk.xml @@ -0,0 +1,30 @@ + + + + Test Manual + + + Test Book + + + Default Preface + This preface should not be chunked by default. + + + + Chunked Preface + This preface should be chunked because of the annotation. + + + + Not Chunked Preface + This preface should not be chunked because of the annotation. + + + + Test Chapter + A regular chapter for comparison. + + + + diff --git a/tests/index/preface_no_chunk.phpt b/tests/index/preface_no_chunk.phpt new file mode 100644 index 00000000..79f7a626 --- /dev/null +++ b/tests/index/preface_no_chunk.phpt @@ -0,0 +1,50 @@ +--TEST-- +Preface is not chunked by default +--FILE-- +forceIndex = true; +$config->xmlFile = $xmlFile; + +$indexRepository = new IndexRepository(new \SQLite3(":memory:")); +$indexRepository->init(); + +$index = new TestIndex($indexRepository, $config, $outputHandler); +$render = new TestRender(new Reader($outputHandler), $config, null, $index); + +$render->run(); + +$nfo = $index->getNfo(); + +echo "All IDs stored:\n"; +var_dump(isset($nfo["preface-default"])); +var_dump(isset($nfo["preface-chunked"])); +var_dump(isset($nfo["preface-not-chunked"])); +var_dump(isset($nfo["test-chapter"])); + +echo "Chunk status:\n"; +echo "preface-default: "; +var_dump($nfo["preface-default"]["chunk"]); +echo "preface-chunked: "; +var_dump($nfo["preface-chunked"]["chunk"]); +echo "preface-not-chunked: "; +var_dump($nfo["preface-not-chunked"]["chunk"]); +echo "test-chapter: "; +var_dump($nfo["test-chapter"]["chunk"]); +?> +--EXPECT-- +All IDs stored: +bool(true) +bool(true) +bool(true) +bool(true) +Chunk status: +preface-default: bool(false) +preface-chunked: bool(true) +preface-not-chunked: bool(false) +test-chapter: bool(true)