League\CommonMark\Block\Parser\ATXHeadingParser::parse PHP Method

parse() public method

public parse ( League\CommonMark\ContextInterface $context, Cursor $cursor ) : boolean
$context League\CommonMark\ContextInterface
$cursor League\CommonMark\Cursor
return boolean
    public function parse(ContextInterface $context, Cursor $cursor)
    {
        if ($cursor->isIndented()) {
            return false;
        }
        $match = RegexHelper::matchAll('/^#{1,6}(?:[ \\t]+|$)/', $cursor->getLine(), $cursor->getFirstNonSpacePosition());
        if (!$match) {
            return false;
        }
        $cursor->advanceToFirstNonSpace();
        $cursor->advanceBy(strlen($match[0]));
        $level = strlen(trim($match[0]));
        $str = $cursor->getRemainder();
        $str = preg_replace('/^ *#+ *$/', '', $str);
        $str = preg_replace('/ +#+ *$/', '', $str);
        $context->addBlock(new Heading($level, $str));
        $context->setBlocksParsed(true);
        return true;
    }
ATXHeadingParser