Example #1
0
 function init()
 {
     parent::init();
     list($this->md_file, $junk) = explode('.', $_GET['args']);
     if ($this->md_file == '' && !isset($this->api->real_page)) {
         $this->md_file = 'index';
     } else {
         if (isset($this->api->real_page)) {
             $this->md_file = $this->api->real_page;
             /*
              * Let's say truth about location to all element on this page.
              * Thay want to send proper AJAX to out server :)
              */
             $this->api->page = $this->api->real_page;
         }
     }
     $parser = new dflydev\markdown\MarkdownExtraParser();
     $html = $parser->transformMarkdown(file_get_contents($this->api->locatePath('docs', $this->md_file . '.md')));
     if ($this->api->atk_version == "4.3") {
         $html = str_replace('<pre><code>', '{Example}', $html);
         $html = str_replace('</code></pre>', '{/Example}', $html);
     } else {
         $html = str_replace('<pre><code>', '<?Example?>', $html);
         $html = str_replace('</code></pre>', '<?/Example?>', $html);
     }
     $html = preg_replace('/<p><img src="([^"]*)" alt="([^"]*)" \\/><\\/p>/', '<?Image?>\\1 \\2<?/?>', $html);
     $this->template->loadTemplateFromString($html);
     $page = $this;
     /*
     $page->template->eachTag('Code',function($a,$b) use($page){
         $page->add('documenting/View_Example', null,$b)->set("\n".$a,true);
     });
     $page->template->eachTag('Example',function($a,$b) use($page){
         $page->add('documenting/View_Example', null,$b)->set(htmlspecialchars_decode("\n".$a));
     });
     */
     $page->template->eachTag('Image', function ($a, $b) use($page) {
         list($file, $title) = explode(' ', $a, 2);
         $page->add('View', null, $b)->setElement('image')->setAttr('src', $page->api->locateURL('public', 'images/doc/' . dirname($page->page) . '/' . $file))->setAttr('alt', $title)->setAttr('title', $title);
     });
     // relative links
     //        $page->template->eachTag('link',
     //            function(&$a,$b) use ($page) {
     //                var_dump($a);
     //                var_dump($b);
     //                $page->template->set($b,$page->api->url($a));
     //            }
     //        );
     $this->api->code_executed = true;
 }
 /**
  * Return a formatted variant of the Long Description using MarkDown.
  *
  * @todo this should become a more intelligent piece of code where the
  *     configuration contains a setting what format long descriptions are.
  *
  * @return string
  */
 public function getFormattedContents()
 {
     $result = $this->contents;
     // if the long description contains a plain HTML <code> element, surround
     // it with a pre element. Please note that we explicitly used str_replace
     // and not preg_replace to gain performance
     if (strpos($result, '<code>') !== false) {
         $result = str_replace(array('<code>', "<code>\r\n", "<code>\n", "<code>\r", '</code>'), array('<pre><code>', '<code>', '<code>', '<code>', '</code></pre>'), $result);
     }
     if (class_exists('\\dflydev\\markdown\\MarkdownExtraParser')) {
         $md = new \dflydev\markdown\MarkdownExtraParser();
         $result = $md->transformMarkdown($result);
     }
     return trim($result);
 }
Example #3
0
 /**
  * Find all the param tags and if using special characters transform
  * using markdown otherwise just add a <p> tag to be consistent.
  *
  * @param \DOMDocument $xml Structure source to apply behaviour onto.
  *
  * @return \DOMDocument
  */
 public function process(\DOMDocument $xml)
 {
     $qry = '//tag[@name=\'' . $this->element_name . '\']/@description[. != ""]';
     $xpath = new \DOMXPath($xml);
     $nodes = $xpath->query($qry);
     /** @var \DOMElement $node */
     foreach ($nodes as $node) {
         // only transform using markdown if the text contains characters
         // other than word characters, whitespaces and punctuation characters.
         // This is because Markdown is a huge performance hit on the system
         if (!preg_match('/^[\\w|\\s|\\.|,|;|\\:|\\&|\\#]+$/', $node->nodeValue)) {
             $md = new \dflydev\markdown\MarkdownExtraParser();
             $node->nodeValue = $md->transformMarkdown($node->nodeValue);
         } else {
             // markdown will always surround the element with a paragraph;
             // we do the same here to make it consistent
             $node->nodeValue = '&lt;p&gt;' . $node->nodeValue . '&lt;/p&gt;';
         }
     }
     return $xml;
 }
Example #4
0
function md($text)
{
    static $obj = NULL;
    $obj === NULL && ($obj = new \dflydev\markdown\MarkdownExtraParser());
    return $obj->transformMarkdown($text);
}