/**
  * Execute shortcode.
  *
  * @param  Event        $event An event object.
  * @return string|null         Return modified contents.
  */
 public function execute(Event $event)
 {
     /* @var \Grav\Common\Data\Data $options */
     $options = $event['options'];
     /* @var \Grav\Common\Grav $grav */
     $grav = $event['grav'];
     /* @var \Grav\Common\Page\Page $page */
     $page = $event['page'];
     /* @var Config $config */
     $config = $grav['config'];
     $body = trim($event['body']);
     // Mimic \Grav\Common\Page\Page processMarkdown() method
     $defaults = (array) $config->get('system.pages.markdown');
     $defaults = array_merge_recursive($defaults, $this->defaults);
     $options->setDefaults($defaults);
     if (isset($page->header()->markdown)) {
         $options->merge($page->header()->markdown);
     }
     // Initialize the preferred variant of Parsedown
     if ($options->get('extra')) {
         $parsedown = new ParsedownExtra($page, $options->toArray());
     } else {
         $parsedown = new Parsedown($page, $options->toArray());
     }
     $content = $parsedown->text($body);
     return $content;
 }
 /**
  * Return HTML markup from the medium.
  *
  * @param string $title
  * @param string $alt
  * @param string $class
  * @param string $id
  * @param bool $reset
  * @return string
  */
 public function html($title = null, $alt = null, $class = null, $id = null, $reset = true)
 {
     $element = $this->parsedownElement($title, $alt, $class, $id, $reset);
     if (!$this->parsedown) {
         $this->parsedown = new Parsedown(null, null);
     }
     return $this->parsedown->elementToHtml($element);
 }
Exemple #3
0
 public function testInvalidLinksSubDirAbsoluteUrl()
 {
     $this->config->set('system.absolute_urls', true);
     $this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
     $this->assertSame('<p><a href="http://testing.dev/subdir/item2/item2-2/no-page">Non Existent Page</a></p>', $this->parsedown->text('[Non Existent Page](no-page)'));
     $this->assertSame('<p><a href="http://testing.dev/subdir/item2/item2-2/existing-file.zip">Existent File</a></p>', $this->parsedown->text('[Existent File](existing-file.zip)'));
     $this->assertSame('<p><a href="http://testing.dev/subdir/item2/item2-2/missing-file.zip">Non Existent File</a></p>', $this->parsedown->text('[Non Existent File](missing-file.zip)'));
 }
Exemple #4
0
 public function markdownFilter($string)
 {
     $page = $this->grav['page'];
     $defaults = $this->config->get('system.pages.markdown');
     // Initialize the preferred variant of Parsedown
     if ($defaults['extra']) {
         $parsedown = new ParsedownExtra($page, $defaults);
     } else {
         $parsedown = new Parsedown($page, $defaults);
     }
     $string = $parsedown->text($string);
     return $string;
 }
Exemple #5
0
 /**
  * Process the Markdown content.  Uses Parsedown or Parsedown Extra depending on configuration
  */
 protected function processMarkdown()
 {
     /** @var Config $config */
     $config = self::getGrav()['config'];
     $defaults = (array) $config->get('system.pages.markdown');
     if (isset($this->header()->markdown)) {
         $defaults = array_merge($defaults, $this->header()->markdown);
     }
     // pages.markdown_extra is deprecated, but still check it...
     if (!isset($defaults['extra']) && (isset($this->markdown_extra) || $config->get('system.pages.markdown_extra') !== null)) {
         $defaults['extra'] = $this->markdown_extra ?: $config->get('system.pages.markdown_extra');
     }
     // Initialize the preferred variant of Parsedown
     if ($defaults['extra']) {
         $parsedown = new ParsedownExtra($this, $defaults);
     } else {
         $parsedown = new Parsedown($this, $defaults);
     }
     $this->content = $parsedown->text($this->content);
 }
 /**
  * Process the page's Markdown content
  *
  * By converting the markdown to HTML first makes searching the markers easier
  *
  * @note inspirated by grav/system/src/Grav/Common/Page/Page.php
  */
 protected function processMarkdown($page)
 {
     $config = $this->grav['config'];
     $defaults = (array) $config->get('system.pages.markdown');
     if (isset($page->header()->markdown)) {
         $defaults = array_merge($defaults, $page->header()->markdown);
     }
     if ($defaults['extra']) {
         $parsedown = new ParsedownExtra($page, $defaults);
     } else {
         $parsedown = new Parsedown($page, $defaults);
     }
     return $parsedown->text($page->getRawContent());
 }