diff --git a/phpdotnet/phd/Index.php b/phpdotnet/phd/Index.php index 2f0d5d3e..9ecbe050 100644 --- a/phpdotnet/phd/Index.php +++ b/phpdotnet/phd/Index.php @@ -103,6 +103,7 @@ class Index extends Format private $commit = array(); private $POST_REPLACEMENT_INDEXES = array(); private $POST_REPLACEMENT_VALUES = array(); + private int $exampleCounter = 0; public function __construct(IndexRepository $indexRepository) { $this->indexRepository = $indexRepository; @@ -377,16 +378,14 @@ public function format_short_desc($open, $name, $attrs, $props) { } public function format_example($open, $name, $attrs, $props) { - static $n = 0; - if ($open) { - ++$n; + ++$this->exampleCounter; if(isset($attrs[Reader::XMLNS_XML]["id"])) { $id = $attrs[Reader::XMLNS_XML]["id"]; } else { - $id = "example-" . $n; + $id = "example-" . $this->exampleCounter; } $this->storeInfo($name, $id, $this->currentchunk, false); diff --git a/phpdotnet/phd/Package/Generic/XHTML.php b/phpdotnet/phd/Package/Generic/XHTML.php index 7e6e837a..b16558c6 100644 --- a/phpdotnet/phd/Package/Generic/XHTML.php +++ b/phpdotnet/phd/Package/Generic/XHTML.php @@ -528,6 +528,8 @@ abstract class Package_Generic_XHTML extends Format_Abstract_XHTML { protected $isSectionChunk = array(); protected $params = array(); + protected int $exampleCounter = 0; + public function __construct() { parent::__construct(); $this->registerPIHandlers($this->pihandlers); @@ -1735,13 +1737,12 @@ public function format_note_title($open, $name, $attrs) return '
'; } public function format_example($open, $name, $attrs, $props) { - static $n = 0; if ($open) { - ++$n; + ++$this->exampleCounter; if (isset($props["id"])) { return '
'; } - return '
'; + return '
'; } return '
'; } diff --git a/phpdotnet/phd/TestRender.php b/phpdotnet/phd/TestRender.php index 047dfeec..6b896dfa 100644 --- a/phpdotnet/phd/TestRender.php +++ b/phpdotnet/phd/TestRender.php @@ -22,6 +22,9 @@ public function run() { if ($this->format !== null) { $this->attach($this->format); + } + + if (count($this) > 0) { $this->reader->open($this->config->xml_file()); $this->execute($this->reader); } diff --git a/tests/bug_doc-en_GH-3428.phpt b/tests/bug_doc-en_GH-3428.phpt new file mode 100644 index 00000000..1b6d48d3 --- /dev/null +++ b/tests/bug_doc-en_GH-3428.phpt @@ -0,0 +1,159 @@ +--TEST-- +Example numbering 001 - indexing and rendering examples with and without an xml:id +--FILE-- + true, + "xml_file" => $xml_file, +]); + +$indexRepository = new IndexRepository(new \SQLite3(":memory:")); +$indexRepository->init(); +Config::set_indexcache($indexRepository); + +$index = new TestIndex($indexRepository); + +$render = new TestRender(new Reader, new Config, null, $index); + +$render->run(); + +$indexes = array_keys($index->getNfo()); + +echo "Indexes stored:\n"; + +var_dump($indexes); + +$render = new TestRender(new Reader, new Config); + +$format1 = new TestGenericChunkedXHTML; +$format2 = new TestGenericChunkedXHTML; +$format3 = new TestGenericChunkedXHTML; + +$render->attach($format1); +$render->attach($format2); +$render->attach($format3); + +$render->run(); + +?> +--EXPECT-- +Indexes stored: +array(6) { + [0]=> + string(17) "example-numbering" + [1]=> + string(9) "example-1" + [2]=> + string(9) "example-2" + [3]=> + string(16) "third-example-id" + [4]=> + string(9) "example-4" + [5]=> + string(9) "example-5" +} +Filename: example-numbering.html +Content: +
+
+
+

Example #1 - 1. example without an xml:id

+
+
+ +
+
+

Example #2 - 2. example without an xml:id

+
+
+ +
+
+

Example #3 - 3. example with an xml:id

+
+
+ +
+
+

Example #4 - 4. example without an xml:id

+
+
+ +
+
+

Example #5 - 5. example without an xml:id

+
+
+
+Filename: example-numbering.html +Content: +
+
+
+

Example #1 - 1. example without an xml:id

+
+
+ +
+
+

Example #2 - 2. example without an xml:id

+
+
+ +
+
+

Example #3 - 3. example with an xml:id

+
+
+ +
+
+

Example #4 - 4. example without an xml:id

+
+
+ +
+
+

Example #5 - 5. example without an xml:id

+
+
+
+Filename: example-numbering.html +Content: +
+
+
+

Example #1 - 1. example without an xml:id

+
+
+ +
+
+

Example #2 - 2. example without an xml:id

+
+
+ +
+
+

Example #3 - 3. example with an xml:id

+
+
+ +
+
+

Example #4 - 4. example without an xml:id

+
+
+ +
+
+

Example #5 - 5. example without an xml:id

+
+
+
diff --git a/tests/data/bug_doc-en_GH-3428.xml b/tests/data/bug_doc-en_GH-3428.xml new file mode 100644 index 00000000..8ca07538 --- /dev/null +++ b/tests/data/bug_doc-en_GH-3428.xml @@ -0,0 +1,31 @@ + +
+ + - 1. example without an xml:id + +
+ +
+ + - 2. example without an xml:id + +
+ +
+ + - 3. example with an xml:id + +
+ +
+ + - 4. example without an xml:id + +
+ +
+ + - 5. example without an xml:id + +
+