Lexer->addSpecialPattern( '\n#{1,6}(?!#)(?:[ \t][^\n]*)?(?=\n)', $mode, 'gfm_header' ); } /** @inheritdoc */ public function handle($match, $state, $pos, Handler $handler) { $line = ltrim($match, "\n"); $level = strspn($line, '#'); $title = trim(substr($line, $level)); // Optional closing `#` run. The sequence must be preceded by // whitespace; a `#` touching the body (`# foo#`) is content. // A body that is nothing but `#`s is a closer with no title. if ($title !== '' && preg_match('/^#+$/', $title)) { $title = ''; } elseif (preg_match('/^(.*?)[ \t]+#+$/', $title, $m)) { $title = rtrim($m[1]); } if ($handler->getStatus('section')) { $handler->addCall('section_close', [], $pos); } $handler->addCall('header', [$title, $level, $pos], $pos); $handler->addCall('section_open', [$level], $pos); $handler->setStatus('section', true); return true; } }