From c22583751d12afaef4a60bd65ee5cc740ed651f6 Mon Sep 17 00:00:00 2001 From: haszi Date: Mon, 23 Dec 2024 12:01:42 +0100 Subject: [PATCH 1/2] Add property linking --- phpdotnet/phd/Package/Generic/XHTML.php | 27 ++++++++ tests/package/php/data/property_linking.xml | 25 +++++++ tests/package/php/property_linking.phpt | 72 +++++++++++++++++++++ 3 files changed, 124 insertions(+) create mode 100644 tests/package/php/data/property_linking.xml create mode 100644 tests/package/php/property_linking.phpt diff --git a/phpdotnet/phd/Package/Generic/XHTML.php b/phpdotnet/phd/Package/Generic/XHTML.php index 9040e21b..3537187d 100644 --- a/phpdotnet/phd/Package/Generic/XHTML.php +++ b/phpdotnet/phd/Package/Generic/XHTML.php @@ -462,6 +462,9 @@ abstract class Package_Generic_XHTML extends Format_Abstract_XHTML { /* DEFAULT */ false, 'footnote' => 'format_footnote_para_text', ), + 'property' => [ + /* DEFAULT */ 'format_property_text', + ], /* FIXME: This is one crazy stupid workaround for footnotes */ 'constant' => array( /* DEFAULT */ 'format_constant_text', @@ -1843,6 +1846,30 @@ public function format_replaceable($open, $name, $attrs, $props) { } return false; } + + public function format_property_text($value, $tag) { + if (! str_contains($value, '::')) { + return $value; + } + + $tempLinkValue = str_replace( + array("\\", "_", "$"), + array("-", "-", ""), + strtolower(trim($value, "_")) + ); + + list($extensionAndClass, $property) = explode("::", $tempLinkValue); + $normalizedLinkFormat = $extensionAndClass . ".props." . trim($property, "-"); + + $link = $this->createLink($normalizedLinkFormat); + + if ($link === null || $link === "") { + return $value; + } + + return '' . $value . ''; + } + public function admonition_title($title, $lang) { return '' .($this->autogen($title, $lang)). ''; diff --git a/tests/package/php/data/property_linking.xml b/tests/package/php/data/property_linking.xml new file mode 100644 index 00000000..5bc3f92e --- /dev/null +++ b/tests/package/php/data/property_linking.xml @@ -0,0 +1,25 @@ + + + +
+ 1. Existing property + + Vendor\Namespace::$definitely_exists + +
+ +
+ 2. Nonexistent properties + + Vendor\Namespace::$this_does_not_exist + +
+ +
+ 3. Properties with leading and trailing underscores in ID + + Extension\Class::$__leading_and_trailing_undescores__ + +
+ +
diff --git a/tests/package/php/property_linking.phpt b/tests/package/php/property_linking.phpt new file mode 100644 index 00000000..4c3dba0e --- /dev/null +++ b/tests/package/php/property_linking.phpt @@ -0,0 +1,72 @@ +--TEST-- +Property linking 001 +--FILE-- +setXml_file($xml_file); + +$indices = [ + [ + "docbook_id" => "vendor-namespace.props.definitely-exists", + "filename" => "extensionname.page", + ], + [ + "docbook_id" => "extension-class.props.leading-and-trailing-undescores", + "filename" => "extensionname2.page2", + ], +]; + +$format = new TestPHPChunkedXHTML($config, $outputHandler); + +foreach ($indices as $index) { + $format->SQLiteIndex( + null, // $context, + null, // $index, + $index["docbook_id"] ?? "", // $id, + $index["filename"] ?? "", // $filename, + $index["parent_id"] ?? "", // $parent, + $index["sdesc"] ?? "", // $sdesc, + $index["ldesc"] ?? "", // $ldesc, + $index["element"] ?? "", // $element, + $index["previous"] ?? "", // $previous, + $index["next"] ?? "", // $next, + $index["chunk"] ?? 0, // $chunk + ); +} + +$render = new TestRender(new Reader($outputHandler), $config, $format); + +$render->run(); +?> +--EXPECTF-- +Filename: property_linking.html +Content: +
+ +
+

%d. Existing property

+

+ Vendor\Namespace::$definitely_exists +

+
+ +
+

%d. Nonexistent properties

+

+ Vendor\Namespace::$this_does_not_exist +

+
+ +
+

%d. Properties with leading and trailing underscores in ID

+

+ Extension\Class::$__leading_and_trailing_undescores__ +

+
+ +
From d35b5262551aeb0b6dd243be4690e0b3f01dc245 Mon Sep 17 00:00:00 2001 From: haszi Date: Sun, 29 Dec 2024 12:27:27 +0100 Subject: [PATCH 2/2] Address review comments --- phpdotnet/phd/Package/Generic/XHTML.php | 4 ++-- tests/package/php/data/property_linking.xml | 9 +++++++++ tests/package/php/property_linking.phpt | 17 +++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/phpdotnet/phd/Package/Generic/XHTML.php b/phpdotnet/phd/Package/Generic/XHTML.php index 3537187d..cc5ff88d 100644 --- a/phpdotnet/phd/Package/Generic/XHTML.php +++ b/phpdotnet/phd/Package/Generic/XHTML.php @@ -1853,8 +1853,8 @@ public function format_property_text($value, $tag) { } $tempLinkValue = str_replace( - array("\\", "_", "$"), - array("-", "-", ""), + ["\\", "_", "$"], + ["-", "-", ""], strtolower(trim($value, "_")) ); diff --git a/tests/package/php/data/property_linking.xml b/tests/package/php/data/property_linking.xml index 5bc3f92e..c6daa9e4 100644 --- a/tests/package/php/data/property_linking.xml +++ b/tests/package/php/data/property_linking.xml @@ -6,6 +6,9 @@ Vendor\Namespace::$definitely_exists + + Vendor\Namespace::$definitelyExists2 +
@@ -13,6 +16,9 @@ Vendor\Namespace::$this_does_not_exist + + Vendor\Namespace::$thisDoesNotExist2 +
@@ -20,6 +26,9 @@ Extension\Class::$__leading_and_trailing_undescores__ + + Extension\Class::$__leadingAndTrailingUndescores2__ +
diff --git a/tests/package/php/property_linking.phpt b/tests/package/php/property_linking.phpt index 4c3dba0e..cfee80da 100644 --- a/tests/package/php/property_linking.phpt +++ b/tests/package/php/property_linking.phpt @@ -15,10 +15,18 @@ $indices = [ "docbook_id" => "vendor-namespace.props.definitely-exists", "filename" => "extensionname.page", ], + [ + "docbook_id" => "vendor-namespace.props.definitelyexists2", + "filename" => "extensionname.page", + ], [ "docbook_id" => "extension-class.props.leading-and-trailing-undescores", "filename" => "extensionname2.page2", ], + [ + "docbook_id" => "extension-class.props.leadingandtrailingundescores2", + "filename" => "extensionname2.page2", + ], ]; $format = new TestPHPChunkedXHTML($config, $outputHandler); @@ -53,6 +61,9 @@ Content:

Vendor\Namespace::$definitely_exists

+

+ Vendor\Namespace::$definitelyExists2 +

@@ -60,6 +71,9 @@ Content:

Vendor\Namespace::$this_does_not_exist

+

+ Vendor\Namespace::$thisDoesNotExist2 +