diff --git a/phpdotnet/phd/Package/Generic/XHTML.php b/phpdotnet/phd/Package/Generic/XHTML.php index 9040e21b..cc5ff88d 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( + ["\\", "_", "$"], + ["-", "-", ""], + 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..c6daa9e4 --- /dev/null +++ b/tests/package/php/data/property_linking.xml @@ -0,0 +1,34 @@ + + + +
+ 1. Existing property + + Vendor\Namespace::$definitely_exists + + + Vendor\Namespace::$definitelyExists2 + +
+ +
+ 2. Nonexistent properties + + Vendor\Namespace::$this_does_not_exist + + + Vendor\Namespace::$thisDoesNotExist2 + +
+ +
+ 3. Properties with leading and trailing underscores in ID + + 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 new file mode 100644 index 00000000..cfee80da --- /dev/null +++ b/tests/package/php/property_linking.phpt @@ -0,0 +1,89 @@ +--TEST-- +Property linking 001 +--FILE-- +setXml_file($xml_file); + +$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); + +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 +

+

+ Vendor\Namespace::$definitelyExists2 +

+
+ +
+

%d. Nonexistent properties

+

+ Vendor\Namespace::$this_does_not_exist +

+

+ Vendor\Namespace::$thisDoesNotExist2 +

+
+ +
+

%d. Properties with leading and trailing underscores in ID

+

+ Extension\Class::$__leading_and_trailing_undescores__ +

+

+ Extension\Class::$__leadingAndTrailingUndescores2__ +

+
+ +