public function parse(InlineParserContext $inlineContext)
    {
        $cursor = $inlineContext->getCursor();

        $previousChar = $cursor->peek(-1);
        if ($previousChar !== null && $previousChar !== ' ') {
            return false;
        }

        $previousState = $cursor->saveState();
        $cursor->advance();

        $handle = $cursor->match('/^[A-Za-z0-9_]{1,15}(?!\w)/');
        if (empty($handle)) {
            $cursor->restoreState($previousState);

            return false;
        }

        $profileUrl = "https://twitter.com/{$handle}";
        $inlineContext->getContainer()->appendChild(new Link($profileUrl, '@'.$handle));

        return true;
    }
public function parse(InlineParserContext $inlineContext)
    {
        $cursor = $inlineContext->getCursor();

        $previousChar = $cursor->peek(-1);
        if ($previousChar !== null && $previousChar !== ' ') {
            return false;
        }

        $previousState = $cursor->saveState();
        $cursor->advance();

        $handle = $cursor->match('/^[A-Za-z0-9_]{1,15}(?!\w)/');
        if (empty($handle)) {
            $cursor->restoreState($previousState);

            return false;
        }

        $profileUrl = "https://twitter.com/{$handle}";
        $inlineContext->getContainer()->appendChild(new Link($profileUrl, '@'.$handle));

        return true;
    }
public function parse ( InlineParserContext $ inlineContext ) { $ cursor = $ inlineContext -> getCursor ( ) ; $ previousChar = $ cursor -> peek ( - 1 ) ; if ( $ previousChar !== null && $ previousChar !== ' ' ) { return false ; } $ previousState = $ cursor -> saveState ( ) ; $ cursor -> advance ( ) ; $ handle = $ cursor -> match ( '/^[A-Za-z0-9_]{1,15}(?!\w)/' ) ; if ( empty ( $ handle ) ) { $ cursor -> restoreState ( $ previousState ) ; return false ; } $ profileUrl = "https://twitter.com/{$handle}" ; $ inlineContext -> getContainer ( ) -> appendChild ( new Link ( $ profileUrl , '@' . $ handle ) ) ; return true ; }
Parse a line and determine if it contains a handle.

If it does, then we do the necessary.

@param \League\CommonMark\InlineParserContext $inlineContext

@return bool
Parse a line and determine if it contains a handle .