original_string: public function toXhtml(\DOMDocument $document, \DOMElement $root)
      {
          $content = '';
          $caption = '';
  
          foreach ($this->node->nodes as $node) {
              $content .= $node->token->content;
          }
  
          $matches = array();
          if (preg_match('/([^<]*)<?([^>]*)>?/', $content, $matches)) {
              // if the role uses the `caption<content>` notation; extract the two parts
              if (isset($matches[2]) && $matches[2]) {
                  $content = $matches[2];
                  $caption = trim($matches[1]);
              }
          }
  
          // check the table of contents for a caption.
          if (!$caption && $this->visitor) {
              $toc = $this->visitor->getTableOfContents();
              $caption = isset($toc[$content]) ? $toc[$content]->getName() : '';
          }
  
          // if no caption is captured; create one.
          if (!$caption) {
              $caption = str_replace(
                  array('-', '_'),
                  ' ',
                  ucfirst(ltrim(substr(htmlspecialchars($content), strrpos($content, '/')), '\\/'))
              );
          }
  
          $link = $document->createElement('a', $caption);
          $root->appendChild($link);
          $link->setAttribute('href', str_replace('\\', '/', $content) . '.html');
      }
code: public function toXhtml(\DOMDocument $document, \DOMElement $root)
      {
          $content = '';
          $caption = '';
  
          foreach ($this->node->nodes as $node) {
              $content .= $node->token->content;
          }
  
          $matches = array();
          if (preg_match('/([^<]*)<?([^>]*)>?/', $content, $matches)) {
              // if the role uses the `caption<content>` notation; extract the two parts
              if (isset($matches[2]) && $matches[2]) {
                  $content = $matches[2];
                  $caption = trim($matches[1]);
              }
          }
  
          // check the table of contents for a caption.
          if (!$caption && $this->visitor) {
              $toc = $this->visitor->getTableOfContents();
              $caption = isset($toc[$content]) ? $toc[$content]->getName() : '';
          }
  
          // if no caption is captured; create one.
          if (!$caption) {
              $caption = str_replace(
                  array('-', '_'),
                  ' ',
                  ucfirst(ltrim(substr(htmlspecialchars($content), strrpos($content, '/')), '\\/'))
              );
          }
  
          $link = $document->createElement('a', $caption);
          $root->appendChild($link);
          $link->setAttribute('href', str_replace('\\', '/', $content) . '.html');
      }
code_tokens: public function toXhtml ( \ DOMDocument $ document , \ DOMElement $ root ) { $ content = '' ; $ caption = '' ; foreach ( $ this -> node -> nodes as $ node ) { $ content .= $ node -> token -> content ; } $ matches = array ( ) ; if ( preg_match ( '/([^<]*)<?([^>]*)>?/' , $ content , $ matches ) ) { // if the role uses the `caption<content>` notation; extract the two parts if ( isset ( $ matches [ 2 ] ) && $ matches [ 2 ] ) { $ content = $ matches [ 2 ] ; $ caption = trim ( $ matches [ 1 ] ) ; } } // check the table of contents for a caption. if ( ! $ caption && $ this -> visitor ) { $ toc = $ this -> visitor -> getTableOfContents ( ) ; $ caption = isset ( $ toc [ $ content ] ) ? $ toc [ $ content ] -> getName ( ) : '' ; } // if no caption is captured; create one. if ( ! $ caption ) { $ caption = str_replace ( array ( '-' , '_' ) , ' ' , ucfirst ( ltrim ( substr ( htmlspecialchars ( $ content ) , strrpos ( $ content , '/' ) ) , '\\/' ) ) ) ; } $ link = $ document -> createElement ( 'a' , $ caption ) ; $ root -> appendChild ( $ link ) ; $ link -> setAttribute ( 'href' , str_replace ( '\\' , '/' , $ content ) . '.html' ) ; }
docstring: Transform text role to HTML.
  
  Create a XHTML structure at the text roles position in the document.
  
  @param \DOMDocument $document
  @param \DOMElement  $root
  
  @return void
docstring_tokens: Transform text role to HTML .