mirror of
https://github.com/php/phd.git
synced 2026-03-23 22:52:05 +01:00
Make <preface> not produce a new page by default (#242)
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.
This commit is contained in:
@@ -330,7 +330,7 @@ class Index extends Format
|
||||
} 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)) {
|
||||
|
||||
@@ -935,7 +935,7 @@ abstract class Package_PHP_XHTML extends Package_Generic_XHTML {
|
||||
|
||||
|
||||
/*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 @@ abstract class Package_PHP_XHTML extends Package_Generic_XHTML {
|
||||
/** 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 @@ abstract class Package_PHP_XHTML extends Package_Generic_XHTML {
|
||||
|
||||
$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 @@ abstract class Package_PHP_XHTML extends Package_Generic_XHTML {
|
||||
}
|
||||
|
||||
$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 @@ abstract class Package_PHP_XHTML extends Package_Generic_XHTML {
|
||||
}
|
||||
return '<div id="'.$id.'" class="'.$name.'">';
|
||||
}
|
||||
if ($this->isChunkedByAttributes($attrs)) {
|
||||
if ($this->isChunkedByAttributes($attrs, $name)) {
|
||||
$this->notify(Render::CHUNK, Render::CLOSE);
|
||||
}
|
||||
return '</div>';
|
||||
|
||||
30
tests/index/data/preface_no_chunk.xml
Normal file
30
tests/index/data/preface_no_chunk.xml
Normal file
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<set xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" version="5.0" xml:id="index" xml:lang="en">
|
||||
<title>Test Manual</title>
|
||||
|
||||
<book xml:id="test-book">
|
||||
<title>Test Book</title>
|
||||
|
||||
<preface xml:id="preface-default">
|
||||
<info><title>Default Preface</title></info>
|
||||
<para>This preface should not be chunked by default.</para>
|
||||
</preface>
|
||||
|
||||
<preface annotations="chunk:true" xml:id="preface-chunked">
|
||||
<info><title>Chunked Preface</title></info>
|
||||
<para>This preface should be chunked because of the annotation.</para>
|
||||
</preface>
|
||||
|
||||
<preface annotations="chunk:false" xml:id="preface-not-chunked">
|
||||
<info><title>Not Chunked Preface</title></info>
|
||||
<para>This preface should not be chunked because of the annotation.</para>
|
||||
</preface>
|
||||
|
||||
<chapter xml:id="test-chapter">
|
||||
<info><title>Test Chapter</title></info>
|
||||
<para>A regular chapter for comparison.</para>
|
||||
</chapter>
|
||||
</book>
|
||||
|
||||
</set>
|
||||
50
tests/index/preface_no_chunk.phpt
Normal file
50
tests/index/preface_no_chunk.phpt
Normal file
@@ -0,0 +1,50 @@
|
||||
--TEST--
|
||||
Preface is not chunked by default
|
||||
--FILE--
|
||||
<?php
|
||||
namespace phpdotnet\phd;
|
||||
|
||||
require_once __DIR__ . "/../setup.php";
|
||||
|
||||
$xmlFile = __DIR__ . "/data/preface_no_chunk.xml";
|
||||
|
||||
$config->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)
|
||||
Reference in New Issue
Block a user