renderBlocks() public method

public renderBlocks ( AbstractBlock[] $blocks, boolean $inTightList = false ) : string
$blocks League\CommonMark\Block\Element\AbstractBlock[]
$inTightList boolean
return string
Example #1
0
 /**
  * @param Document $block
  * @param bool $inTightList
  *
  * @return string
  */
 public function render(AbstractBlock $block, HtmlRenderer $htmlRenderer, $inTightList = false)
 {
     if (!$block instanceof Document) {
         throw new \InvalidArgumentException('Incompatible block type: ' . get_class($block));
     }
     $wholeDoc = $htmlRenderer->renderBlocks($block->getChildren());
     return $wholeDoc === '' ? '' : $wholeDoc . "\n";
 }
 /**
  * @param BlockQuote $block
  * @param HtmlRenderer $htmlRenderer
  * @param bool $inTightList
  *
  * @return HtmlElement
  */
 public function render(AbstractBlock $block, HtmlRenderer $htmlRenderer, $inTightList = false)
 {
     if (!$block instanceof BlockQuote) {
         throw new \InvalidArgumentException('Incompatible block type: ' . get_class($block));
     }
     $filling = $htmlRenderer->renderBlocks($block->getChildren());
     if ($filling === '') {
         return new HtmlElement('blockquote', array(), $htmlRenderer->getOption('inner_separator', "\n"));
     }
     return new HtmlElement('blockquote', array(), $htmlRenderer->getOption('inner_separator', "\n") . $filling . $htmlRenderer->getOption('inner_separator', "\n"));
 }
 /**
  * @param ListBlock $block
  * @param HtmlRenderer $htmlRenderer
  * @param bool $inTightList
  *
  * @return HtmlElement
  */
 public function render(AbstractBlock $block, HtmlRenderer $htmlRenderer, $inTightList = false)
 {
     if (!$block instanceof ListBlock) {
         throw new \InvalidArgumentException('Incompatible block type: ' . get_class($block));
     }
     $listData = $block->getListData();
     $start = $listData->start ?: null;
     $tag = $listData->type == ListBlock::TYPE_UNORDERED ? 'ul' : 'ol';
     $attr = !$start || $start == 1 ? array() : array('start' => (string) $start);
     return new HtmlElement($tag, $attr, $htmlRenderer->getOption('inner_separator', "\n") . $htmlRenderer->renderBlocks($block->getChildren(), $block->isTight()) . $htmlRenderer->getOption('inner_separator', "\n"));
 }
Example #4
0
 /**
  * @param ListItem $block
  * @param HtmlRenderer $htmlRenderer
  * @param bool $inTightList
  *
  * @return string
  */
 public function render(AbstractBlock $block, HtmlRenderer $htmlRenderer, $inTightList = false)
 {
     if (!$block instanceof ListItem) {
         throw new \InvalidArgumentException('Incompatible block type: ' . get_class($block));
     }
     $contents = $htmlRenderer->renderBlocks($block->getChildren(), $inTightList);
     if (substr($contents, 0, 1) === '<') {
         $contents = "\n" . $contents;
     }
     if (substr($contents, -1, 1) === '>') {
         $contents .= "\n";
     }
     $li = new HtmlElement('li', array(), $contents);
     return trim($li);
 }