/**
  * Add token with data:
  * * level   - header level (depend on # count)
  * * content - header content
  *
  * @param string                  $content
  * @param int                     $position
  * @param \ViKon\Parser\TokenList $tokenList
  *
  * @return bool
  */
 protected function handleSingleState($content, $position, TokenList $tokenList)
 {
     $content = trim($content);
     preg_match('/^#{1,6}/', $content, $matches);
     $tokenList->addToken($this->name, $position)->set('level', abs(strlen($matches[0])))->set('content', trim($content, "# \t\n\r\v"));
     return true;
 }
 /**
  * Add token with data:
  * * level   - header level (depend on # count)
  * * content - header
  *
  * @param string                  $content
  * @param int                     $position
  * @param \ViKon\Parser\TokenList $tokenList
  *
  * @return bool
  */
 protected function handleSingleState($content, $position, TokenList $tokenList)
 {
     list(, $content, $level) = explode("\n", $content);
     $content = trim($content);
     $level = $level[0] === '=' ? 1 : 2;
     $tokenList->addToken($this->name, $position)->set('level', $level)->set('content', $content);
     return true;
 }
 /**
  * @param string                  $content
  * @param int                     $position
  * @param int                     $state
  * @param \ViKon\Parser\TokenList $tokenList
  *
  * @throws \ViKon\Parser\Rule\RuleException
  */
 public function parseToken($content, $position, $state, TokenList $tokenList)
 {
     switch ($state) {
         case Lexer::STATE_MATCHED:
             $token = $tokenList->addToken($this->name, $position);
             $token->set('content', str_repeat("\n", substr_count($content, "\n")));
             break;
         default:
             parent::parseToken($content, $position, $state, $tokenList);
             break;
     }
 }
 /**
  * Add token with data:
  * * match     - whole matched content
  * * alt       - alt content for image
  * * reference - reference name or object
  *
  * @param string                  $content
  * @param int                     $position
  * @param \ViKon\Parser\TokenList $tokenList
  */
 protected function handleSingleState($content, $position, TokenList $tokenList)
 {
     preg_match('/!\\[((?:\\\\.|[^]\\\\])+)\\][\\t ]*\\[((?:\\\\.|[^]\\\\])*)\\]/', $content, $matches);
     $reference = strtolower(empty($matches[2]) ? $matches[1] : $matches[2]);
     $referenceTokens = $tokenList->getTokensByCallback(function (Token $token) use($reference) {
         return $token->getName() === ReferenceRule::NAME && $token->get('reference', null) === $reference;
     });
     if (($referenceToken = reset($referenceTokens)) !== false) {
         $referenceToken->set('used', true);
         $reference = $referenceToken;
     }
     $tokenList->addToken($this->name, $position)->set('match', $content)->set('alt', $matches[1])->set('reference', $reference);
 }
 /**
  * Add token with data
  * * match     - whole matched content
  * * label     - link content
  * * reference - reference name or object
  *
  * @param string                  $content
  * @param int                     $position
  * @param \ViKon\Parser\TokenList $tokenList
  */
 protected function handleSingleState($content, $position, TokenList $tokenList)
 {
     preg_match('/\\[((?:\\\\.|[^]\\\\])+)\\](?: ?\\[((?:\\\\.|[^]\\\\])+)\\])?/', $content, $matches);
     $reference = strtolower(empty($matches[2]) ? $matches[1] : $matches[2]);
     // List all reference token which match url reference part
     $referenceTokens = $tokenList->getTokensByCallback(function (Token $token) use($reference) {
         return $token->getName() === ReferenceRule::NAME && $token->get('reference', null) === $reference;
     });
     // Get first matching reference token
     if (($referenceToken = reset($referenceTokens)) !== false) {
         $referenceToken->set('used', true);
         $reference = $referenceToken;
     }
     $tokenList->addToken($this->name, $position)->set('match', $content)->set('label', $matches[1])->set('reference', $reference);
 }
