/**
  * @param AbstractBlock $block
  * @param CliRenderer   $renderer
  *
  * @return string
  */
 public function render(AbstractBlock $block, CliRenderer $renderer)
 {
     if (!$block instanceof ListBlock) {
         throw new \InvalidArgumentException(sprintf('Incompatible block type: "%s"', get_class($block)));
     }
     return $renderer->renderBlocks($block->children());
 }
Пример #2
0
 /**
  * @param AbstractInline $inline
  * @param CliRenderer    $renderer
  *
  * @return string
  */
 public function render(AbstractInline $inline, CliRenderer $renderer)
 {
     if (!$inline instanceof Code) {
         throw new \InvalidArgumentException(sprintf('Incompatible inline type: "%s"', get_class($inline)));
     }
     return $renderer->style($inline->getContent(), 'yellow');
 }
Пример #3
0
 /**
  * @param AbstractInline $inline
  * @param CliRenderer    $renderer
  *
  * @return string
  */
 public function render(AbstractInline $inline, CliRenderer $renderer)
 {
     if (!$inline instanceof Link) {
         throw new \InvalidArgumentException(sprintf('Incompatible inline type: "%s"', get_class($inline)));
     }
     return $renderer->style($renderer->renderInlines($inline->children()), ['underline', 'bold', 'light_blue']);
 }
 /**
  * @param AbstractInline $inline
  * @param CliRenderer    $renderer
  *
  * @return string
  */
 public function render(AbstractInline $inline, CliRenderer $renderer)
 {
     if (!$inline instanceof Emphasis) {
         throw new \InvalidArgumentException(sprintf('Incompatible inline type: "%s"', get_class($inline)));
     }
     return $renderer->style($renderer->renderInlines($inline->children()), 'italic');
 }
 public function testRenderInlineBlocksThrowsExceptionIfNoRenderer()
 {
     $block = $this->getMock(AbstractInline::class);
     $this->setExpectedException(RuntimeException::class, sprintf('Unable to find corresponding renderer for inline type: "%s"', get_class($block)));
     $renderer = new CliRenderer([], [], new Color());
     $renderer->renderInlines([$block]);
 }
 /**
  * @param AbstractBlock $block
  * @param CliRenderer   $renderer
  *
  * @return string
  */
 public function render(AbstractBlock $block, CliRenderer $renderer)
 {
     if (!$block instanceof ThematicBreak) {
         throw new \InvalidArgumentException(sprintf('Incompatible block type: "%s"', get_class($block)));
     }
     return $renderer->style(str_repeat('-', $this->width), 'dark_gray');
 }
 /**
  * @param AbstractBlock $block
  * @param CliRenderer   $renderer
  *
  * @return string
  */
 public function render(AbstractBlock $block, CliRenderer $renderer)
 {
     if (!$block instanceof Document) {
         throw new \InvalidArgumentException(sprintf('Incompatible block type: "%s"', get_class($block)));
     }
     $wholeDoc = $renderer->renderBlocks($block->children());
     return $wholeDoc === '' ? '' : $wholeDoc . "\n";
 }
 /**
  * @param AbstractBlock $block
  * @param CliRenderer   $renderer
  *
  * @return string
  */
 public function render(AbstractBlock $block, CliRenderer $renderer)
 {
     if (!$block instanceof Heading) {
         throw new \InvalidArgumentException(sprintf('Incompatible block type: "%s"', get_class($block)));
     }
     $level = $block->getLevel();
     $text = $renderer->renderInlines($block->children());
     return sprintf("\n%s %s\n", $renderer->style(str_repeat('#', $level), 'dark_gray'), $renderer->style($text, ['bold', 'cyan']));
 }
 /**
  * @param AbstractBlock $block
  * @param CliRenderer   $renderer
  *
  * @return string
  */
 public function render(AbstractBlock $block, CliRenderer $renderer)
 {
     if (!$block instanceof FencedCode) {
         throw new \InvalidArgumentException(sprintf('Incompatible block type: "%s"', get_class($block)));
     }
     $infoWords = $block->getInfoWords();
     $codeType = null;
     if (count($infoWords) !== 0 && strlen($infoWords[0]) !== 0) {
         $codeType = $infoWords[0];
     }
     if (null === $codeType || !isset($this->highlighters[$codeType])) {
         return $this->indent($renderer->style($block->getStringContent(), 'yellow'));
     }
     return $this->indent(sprintf("%s\n", $this->highlighters[$codeType]->highlight($block->getStringContent())));
 }
Пример #10
0
 /**
  * @param string $markdown
  * @return string
  */
 public function render($markdown)
 {
     $ast = $this->docParser->parse($markdown);
     return $this->cliRenderer->renderBlock($ast);
 }