diff --git a/phpdotnet/phd/Format/Abstract/XHTML.php b/phpdotnet/phd/Format/Abstract/XHTML.php index a28b59a..12f5717 100644 --- a/phpdotnet/phd/Format/Abstract/XHTML.php +++ b/phpdotnet/phd/Format/Abstract/XHTML.php @@ -6,6 +6,9 @@ abstract class Format_Abstract_XHTML extends Format { /** @var array Last In First Out stack of roles */ private array $role = []; + /** @var array Last In First Out stack of annotations */ + private array $annotations = []; + /* XHTMLPhDFormat */ protected $openPara = 0; protected $escapedPara = array(); @@ -44,13 +47,19 @@ abstract class Format_Abstract_XHTML extends Format { } public function CDATA($value) { + $annotations = $this->getAnnotations(); + $annotationsStr = ''; + if (count($annotations) > 0) { + $annotationsStr = 'annotation-' . join(' annotation-', $annotations) . ' '; + } + switch($this->getRole()) { case '': - return '
'
+            return '
'
                 . htmlspecialchars($value, ENT_QUOTES, "UTF-8")
                 . '
'; default: - return '
' + return '
' . $this->highlight(trim($value), $this->getRole(), 'xhtml') . '
'; } @@ -139,4 +148,20 @@ abstract class Format_Abstract_XHTML extends Format { protected function popRole(): ?string { return array_pop($this->role); } + + protected function pushAnnotations(?string $annotations): void { + $this->annotations[] = ($annotations != null ? explode(' ', $annotations) : []); + } + + protected function getAnnotations() : ?array { + $top = end($this->annotations); + if ($top === false) { + $top = []; + } + return $top; + } + + protected function popAnnotations() : ?array { + return array_pop($this->annotations); + } } diff --git a/phpdotnet/phd/Package/Generic/XHTML.php b/phpdotnet/phd/Package/Generic/XHTML.php index f421282..ad9dc32 100644 --- a/phpdotnet/phd/Package/Generic/XHTML.php +++ b/phpdotnet/phd/Package/Generic/XHTML.php @@ -820,6 +820,8 @@ abstract class Package_Generic_XHTML extends Format_Abstract_XHTML { } public function format_container_chunk_top($open, $name, $attrs, $props) { + $hasAnnotations = array_key_exists('annotations', $attrs[Reader::XMLNS_DOCBOOK]); + $this->cchunk = $this->dchunk; $this->cchunk["name"] = $name; if(isset($attrs[Reader::XMLNS_XML]["id"])) { @@ -829,12 +831,20 @@ abstract class Package_Generic_XHTML extends Format_Abstract_XHTML { } if ($open) { + if ($hasAnnotations) { + $this->pushAnnotations($attrs[Reader::XMLNS_DOCBOOK]["annotations"]); + } + $this->CURRENT_CHUNK = $id; $this->notify(Render::CHUNK, Render::OPEN); return '
'; } + if ($hasAnnotations) { + $this->popAnnotations(); + } + $this->CURRENT_CHUNK = $id; $this->notify(Render::CHUNK, Render::CLOSE); $toc = ""; @@ -1714,10 +1724,17 @@ abstract class Package_Generic_XHTML extends Format_Abstract_XHTML { return "

"; } public function format_programlisting($open, $name, $attrs) { + $hasAnnotations = array_key_exists('annotations', $attrs[Reader::XMLNS_DOCBOOK]); if ($open) { $this->pushRole($attrs[Reader::XMLNS_DOCBOOK]["role"] ?? null); + if ($hasAnnotations) { + $this->pushAnnotations($attrs[Reader::XMLNS_DOCBOOK]["annotations"]); + } return '
'; } + if ($hasAnnotations) { + $this->popAnnotations(); + } $this->popRole(); return "
\n"; } diff --git a/phpdotnet/phd/Package/PHP/XHTML.php b/phpdotnet/phd/Package/PHP/XHTML.php index 4191181..d70843a 100644 --- a/phpdotnet/phd/Package/PHP/XHTML.php +++ b/phpdotnet/phd/Package/PHP/XHTML.php @@ -914,6 +914,8 @@ abstract class Package_PHP_XHTML extends Package_Generic_XHTML { } public function format_container_chunk($open, $name, $attrs, $props) { + $hasAnnotations = array_key_exists('annotations', $attrs[Reader::XMLNS_DOCBOOK]); + $this->CURRENT_CHUNK = $this->CURRENT_ID = $id = $attrs[Reader::XMLNS_XML]["id"] ?? ''; if ($this->isChunkedByAttributes($attrs)) { @@ -921,6 +923,10 @@ abstract class Package_PHP_XHTML extends Package_Generic_XHTML { } if ($open) { + if ($hasAnnotations) { + $this->pushAnnotations($attrs[Reader::XMLNS_DOCBOOK]["annotations"]); + } + $this->notify(Render::CHUNK, Render::OPEN); if ($name != "reference") { $chunks = Format::getChildren($id); @@ -937,6 +943,10 @@ abstract class Package_PHP_XHTML extends Package_Generic_XHTML { } return '
'; } + if ($hasAnnotations) { + $this->popAnnotations(); + } + $this->notify(Render::CHUNK, Render::CLOSE); $content = ""; @@ -957,11 +967,22 @@ abstract class Package_PHP_XHTML extends Package_Generic_XHTML { } public function format_root_chunk($open, $name, $attrs) { + $hasAnnotations = array_key_exists('annotations', $attrs[Reader::XMLNS_DOCBOOK]); + $this->CURRENT_CHUNK = $this->CURRENT_ID = $id = $attrs[Reader::XMLNS_XML]["id"] ?? ''; if ($open) { + if ($hasAnnotations) { + $this->pushAnnotations($attrs[Reader::XMLNS_DOCBOOK]["annotations"]); + } + $this->notify(Render::CHUNK, Render::OPEN); return '
'; } + + if ($hasAnnotations) { + $this->popAnnotations(); + } + $this->notify(Render::CHUNK, Render::CLOSE); $chunks = Format::getChildren($id); $content = '
    ';