예제 #1
0
 protected function renderList($block)
 {
     if ($this->_chapter > 0) {
         foreach ($block['items'] as $item => $itemLines) {
             if (preg_match('~\\[([^\\]]+)\\]\\(([^\\)]+)\\)(.*)~', implode("\n", $itemLines), $matches)) {
                 $this->_chapters[$this->_chapter]['content'][] = ['headline' => $matches[1], 'file' => $matches[2], 'teaser' => $matches[3]];
             }
         }
     }
     return parent::renderList($block);
 }
예제 #2
0
 public function getVersions()
 {
     $parser = new Markdown();
     $currentVersion = null;
     $currentLabel = null;
     foreach (new \SplFileObject($this->filePath) as $line) {
         if (preg_match($this->regex['version'], $line, $matches)) {
             if (null !== $currentVersion) {
                 $this->versions->add($currentVersion);
             }
             $currentVersion = new Version();
             $currentVersion->setVersion($matches[1]);
             if ($currentVersion->isReleased()) {
                 if (array_key_exists(2, $matches)) {
                     $currentVersion->setUrl($matches[2]);
                 }
                 if (array_key_exists(3, $matches)) {
                     $currentVersion->setReleaseDate(new \DateTime($matches[3]));
                 }
             }
             $currentVersion->setYanked(in_array('[YANKED]', $matches));
         } else {
             if (preg_match($this->regex['changes_url'], $line, $matches)) {
                 //$fullChangelogUrl = $matches[0]; // Currently not used
             } else {
                 if (preg_match($this->regex['label'], $line, $matches)) {
                     $currentLabel = $this->translator->translateFrom(strtolower($matches[1]));
                 } else {
                     if (preg_match($this->regex['change'], $line, $matches)) {
                         $change = $this->removeIssues ? preg_replace('/#\\d+/', '', $matches[1]) : $matches[1];
                         $currentVersion->addChange($currentLabel, $parser->parseParagraph($change));
                     }
                 }
             }
         }
     }
     if (null !== $currentVersion) {
         $this->versions->add($currentVersion);
     }
     return $this->versions;
 }
예제 #3
0
 /**
  * @inheritdoc
  */
 protected function renderList($block)
 {
     if ($this->_chapter > 0) {
         foreach ($block['items'] as $item => $absyElements) {
             foreach ($absyElements as $element) {
                 if ($element[0] === 'link') {
                     $this->_chapters[$this->_chapter]['content'][] = ['headline' => $this->renderAbsy($element['text']), 'file' => $element['url']];
                 }
             }
         }
     }
     return parent::renderList($block);
 }
예제 #4
0
 /**
  * Template Service Render Interface
  *
  * @param string $name
  * @param array  $data
  *
  * @return string
  */
 public function render($name, array $data = []) : string
 {
     if ($name === '') {
         throw new \InvalidArgumentException('Markdown template name cannot be empty.');
     }
     $name = pathinfo($name, PATHINFO_EXTENSION) === '' ? $name . 'md' : $name;
     $data = $this->collectScope($data);
     # search for markdown file
     foreach ($this->templatePaths as $path) {
         if (file_exists("{$path}/{$name}")) {
             $markdown = file_get_contents("{$path}/{$name}");
             $markdown = $this->translate_template_data($markdown, $data);
             return $this->markdown->parse($markdown);
         }
     }
     throw new \InvalidArgumentException('MarkdownTemplateService Error: Template file not found.');
 }
예제 #5
0
 protected function parseInline($text)
 {
     $elements = parent::parseInline($text);
     // merge special attribute elements to links and images as they are not part of the final absy later
     $relatedElement = null;
     foreach ($elements as $i => $element) {
         if ($element[0] === 'link' || $element[0] === 'images') {
             $relatedElement = $i;
         } elseif ($element[0] === 'specialAttributes') {
             if ($relatedElement !== null) {
                 $elements[$relatedElement]['attributes'] = $element[1];
                 unset($elements[$i]);
             }
             $relatedElement = null;
         } else {
             $relatedElement = null;
         }
     }
     return $elements;
 }
예제 #6
0
    public function readArticle($path)
    {
        $fullPath = $this->rootPath . DIRECTORY_SEPARATOR . $path;
        $md = new Markdown();
        $content = $md->parse(file_get_contents($fullPath));
        return <<<HTML
         <div class="panel">
            <div class="panel-body" style="min-height:500px">
               {$content}
            </div>
        </div>
HTML;
    }
예제 #7
0
 /**
  * {@inheritdoc}
  */
 public function run($markdown = '')
 {
     return $this->markdown->parse($markdown);
 }
예제 #8
0
 /**
  * {@inheritdoc}
  */
 public function addDocumentation($url, $title)
 {
     $this->documentation[] = ['url' => $url, 'title' => $this->parser->parseParagraph($title)];
     return $this;
 }
 public function __invoke(Filter $node, Compiler $compiler)
 {
     $parser = new Parser();
     return $parser->parse($this->getNodeString($node, $compiler));
 }