Skip to content

Commit

Permalink
Fix GH-98 (#105)
Browse files Browse the repository at this point in the history
Store IDs of non-chunked elements.
Closes #98.

---------

Co-authored-by: haszi <[email protected]>
  • Loading branch information
haszi and haszi authored Feb 27, 2024
1 parent b703f50 commit 262926d
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 1 deletion.
5 changes: 4 additions & 1 deletion phpdotnet/phd/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class Index extends Format
private $currentid;
private $chunks = array();
private $isChunk = array();
private $nfo = array();
protected $nfo = array();
private $isSectionChunk = array();
private $log = '';
private $previousId = "";
Expand Down Expand Up @@ -383,6 +383,9 @@ public function format_chunk($open, $name, $attrs, $props) {
$this->chunks[] = $id;
$this->currentchunk = $id;
$this->storeInfo($name, $id, $id);
} else {
$this->storeInfo($name, $id, $this->currentchunk, false);
$this->appendID();
}
return false;
}
Expand Down
8 changes: 8 additions & 0 deletions phpdotnet/phd/TestIndex.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
namespace phpdotnet\phd;

class TestIndex extends Index {
public function getNfo(): array {
return $this->nfo;
}
}
37 changes: 37 additions & 0 deletions tests/index/bug_GH-98.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
--TEST--
Bug GH-98 - Non-chunked section is not linked
--FILE--
<?php
namespace phpdotnet\phd;

require_once __DIR__ . "/../setup.php";

$xml_file = __DIR__ . "/data/bug_GH-98.xml";

Config::init([
"force_index" => true,
"xml_file" => $xml_file,
]);

$index = new TestIndex;
$render = new TestRender(new Reader, new Config, null, $index);

$render->run();

$indexes = array_keys($index->getNfo());

echo "Indexes stored:\n";

var_dump(in_array("non-chunked.element.id", $indexes));
var_dump(in_array("another.non-chunked.element.id", $indexes));
var_dump(in_array("chunked.element.id", $indexes));
var_dump(in_array("another.chunked.element.id", $indexes));
var_dump(in_array("bug-GH-98", $indexes));
?>
--EXPECT--
Indexes stored:
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
28 changes: 28 additions & 0 deletions tests/index/data/bug_GH-98.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<chapter xml:id="bug-GH-98">

<sect1 xmlns="http://docbook.org/ns/docbook" annotations="chunk:false" xml:id="non-chunked.element.id">
<para>
Content to ensure this elements is indexed
</para>
</sect1>

<section xmlns="http://docbook.org/ns/docbook" annotations="chunk:false" xml:id="another.non-chunked.element.id">
<para>
Content to ensure this elements is indexed too
</para>
</section>

<sect1 xmlns="http://docbook.org/ns/docbook" xml:id="chunked.element.id">
<para>
Content to ensure this elements is indexed as well
</para>
</sect1>

<section xmlns="http://docbook.org/ns/docbook" xml:id="another.chunked.element.id">
<para>
Content to ensure this elements is also indexed
</para>
</section>

</chapter>

0 comments on commit 262926d

Please sign in to comment.