renderBlocks() public method

public renderBlocks ( AbstractBlock[] $blocks, boolean $inTightList = false ) : string
$blocks League\CommonMark\Block\Element\AbstractBlock[]
$inTightList boolean
return string
 /**
  * @param AbstractBlock|Document   $block
  * @param ElementRendererInterface $htmlRenderer
  * @param bool                     $inTightList
  *
  * @return string
  */
 public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, $inTightList = false)
 {
     if (!$block instanceof Document) {
         throw new \InvalidArgumentException('Incompatible block type: ' . get_class($block));
     }
     $wholeDoc = $htmlRenderer->renderBlocks($block->children());
     return $wholeDoc === '' ? '' : $wholeDoc . "\n";
 }
示例#2
0
 /**
  * @param ListBlock                $block
  * @param ElementRendererInterface $htmlRenderer
  * @param bool                     $inTightList
  *
  * @return HtmlElement
  */
 public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, $inTightList = false)
 {
     if (!$block instanceof ListBlock) {
         throw new \InvalidArgumentException('Incompatible block type: ' . get_class($block));
     }
     $listData = $block->getListData();
     $tag = $listData->type === ListBlock::TYPE_UNORDERED ? 'ul' : 'ol';
     $attr = $listData->start === null || $listData->start === 1 ? [] : ['start' => (string) $listData->start];
     return new HtmlElement($tag, $attr, $htmlRenderer->getOption('inner_separator', "\n") . $htmlRenderer->renderBlocks($block->getChildren(), $block->isTight()) . $htmlRenderer->getOption('inner_separator', "\n"));
 }
示例#3
0
 /**
  * @param BlockQuote               $block
  * @param ElementRendererInterface $htmlRenderer
  * @param bool                     $inTightList
  *
  * @return HtmlElement
  */
 public function render(AbstractBlock $block, ElementRendererInterface $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', [], $htmlRenderer->getOption('inner_separator', "\n"));
     }
     return new HtmlElement('blockquote', [], $htmlRenderer->getOption('inner_separator', "\n") . $filling . $htmlRenderer->getOption('inner_separator', "\n"));
 }
 public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, $inTightList = false)
 {
     if (!$block instanceof TableRow) {
         throw new \InvalidArgumentException('Incompatible block type: ' . get_class($block));
     }
     $attrs = [];
     foreach ($block->getData('attributes', []) as $key => $value) {
         $attrs[$key] = $htmlRenderer->escape($value, true);
     }
     $separator = $htmlRenderer->getOption('inner_separator', "\n");
     return new HtmlElement('tr', $attrs, $separator . $htmlRenderer->renderBlocks($block->children()) . $separator);
 }
示例#5
0
 /**
  * @param ListItem                 $block
  * @param ElementRendererInterface $htmlRenderer
  * @param bool                     $inTightList
  *
  * @return string
  */
 public function render(AbstractBlock $block, ElementRendererInterface $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', [], $contents);
     return trim($li);
 }
示例#6
0
 /**
  * @param ListBlock                $block
  * @param ElementRendererInterface $htmlRenderer
  * @param bool                     $inTightList
  *
  * @return HtmlElement
  */
 public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, $inTightList = false)
 {
     if (!$block instanceof ListBlock) {
         throw new \InvalidArgumentException('Incompatible block type: ' . get_class($block));
     }
     $listData = $block->getListData();
     $tag = $listData->type === ListBlock::TYPE_UNORDERED ? 'ul' : 'ol';
     $attrs = [];
     foreach ($block->getData('attributes', []) as $key => $value) {
         $attrs[$key] = $htmlRenderer->escape($value, true);
     }
     if ($listData->start !== null && $listData->start !== 1) {
         $attrs['start'] = (string) $listData->start;
     }
     return new HtmlElement($tag, $attrs, $htmlRenderer->getOption('inner_separator', "\n") . $htmlRenderer->renderBlocks($block->getChildren(), $block->isTight()) . $htmlRenderer->getOption('inner_separator', "\n"));
 }
 /**
  * @param ListItem                 $block
  * @param ElementRendererInterface $htmlRenderer
  * @param bool                     $inTightList
  *
  * @return string
  */
 public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, $inTightList = false)
 {
     if (!$block instanceof ListItem) {
         throw new \InvalidArgumentException('Incompatible block type: ' . get_class($block));
     }
     $contents = $htmlRenderer->renderBlocks($block->children(), $inTightList);
     if (substr($contents, 0, 1) === '<') {
         $contents = "\n" . $contents;
     }
     if (substr($contents, -1, 1) === '>') {
         $contents .= "\n";
     }
     $attrs = [];
     foreach ($block->getData('attributes', []) as $key => $value) {
         $attrs[$key] = $htmlRenderer->escape($value, true);
     }
     $li = new HtmlElement('li', $attrs, $contents);
     return $li;
 }
示例#8
0
 public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, $inTightList = false)
 {
     return $htmlRenderer->renderBlocks($block->children());
 }