Inheritance: extends League\CommonMark\Node\Node
 public function __construct(AbstractBlock $container, ReferenceMap $referenceMap)
 {
     $this->referenceMap = $referenceMap;
     $this->container = $container;
     $this->cursor = new Cursor(trim($container->getStringContent()));
     $this->delimiterStack = new DelimiterStack();
 }
 private function applyAttributes(AbstractBlock $block)
 {
     $previous = null;
     $prepend = null;
     foreach ($block->getChildren() as $key => $child) {
         if ($child instanceof Attributes) {
             if ($child->isPrepend()) {
                 $prepend = $child;
             } elseif ($child->isAppend()) {
                 $previous->data['attributes'] = AttributesUtils::merge($previous ?: $block, $child->getAttributes());
             }
             $block->removeChild($child);
         } else {
             if (isset($prepend)) {
                 $child->data['attributes'] = AttributesUtils::merge($child, $prepend->getAttributes());
             }
             $prepend = null;
             $this->applyAttributes($child);
             $previous = $child;
         }
     }
     if (isset($prepend)) {
         $block->data['attributes'] = AttributesUtils::merge($block, $prepend->getAttributes());
     }
     return $block;
 }
Exemplo n.º 3
0
 public function closeUnmatchedBlocks()
 {
     while ($this->oldTip !== $this->lastMatchedContainer) {
         $this->oldTip->finalize($this->context);
         $this->oldTip = $this->oldTip->getParent();
     }
 }
 public function closeUnmatchedBlocks()
 {
     while ($this->oldTip !== $this->lastMatchedContainer) {
         $oldTip = $this->oldTip->parent();
         $this->oldTip->finalize($this->context, $this->context->getLineNumber() - 1);
         $this->oldTip = $oldTip;
     }
 }
 public function __construct($string = '', $type = self::TYPE_BODY, $align = null)
 {
     parent::__construct();
     $this->finalStringContents = $string;
     $this->type = $type;
     $this->align = $align;
 }
Exemplo n.º 6
0
 public function __construct(\Closure $parser)
 {
     parent::__construct();
     $this->appendChild(new TableRows(TableRows::TYPE_HEAD));
     $this->appendChild(new TableRows(TableRows::TYPE_BODY));
     $this->parser = $parser;
 }
 public function __construct(\Closure $parser)
 {
     parent::__construct();
     parent::addChild($this->head = new TableRows(TableRows::TYPE_HEAD));
     parent::addChild($this->body = new TableRows(TableRows::TYPE_BODY));
     $this->parser = $parser;
 }
Exemplo n.º 8
0
 /**
  * @param AbstractBlock $block
  *
  * @return AbstractBlock
  */
 public function addBlock(AbstractBlock $block)
 {
     $this->getBlockCloser()->closeUnmatchedBlocks();
     $block->setStartLine($this->lineNumber);
     while (!$this->tip->canContain($block)) {
         $this->tip->finalize($this);
     }
     $this->tip->addChild($block);
     $this->tip = $block;
     $this->container = $block;
     return $block;
 }
 public function finalize(ContextInterface $context, $endLineNumber)
 {
     parent::finalize($context, $endLineNumber);
     $this->finalStringContents = preg_replace('/^  */m', '', implode("\n", $this->getStrings()));
     // Short-circuit
     if ($this->finalStringContents === '' || $this->finalStringContents[0] !== '[') {
         return;
     }
     $cursor = new Cursor($this->finalStringContents);
     $referenceFound = $this->parseReferences($context, $cursor);
     $this->finalStringContents = $cursor->getRemainder();
     if ($referenceFound && $cursor->isAtEnd()) {
         $this->detach();
     }
 }
Exemplo n.º 10
0
 public function finalize(ContextInterface $context)
 {
     parent::finalize($context);
     $reversed = array_reverse($this->getStrings(), true);
     foreach ($reversed as $index => $line) {
         if ($line == '' || $line === "\n" || preg_match('/^(\\n *)$/', $line)) {
             unset($reversed[$index]);
         } else {
             break;
         }
     }
     $fixed = array_reverse($reversed);
     $tmp = implode("\n", $fixed);
     if (substr($tmp, -1) !== "\n") {
         $tmp .= "\n";
     }
     $this->finalStringContents = $tmp;
 }
Exemplo n.º 11
0
 public function replaceChild(ContextInterface $context, AbstractBlock $original, AbstractBlock $replacement)
 {
     if (($index = $this->children->indexOf($original)) !== false) {
         $this->children->remove($index);
         $replacement->setParent($this);
         $this->children->set($index, $replacement);
     } else {
         $this->addChild($replacement);
     }
     if ($context->getTip() === $original) {
         $context->setTip($replacement);
     }
 }