Ejemplo n.º 6
0
 /**
  * @param string                  $content
  * @param int                     $position
  * @param \ViKon\Parser\TokenList $tokenList
  */
 protected function handleMatchedState($content, $position, TokenList $tokenList)
 {
     $cols = explode('|', trim($content, "\n|"));
     $tokenList->addToken($this->name . '_ROW_OPEN', $position);
     foreach ($cols as $i => $col) {
         $token = $tokenList->addToken($this->name . '_COLL_OPEN', $position);
         if (isset($this->colAlign[$i]) && $this->colAlign[$i] !== null) {
             $token->set('align', $this->colAlign[$i]);
         }
         $this->parseCol($col, $tokenList);
         $tokenList->addToken($this->name . '_COLL_CLOSE', $position);
     }
     $tokenList->addToken($this->name . '_ROW_CLOSE', $position);
 }
 /**
  * @param string                  $content
  * @param int                     $position
  * @param \ViKon\Parser\TokenList $tokenList
  *
  * @return bool
  */
 protected function handleUnmatchedState($content, $position, TokenList $tokenList)
 {
     if (empty($content)) {
         return;
     }
     $lastToken = $tokenList->last();
     if ($lastToken !== null && $lastToken->getName() === $this->name) {
         $lastToken->set('content', $lastToken->get('content', '') . $content);
     } else {
         $tokenList->addToken($this->name, $position)->set('content', $content);
     }
 }
 /**
  * Add token with data
  * * match     - whole matched content
  * * reference - reference identifier
  * * url       - reference url
  * * title     - reference title
  * * used      - indicates if reference is used by link or image
  *
  * @param string                  $content
  * @param int                     $position
  * @param \ViKon\Parser\TokenList $tokenList
  */
 protected function handleSingleState($content, $position, TokenList $tokenList)
 {
     preg_match('/\\[((?:\\\\.|[^]\\\\])*)\\]:[ \\t]*([^ \\t\\n]+)[ \\t]*\\n?[ \\t]*(?:["\'\\(]((?:\\\\.|[^"\\\\])+)["\'\\)])?/', $content, $matches);
     $tokenList->addToken($this->name, $position)->set('match', $content)->set('reference', strtolower($matches[1]))->set('url', $matches[2])->set('title', isset($matches[3]) ? $matches[3] : null)->set('used', false);
 }
 /**
  * Handle lexers entry state
  *
  * @param string                  $content
  * @param int                     $position
  * @param \ViKon\Parser\TokenList $tokenList
  */
 protected function handleEntryState($content, $position, TokenList $tokenList)
 {
     $lang = trim($content, " `\t\n\r\v");
     $tokenList->addToken($this->name . self::OPEN, $position)->set('lang', $lang);
 }
Ejemplo n.º 10
0
 /**
  * @param string                  $content
  * @param int                     $position
  * @param \ViKon\Parser\TokenList $tokenList
  */
 protected function handleSingleState($content, $position, TokenList $tokenList)
 {
     $tokenList->addToken($this->name, $position)->set('url', $content);
 }
 /**
  * Add token with data
  * * label - link content
  * * url   - link url address
  * * title - link title (optional)
  *
  * @param string                  $content
  * @param int                     $position
  * @param \ViKon\Parser\TokenList $tokenList
  */
 protected function handleSingleState($content, $position, TokenList $tokenList)
 {
     preg_match('/\\[((?:\\\\.|[^]\\\\])+)\\][\\t ]*\\([\\t ]*((?:\\\\.|[^\\)\\\\ ])+)[\\t ]*(?:"((?:\\\\.|[^"\\\\])+)")?\\)/', $content, $matches);
     $tokenList->addToken($this->name, $position)->set('label', $matches[1])->set('url', $matches[2])->set('title', isset($matches[3]) ? $matches[3] : null);
 }
Ejemplo n.º 12
0
 /**
  * @param string                  $content
  * @param int                     $position
  * @param \ViKon\Parser\TokenList $tokenList
  */
 protected function handleUnmatchedState($content, $position, TokenList $tokenList)
 {
     $tokenList->addToken($this->name, $position)->set('expression', $content);
 }
Ejemplo n.º 13
0
 protected function handleSingleState($content, $position, TokenList $tokenList)
 {
     preg_match('/(\\\\\\\\|\\\\`|\\\\\\*|\\\\\\_|\\\\\\{|\\\\\\}|\\\\\\[|\\\\\\]|\\\\\\(|\\\\\\)|\\\\\\#|\\\\\\+|\\\\\\-|\\\\\\.|\\\\\\!)/', $content, $matches);
     $tokenList->addToken($this->name, $position)->set('char', $matches[1][1]);
 }
Ejemplo n.º 14
0
 /**
  * Accept all matches
  *
  * @param string                  $content
  * @param int                     $position
  * @param int                     $state
  * @param \ViKon\Parser\TokenList $tokenList
  */
 public function parseToken($content, $position, $state, TokenList $tokenList)
 {
     if (!empty($content)) {
         $tokenList->addToken($this->name, $position)->set('content', $content);
     }
 }