for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/*
* This file is part of the league/commonmark package.
*
* (c) Davey Shafik <[email protected]
* (c) Colin O'Dell <[email protected]>
* (c) Dan Hunsaker <[email protected]>
* Original code based on the CommonMark JS reference parser (http://bitly.com/commonmarkjs)
* - (c) John MacFarlane
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Danhunsaker\Markua\Block\Parser;
use League\CommonMark\Block\Parser\AbstractBlockParser;
use League\CommonMark\ContextInterface;
use League\CommonMark\Cursor;
use Danhunsaker\Markua\Block\Element\IconBlock;
class IconBlockParser extends AbstractBlockParser
{
/**
* @param ContextInterface $context
* @param Cursor $cursor
* @return bool
public function parse(ContextInterface $context, Cursor $cursor)
if (!in_array($cursor->getNextNonSpaceCharacter(), IconBlock::getIconBlockTypes()) ||
$cursor->getCharacter($cursor->getNextNonSpacePosition() + 1) !== '>') {
return false;
}
$type = $cursor->getNextNonSpaceCharacter();
$cursor->advanceToNextNonSpaceOrNewline();
if ($cursor->peek() === '>') {
$cursor->advanceBy(2);
if ($cursor->getCharacter() === ' ') {
$cursor->advance();
$context->addBlock(new IconBlock($type));
return true;