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;
}