From 7356d971cb609b7493164a782c3be0b165f762d8 Mon Sep 17 00:00:00 2001 From: lacatoire Date: Thu, 12 Feb 2026 17:36:39 +0100 Subject: [PATCH 1/2] Fix GH-152 + GH-213: Admonition id propagation and semantic title Propagate xml:id to the rendered HTML id attribute on admonition elements (warning, caution, tip, important, note) so that anchor links work. Change admonition title from (inline) to
(block) to prevent layout issues with block-level content. --- phpdotnet/phd/Package/Generic/XHTML.php | 15 ++++- phpdotnet/phd/Package/PEAR/XHTML.php | 6 +- .../package/php/admonition_rendering_001.phpt | 59 +++++++++++++++++++ .../package/php/data/admonition_rendering.xml | 39 ++++++++++++ 4 files changed, 115 insertions(+), 4 deletions(-) create mode 100644 tests/package/php/admonition_rendering_001.phpt create mode 100644 tests/package/php/data/admonition_rendering.xml diff --git a/phpdotnet/phd/Package/Generic/XHTML.php b/phpdotnet/phd/Package/Generic/XHTML.php index 52433334..6b15f325 100644 --- a/phpdotnet/phd/Package/Generic/XHTML.php +++ b/phpdotnet/phd/Package/Generic/XHTML.php @@ -1974,11 +1974,15 @@ protected function normalizeFQN(string $fqn): string { public function admonition_title($title, $lang) { - return '' .($this->autogen($title, $lang)). ''; + return '
' .($this->autogen($title, $lang)). '
'; } public function format_admonition($open, $name, $attrs, $props) { if ($open) { - return '
' .$this->admonition_title($name, $props["lang"]); + $idstr = ""; + if (isset($attrs[Reader::XMLNS_XML]["id"])) { + $idstr = ' id="' . $attrs[Reader::XMLNS_XML]["id"] . '"'; + } + return '
' .$this->admonition_title($name, $props["lang"]); } return "
"; } @@ -1999,7 +2003,12 @@ public function format_editor($open, $name, $attrs, $props) { } public function format_note($open, $name, $attrs, $props) { if ($open) { - return '

'.$this->admonition_title("note", $props["lang"]). ': '; + $idstr = ""; + if (isset($attrs[Reader::XMLNS_XML]["id"])) { + $idstr = ' id="' . $attrs[Reader::XMLNS_XML]["id"] . '"'; + } + return '

' + .$this->admonition_title("note", $props["lang"]). ': '; } return "

"; } diff --git a/phpdotnet/phd/Package/PEAR/XHTML.php b/phpdotnet/phd/Package/PEAR/XHTML.php index 36580038..5ca6d94a 100755 --- a/phpdotnet/phd/Package/PEAR/XHTML.php +++ b/phpdotnet/phd/Package/PEAR/XHTML.php @@ -868,7 +868,11 @@ public function format_replaceable($open, $name, $attrs, $props) public function format_warning($open, $name, $attrs, $props) { if ($open) { - return '
' . "\n"; + $idstr = ""; + if (isset($attrs[Reader::XMLNS_XML]["id"])) { + $idstr = ' id="' . $attrs[Reader::XMLNS_XML]["id"] . '"'; + } + return '
' . "\n"; } return "
\n"; } diff --git a/tests/package/php/admonition_rendering_001.phpt b/tests/package/php/admonition_rendering_001.phpt new file mode 100644 index 00000000..2a43c6bc --- /dev/null +++ b/tests/package/php/admonition_rendering_001.phpt @@ -0,0 +1,59 @@ +--TEST-- +Admonition rendering (GH-152 id propagation + GH-213 semantic title) +--FILE-- +xmlFile = $xmlFile; + +$format = new TestPHPChunkedXHTML($config, $outputHandler); + +$render = new TestRender(new Reader($outputHandler), $config, $format); + +$render->run(); +?> +--EXPECT-- +Filename: admonition_rendering.html +Content: +
+ +
+

1. Warning with xml:id

+
Warning
+

This is a warning with an id.

+
+
+ +
+

2. Caution without xml:id

+
Caution
+

This is a caution without an id.

+
+
+ +
+

3. Tip with xml:id

+
Tip
+

This is a tip with an id.

+
+
+ +
+

4. Note with xml:id

+

Note
: +

This is a note with an id.

+

+
+ +
+

5. Important without xml:id

+
Important
+

This is an important without an id.

+
+
+ +
diff --git a/tests/package/php/data/admonition_rendering.xml b/tests/package/php/data/admonition_rendering.xml new file mode 100644 index 00000000..5ccef2f2 --- /dev/null +++ b/tests/package/php/data/admonition_rendering.xml @@ -0,0 +1,39 @@ + + + +
+ 1. Warning with xml:id + + This is a warning with an id. + +
+ +
+ 2. Caution without xml:id + + This is a caution without an id. + +
+ +
+ 3. Tip with xml:id + + This is a tip with an id. + +
+ +
+ 4. Note with xml:id + + This is a note with an id. + +
+ +
+ 5. Important without xml:id + + This is an important without an id. + +
+ +
From 98caf2162565fbe8ba1f491f83de0a2038a5c8d4 Mon Sep 17 00:00:00 2001 From: lacatoire Date: Sun, 15 Feb 2026 22:00:55 +0100 Subject: [PATCH 2/2] Add test case for constructorsynopsis inside a warning admonition --- tests/package/php/admonition_rendering_001.phpt | 10 ++++++++++ tests/package/php/data/admonition_rendering.xml | 12 ++++++++++++ 2 files changed, 22 insertions(+) diff --git a/tests/package/php/admonition_rendering_001.phpt b/tests/package/php/admonition_rendering_001.phpt index 2a43c6bc..a5641048 100644 --- a/tests/package/php/admonition_rendering_001.phpt +++ b/tests/package/php/admonition_rendering_001.phpt @@ -56,4 +56,14 @@ Content:
+
+

6. Warning with constructorsynopsis

+
Warning
+

This constructor is deprecated:

+
public + ClassName::__construct(string $param)
+ +
+
+ diff --git a/tests/package/php/data/admonition_rendering.xml b/tests/package/php/data/admonition_rendering.xml index 5ccef2f2..0b6e1ccf 100644 --- a/tests/package/php/data/admonition_rendering.xml +++ b/tests/package/php/data/admonition_rendering.xml @@ -36,4 +36,16 @@ +
+ 6. Warning with constructorsynopsis + + This constructor is deprecated: + + public + ClassName::__construct + stringparam + + +
+