Exemplo n.º 12
0
 /**
  * @param Cursor $cursor
  * @param int $currentLineNumber
  *
  * @return $this
  */
 public function setLastLineBlank(Cursor $cursor, $currentLineNumber)
 {
     parent::setLastLineBlank($cursor, $currentLineNumber);
     $this->lastLineBlank = false;
 }
Exemplo n.º 13
0
 /**
  * @param HtmlBlock $block
  * @param HtmlRenderer $htmlRenderer
  * @param bool $inTightList
  *
  * @return string
  */
 public function render(AbstractBlock $block, HtmlRenderer $htmlRenderer, $inTightList = false)
 {
     return $block->getStringContent();
 }
Exemplo n.º 14
0
 public function finalize(ContextInterface $context, $endLineNumber)
 {
     parent::finalize($context, $endLineNumber);
     $this->finalStringContents = implode("\n", $this->getStrings());
 }
Exemplo n.º 15
0
 public function finalize(ContextInterface $context)
 {
     parent::finalize($context);
     $this->tight = true;
     // tight by default
     foreach ($this->children as $item) {
         // check for non-final list item ending with blank line:
         if ($item->endsWithBlankLine() && $item !== $this->getLastChild()) {
             $this->tight = false;
             break;
         }
         // Recurse into children of list item, to see if there are
         // spaces between any of them:
         foreach ($item->getChildren() as $subItem) {
             if ($subItem->endsWithBlankLine() && ($item !== $this->getLastChild() || $subItem !== $item->getLastChild())) {
                 $this->tight = false;
                 break;
             }
         }
     }
 }
Exemplo n.º 16
0
 public function __construct()
 {
     parent::__construct();
     $this->inlines = new ArrayCollection();
 }
 public function __construct($attributes, $direction)
 {
     parent::__construct();
     $this->attributes = $attributes;
     $this->direction = $direction;
 }
Exemplo n.º 18
0
 /**
  * Break out of all containing lists, resetting the tip of the
  * document to the parent of the highest list, and finalizing
  * all the lists.  (This is used to implement the "two blank lines
  * break of of all lists" feature.)
  *
  * @param ContextInterface $context
  * @param AbstractBlock    $block
  */
 private function breakOutOfLists(ContextInterface $context, AbstractBlock $block)
 {
     $b = $block;
     $lastList = null;
     do {
         if ($b instanceof ListBlock) {
             $lastList = $b;
         }
         $b = $b->getParent();
     } while ($b);
     if ($lastList) {
         while ($block !== $lastList) {
             $block->finalize($context);
             $block = $block->getParent();
         }
         $lastList->finalize($context);
     }
 }
 public function __construct($type = self::TYPE_BODY)
 {
     parent::__construct();
     $this->type = $type;
 }
Exemplo n.º 20
0
 /**
  * @param Cursor $cursor
  * @param int    $currentLineNumber
  *
  * @return $this
  */
 public function setLastLineBlank(Cursor $cursor, $currentLineNumber)
 {
     parent::setLastLineBlank($cursor, $currentLineNumber);
     if ($cursor->isBlank()) {
         $this->lastLineBlank = $this->startLine < $currentLineNumber;
     }
 }
 public function __construct($attributes)
 {
     parent::__construct();
     $this->attributes = $attributes;
 }
 public function __construct($caption, $id = null)
 {
     parent::__construct();
     $this->finalStringContents = $caption;
     $this->id = $id;
 }
Exemplo n.º 23
0
 public function finalize(ContextInterface $context, $endLineNumber)
 {
     parent::finalize($context, $endLineNumber);
     // first line becomes info string
     $this->info = RegexHelper::unescape(trim($this->strings->first()));
     if ($this->strings->count() === 1) {
         $this->finalStringContents = '';
     } else {
         $this->finalStringContents = implode("\n", $this->strings->slice(1)) . "\n";
     }
 }
Exemplo n.º 24
0
 public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, $inTightList = false)
 {
     return $htmlRenderer->renderBlocks($block->children());
 }
Exemplo n.º 25
0
 public function __construct()
 {
     parent::__construct();
     $this->setStartLine(1);
     $this->referenceMap = new ReferenceMap();
 }
Exemplo n.º 26
0
 public function __construct(ListData $listData)
 {
     parent::__construct();
     $this->listData = $listData;
 }
Exemplo n.º 27
0
 /**
  * @param AbstractBlock $block
  * @param HtmlRenderer $htmlRenderer
  * @param bool $inTightList
  *
  * @return HtmlElement
  */
 public function render(AbstractBlock $block, HtmlRenderer $htmlRenderer, $inTightList = false)
 {
     return new HtmlElement('pre', array(), new HtmlElement('code', array(), $htmlRenderer->escape($block->getStringContent())));
 }