Skip to content

Commit 5f10df1

Browse files
authored
Fix <function> with <replaceable> not rendering correctly (#235)
When <function> contains <replaceable>, skip link/parentheses processing in format_function_text() and output plain text instead. Uses the role stack pattern already established by format_constant(). Fixes #171
1 parent 61ad3e7 commit 5f10df1

4 files changed

Lines changed: 69 additions & 1 deletion

File tree

phpdotnet/phd/Package/PHP/XHTML.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,12 +827,24 @@ public function format_classsynopsis_methodsynopsis_methodname_text($value, $tag
827827

828828
public function format_function($open, $tag, $attrs, $props) {
829829
if ($open) {
830+
if (str_contains($props["innerXml"], '<replaceable')) {
831+
$this->pushRole("function_replaceable");
832+
}
830833
return '<span class="' . $tag . '">';
831834
}
835+
836+
if ($this->getRole() === "function_replaceable") {
837+
$this->popRole();
838+
}
839+
832840
return "</span>";
833841
}
834842

835843
public function format_function_text($value, $tag, $display_value = null) {
844+
if ($this->getRole() === "function_replaceable") {
845+
return $this->TEXT($value);
846+
}
847+
836848
static $non_functions = array(
837849
"echo" => true, "print" => true,
838850
"include" => true, "include_once" => true,

phpdotnet/phd/Render.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function execute(Reader $r) { /* {{{ */
7777
$r->name === "type" ||
7878
$r->name === "classsynopsis" ||
7979
$r->name === "qandaset" ||
80-
in_array($r->name, ["methodsynopsis", "constructorsynopsis", "destructorsynopsis", "constant"], true)
80+
in_array($r->name, ["methodsynopsis", "constructorsynopsis", "destructorsynopsis", "constant", "function"], true)
8181
)
8282
) {
8383
$innerXml = $r->readInnerXml();
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<chapter xml:id="function_replaceable_rendering" xmlns="http://docbook.org/ns/docbook">
3+
4+
<section>
5+
<para>1. Function with replaceable</para>
6+
<para>
7+
<function>xml_set_<replaceable>*</replaceable></function>
8+
</para>
9+
</section>
10+
11+
<section>
12+
<para>2. Normal function (no replaceable)</para>
13+
<para>
14+
<function>strlen</function>
15+
</para>
16+
</section>
17+
18+
</chapter>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
--TEST--
2+
Function with replaceable rendering
3+
--FILE--
4+
<?php
5+
namespace phpdotnet\phd;
6+
7+
require_once __DIR__ . "/../../setup.php";
8+
9+
$xmlFile = __DIR__ . "/data/function_replaceable_rendering.xml";
10+
11+
$config->xmlFile = $xmlFile;
12+
13+
$format = new TestPHPChunkedXHTML($config, $outputHandler);
14+
15+
$render = new TestRender(new Reader($outputHandler), $config, $format);
16+
17+
$render->run();
18+
?>
19+
--EXPECTF--
20+
Filename: function_replaceable_rendering.html
21+
Content:
22+
<div id="function_replaceable_rendering" class="chapter">
23+
24+
<div class="section">
25+
<p class="para">1. Function with replaceable</p>
26+
<p class="para">
27+
<span class="function">xml_set_<span class="replaceable">*</span></span>
28+
</p>
29+
</div>
30+
31+
<div class="section">
32+
<p class="para">2. Normal function (no replaceable)</p>
33+
<p class="para">
34+
<span class="function"><strong>strlen()</strong></span>
35+
</p>
36+
</div>
37+
38+
</div>

0 commit comments

Comments
 (0)