Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add property linking #183

Merged
merged 2 commits into from
Dec 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions phpdotnet/phd/Package/Generic/XHTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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 '<a href="' . $link . '">' . $value . '</a>';
}

public function admonition_title($title, $lang)
{
return '<strong class="' .(strtolower($title)). '">' .($this->autogen($title, $lang)). '</strong>';
Expand Down
34 changes: 34 additions & 0 deletions tests/package/php/data/property_linking.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<chapter xml:id="property_linking" xmlns="http://docbook.org/ns/docbook">

<section>
<para>1. Existing property</para>
<para>
<property>Vendor\Namespace::$definitely_exists</property>
</para>
<para>
<property>Vendor\Namespace::$definitelyExists2</property>
</para>
</section>

<section>
<para>2. Nonexistent properties</para>
<para>
<property>Vendor\Namespace::$this_does_not_exist</property>
</para>
<para>
<property>Vendor\Namespace::$thisDoesNotExist2</property>
</para>
</section>

<section>
<para>3. Properties with leading and trailing underscores in ID</para>
<para>
<property>Extension\Class::$__leading_and_trailing_undescores__</property>
haszi marked this conversation as resolved.
Show resolved Hide resolved
</para>
<para>
<property>Extension\Class::$__leadingAndTrailingUndescores2__</property>
</para>
</section>

</chapter>
89 changes: 89 additions & 0 deletions tests/package/php/property_linking.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
--TEST--
Property linking 001
--FILE--
<?php
namespace phpdotnet\phd;

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

$xml_file = __DIR__ . "/data/property_linking.xml";

$config->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:
<div id="property_linking" class="chapter">

<div class="section">
<p class="para">%d. Existing property</p>
<p class="para">
<span class="property"><a href="extensionname.page.html#vendor-namespace.props.definitely-exists">Vendor\Namespace::$definitely_exists</a></span>
</p>
<p class="para">
<span class="property"><a href="extensionname.page.html#vendor-namespace.props.definitelyexists2">Vendor\Namespace::$definitelyExists2</a></span>
</p>
</div>

<div class="section">
<p class="para">%d. Nonexistent properties</p>
<p class="para">
<span class="property">Vendor\Namespace::$this_does_not_exist</span>
</p>
<p class="para">
<span class="property">Vendor\Namespace::$thisDoesNotExist2</span>
</p>
</div>

<div class="section">
<p class="para">%d. Properties with leading and trailing underscores in ID</p>
<p class="para">
<span class="property"><a href="extensionname2.page2.html#extension-class.props.leading-and-trailing-undescores">Extension\Class::$__leading_and_trailing_undescores__</a></span>
</p>
<p class="para">
<span class="property"><a href="extensionname2.page2.html#extension-class.props.leadingandtrailingundescores2">Extension\Class::$__leadingAndTrailingUndescores2__</a></span>
</p>
</div>

</div>
Loading