/** * @param Token $token */ protected function transMarkdown(Token $token) { if ($this->captureIndent) { $prefix = ''; $indent = 0; $matches = null; if (preg_match('/^\\h+/', $token->value(), $matches)) { $prefix = $matches[0]; $indent = strlen(str_replace("\t", " ", $prefix)); } $token->set('INDENT', $indent)->set('PREFIX', $prefix); $this->captureIndent = false; } if ($token->match('NEWLINE')) { $space = $this->normNewline($token->value()); $step = substr_count($space, "\n"); $this->line += $step; $this->captureIndent = true; } elseif ($token->match('YAML_START')) { $this->switchContext('yaml'); } elseif ($token->match('TAG_OPEN')) { $this->switchContext('att-default'); } elseif ($token->match('OPT_OPEN')) { $this->switchContext('opt-default'); } }
/** * @param Token $token * @param string $type * @param int $position * @return Token */ protected function splitToken(Token $token, $type, $position) { $value = $token->value(); if (strlen($value) > $position) { $offset = $token->offset() + $position; $head = substr($value, 0, $position); $tail = Token::bit($type, substr($value, $position), $offset); $this->putBack($tail); $token->set($type, $head)->set(0, $head); } return $token; }
/** * @param Token $token * @return string */ protected function tagName(Token $token) { return ltrim(rtrim($token->value(), '> '), '</'); }