Example #1
0
 /**
  * @param BlockElement $block
  * @param int          $lineNumber
  */
 public function finalize(CommonMark_Element_BlockElement $block, $lineNumber)
 {
     $block->finalize($lineNumber, $this->inlineParser, $this->refMap);
     $this->tip = $block->getParent();
     // typo on 1310?
 }
Example #2
0
 /**
  * @param BlockElement $block
  * @param bool         $inTightList
  *
  * @return string
  *
  * @throws \RuntimeException
  */
 public function renderBlock(CommonMark_Element_BlockElement $block, $inTightList = false)
 {
     switch ($block->getType()) {
         case CommonMark_Element_BlockElement::TYPE_DOCUMENT:
             $wholeDoc = $this->renderBlocks($block->getChildren());
             return $wholeDoc === '' ? '' : $wholeDoc . "\n";
         case CommonMark_Element_BlockElement::TYPE_PARAGRAPH:
             if ($inTightList) {
                 return $this->renderInlines($block->getInlineContent());
             } else {
                 return $this->inTags('p', array(), $this->renderInlines($block->getInlineContent()));
             }
             break;
         case CommonMark_Element_BlockElement::TYPE_BLOCK_QUOTE:
             $filling = $this->renderBlocks($block->getChildren());
             if ($filling === '') {
                 return $this->inTags('blockquote', array(), $this->innerSeparator);
             } else {
                 return $this->inTags('blockquote', array(), $this->innerSeparator . $filling . $this->innerSeparator);
             }
         case CommonMark_Element_BlockElement::TYPE_LIST_ITEM:
             return trim($this->inTags('li', array(), $this->renderBlocks($block->getChildren(), $inTightList)));
         case CommonMark_Element_BlockElement::TYPE_LIST:
             $listData = $block->getExtra('list_data');
             $start = isset($listData['start']) ? $listData['start'] : null;
             $tag = $listData['type'] == CommonMark_Element_BlockElement::LIST_TYPE_UNORDERED ? 'ul' : 'ol';
             $attr = !$start || $start == 1 ? array() : array('start' => (string) $start);
             return $this->inTags($tag, $attr, $this->innerSeparator . $this->renderBlocks($block->getChildren(), $block->getExtra('tight')) . $this->innerSeparator);
         case CommonMark_Element_BlockElement::TYPE_ATX_HEADER:
         case CommonMark_Element_BlockElement::TYPE_SETEXT_HEADER:
             $tag = 'h' . $block->getExtra('level');
             return $this->inTags($tag, array(), $this->renderInlines($block->getInlineContent()));
         case CommonMark_Element_BlockElement::TYPE_INDENTED_CODE:
             return $this->inTags('pre', array(), $this->inTags('code', array(), $this->escape($block->getStringContent())));
         case CommonMark_Element_BlockElement::TYPE_FENCED_CODE:
             $infoWords = preg_split('/ +/', $block->getExtra('info'));
             $attr = count($infoWords) === 0 || strlen($infoWords[0]) === 0 ? array() : array('class' => 'language-' . $this->escape($infoWords[0], true));
             return $this->inTags('pre', array(), $this->inTags('code', $attr, $this->escape($block->getStringContent())));
         case CommonMark_Element_BlockElement::TYPE_HTML_BLOCK:
             return $block->getStringContent();
         case CommonMark_Element_BlockElement::TYPE_REFERENCE_DEF:
             return '';
         case CommonMark_Element_BlockElement::TYPE_HORIZONTAL_RULE:
             return $this->inTags('hr', array(), '', true);
         default:
             throw new RuntimeException('Unknown block type: ' . $block->getType());
     }
 }