本文整理汇总了PHP中League\CommonMark\Cursor::advanceBy方法的典型用法代码示例。如果您正苦于以下问题:PHP Cursor::advanceBy方法的具体用法?PHP Cursor::advanceBy怎么用?PHP Cursor::advanceBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类League\CommonMark\Cursor
的用法示例。
在下文中一共展示了Cursor::advanceBy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parse
public static function parse(Cursor $cursor)
{
if (null === self::$regexp) {
$regex = RegexHelper::getInstance();
self::$regexp = sprintf('/^\\s*([.#][_a-z0-9-]+|%s%s)(?<!})\\s*/i', $regex->getPartialRegex(RegexHelper::ATTRIBUTENAME), $regex->getPartialRegex(RegexHelper::ATTRIBUTEVALUESPEC));
}
$state = $cursor->saveState();
$cursor->advanceToFirstNonSpace();
if ('{' !== $cursor->getCharacter()) {
$cursor->restoreState($state);
return [];
}
$cursor->advanceBy(1);
if (':' === $cursor->getCharacter()) {
$cursor->advanceBy(1);
}
$attributes = [];
while ($attribute = trim($cursor->match(self::$regexp))) {
if ('#' === $attribute[0]) {
$attributes['id'] = substr($attribute, 1);
continue;
}
if ('.' === $attribute[0]) {
$attributes['class'][] = substr($attribute, 1);
continue;
}
list($name, $value) = explode('=', $attribute, 2);
$first = $value[0];
$last = substr($value, -1);
if (('"' === $first && '"' === $last || "'" === $first && "'" === $last) && strlen($value) > 1) {
$value = substr($value, 1, -1);
}
if ('class' === strtolower(trim($name))) {
foreach (array_filter(explode(' ', trim($value))) as $class) {
$attributes['class'][] = $class;
}
} else {
$attributes[trim($name)] = trim($value);
}
}
if (0 === $cursor->advanceWhileMatches('}')) {
$cursor->restoreState($state);
return [];
}
if (isset($attributes['class'])) {
$attributes['class'] = implode(' ', $attributes['class']);
}
return $attributes;
}
示例2: parse
/**
* @param ContextInterface $context
* @param Cursor $cursor
*
* @return bool
*/
public function parse(ContextInterface $context, Cursor $cursor)
{
$tmpCursor = clone $cursor;
$indent = $tmpCursor->advanceWhileMatches(' ', 3);
$rest = $tmpCursor->getRemainder();
$data = new ListData();
if ($matches = RegexHelper::matchAll('/^[*+-]( +|$)/', $rest)) {
$spacesAfterMarker = strlen($matches[1]);
$data->type = ListBlock::TYPE_UNORDERED;
$data->delimiter = null;
$data->bulletChar = $matches[0][0];
} elseif ($matches = RegexHelper::matchAll('/^(\\d+)([.)])( +|$)/', $rest)) {
$spacesAfterMarker = strlen($matches[3]);
$data->type = ListBlock::TYPE_ORDERED;
$data->start = intval($matches[1]);
$data->delimiter = $matches[2];
$data->bulletChar = null;
} else {
return false;
}
$data->padding = $this->calculateListMarkerPadding($matches[0], $spacesAfterMarker, $rest);
$cursor->advanceToFirstNonSpace();
$cursor->advanceBy($data->padding);
// list item
$data->markerOffset = $indent;
// add the list if needed
$container = $context->getContainer();
if (!$container || !$context->getContainer() instanceof ListBlock || !$data->equals($container->getListData())) {
$context->addBlock(new ListBlock($data));
}
// add the list item
$context->addBlock(new ListItem($data));
return true;
}
示例3: matchesNextLine
public function matchesNextLine(Cursor $cursor)
{
if ($cursor->getIndent() >= $this->listData->markerOffset + $this->listData->padding) {
$cursor->advanceBy($this->listData->markerOffset + $this->listData->padding, true);
} elseif ($cursor->isBlank()) {
$cursor->advanceToFirstNonSpace();
} else {
return false;
}
return true;
}
示例4: matchesNextLine
public function matchesNextLine(Cursor $cursor)
{
if ($cursor->getIndent() >= IndentedCodeParser::CODE_INDENT_LEVEL) {
$cursor->advanceBy(IndentedCodeParser::CODE_INDENT_LEVEL);
} elseif ($cursor->isBlank()) {
$cursor->advanceToFirstNonSpace();
} else {
return false;
}
return true;
}
示例5: matchesNextLine
public function matchesNextLine(Cursor $cursor)
{
if ($cursor->isIndented()) {
$cursor->advanceBy(Cursor::INDENT_LEVEL, true);
} elseif ($cursor->isBlank()) {
$cursor->advanceToFirstNonSpace();
} else {
return false;
}
return true;
}
示例6: matchesNextLine
public function matchesNextLine(Cursor $cursor)
{
if ($cursor->getIndent() <= 3 && $cursor->getFirstNonSpaceCharacter() == 'A') {
$cursor->advanceToFirstNonSpace();
if ($cursor->peek() === '>') {
$cursor->advanceBy(2);
if ($cursor->getCharacter() === ' ') {
$cursor->advance();
}
return true;
}
}
return false;
}
示例7: matchesNextLine
public function matchesNextLine(Cursor $cursor)
{
if ($cursor->getIndent() <= 3 && in_array($cursor->getFirstNonSpaceCharacter(), static::getIconBlockTypes())) {
$cursor->advanceToFirstNonSpace();
if ($cursor->peek() === '>') {
$cursor->advanceBy(2);
if ($cursor->getCharacter() === ' ') {
$cursor->advance();
}
return true;
}
}
return false;
}
示例8: parse
/**
* @param ContextInterface $context
* @param Cursor $cursor
*
* @return bool
*/
public function parse(ContextInterface $context, Cursor $cursor)
{
if ($cursor->isIndented()) {
return false;
}
$match = RegexHelper::matchAt(RegexHelper::getInstance()->getThematicBreakRegex(), $cursor->getLine(), $cursor->getFirstNonSpacePosition());
if ($match === null) {
return false;
}
// Advance to the end of the string, consuming the entire line (of the thematic break)
$cursor->advanceBy(mb_strlen($cursor->getRemainder()));
$context->addBlock(new ThematicBreak());
$context->setBlocksParsed(true);
return true;
}
示例9: parse
/**
* @param ContextInterface $context
* @param Cursor $cursor
*
* @return bool
*/
public function parse(ContextInterface $context, Cursor $cursor)
{
if (!$cursor->isIndented()) {
return false;
}
if ($context->getTip() instanceof Paragraph) {
return false;
}
if ($cursor->isBlank()) {
return false;
}
$cursor->advanceBy(Cursor::INDENT_LEVEL, true);
$context->addBlock(new IndentedCode());
return true;
}
示例10: parse
/**
* @param ContextInterface $context
* @param Cursor $cursor
*
* @return bool
*/
public function parse(ContextInterface $context, Cursor $cursor)
{
if ($cursor->getFirstNonSpaceCharacter() !== 'A' || $cursor->getCharacter($cursor->getFirstNonSpacePosition() + 1) !== '>') {
return false;
}
$cursor->advanceToFirstNonSpace();
if ($cursor->peek() === '>') {
$cursor->advanceBy(2);
if ($cursor->getCharacter() === ' ') {
$cursor->advance();
}
}
$context->addBlock(new Aside());
return true;
}
示例11: parse
/**
* @param \League\CommonMark\ContextInterface $context
* @param \League\CommonMark\Cursor $cursor
*
* @return bool
*/
public function parse(\League\CommonMark\ContextInterface $context, \League\CommonMark\Cursor $cursor)
{
$line = $cursor->getLine();
//either a line starting with 'example:' (expected to have a set of links)
//or a line starting with [example] (a single link)
//remove potential markdown formatting (except what we need)
$check = preg_replace('#[^a-z:\\[\\]]#', '', strtolower($line));
if (substr($check, 0, 8) != 'example:' and substr($check, 0, 9) != '[example]') {
return false;
}
$context->addBlock(new ExampleElement($cursor->getLine(), $this->path));
$cursor->advanceBy(strlen($line));
$context->setBlocksParsed(true);
return true;
}
示例12: parse
/**
* @param ContextInterface $context
* @param Cursor $cursor
*
* @return bool
*/
public function parse(ContextInterface $context, Cursor $cursor)
{
$match = RegexHelper::matchAll('/^#{1,6}(?: +|$)/', $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 Header($level, $str));
$context->setBlocksParsed(true);
return true;
}
示例13: parse
/**
* @param ContextInterface $context
* @param Cursor $cursor
*
* @return bool
*/
public function parse(ContextInterface $context, Cursor $cursor)
{
if (!in_array($cursor->getFirstNonSpaceCharacter(), IconBlock::getIconBlockTypes()) || $cursor->getCharacter($cursor->getFirstNonSpacePosition() + 1) !== '>') {
return false;
}
$type = $cursor->getFirstNonSpaceCharacter();
$cursor->advanceToFirstNonSpace();
if ($cursor->peek() === '>') {
$cursor->advanceBy(2);
if ($cursor->getCharacter() === ' ') {
$cursor->advance();
}
}
$context->addBlock(new IconBlock($type));
return true;
}
示例14: parse
/**
* @param ContextInterface $context
* @param Cursor $cursor
*
* @return bool
*/
public function parse(ContextInterface $context, Cursor $cursor)
{
if ($cursor->isIndented() && !$context->getContainer() instanceof ListBlock) {
return false;
}
$tmpCursor = clone $cursor;
$tmpCursor->advanceToFirstNonSpace();
$rest = $tmpCursor->getRemainder();
$data = new ListData();
$data->markerOffset = $cursor->getIndent();
if ($matches = RegexHelper::matchAll('/^[*+-]/', $rest)) {
$data->type = ListBlock::TYPE_UNORDERED;
$data->delimiter = null;
$data->bulletChar = $matches[0][0];
} elseif (($matches = RegexHelper::matchAll('/^(\\d{1,9})([.)])/', $rest)) && (!$context->getContainer() instanceof Paragraph || $matches[1] === '1')) {
$data->type = ListBlock::TYPE_ORDERED;
$data->start = intval($matches[1]);
$data->delimiter = $matches[2];
$data->bulletChar = null;
} else {
return false;
}
$markerLength = strlen($matches[0]);
// Make sure we have spaces after
$nextChar = $tmpCursor->peek($markerLength);
if (!($nextChar === null || $nextChar === "\t" || $nextChar === ' ')) {
return false;
}
// If it interrupts paragraph, make sure first line isn't blank
if ($context->getContainer() instanceof Paragraph && !RegexHelper::matchAt(RegexHelper::REGEX_NON_SPACE, $rest, $markerLength)) {
return false;
}
// We've got a match! Advance offset and calculate padding
$cursor->advanceToFirstNonSpace();
// to start of marker
$cursor->advanceBy($markerLength, true);
// to end of marker
$data->padding = $this->calculateListMarkerPadding($cursor, $markerLength);
// add the list if needed
$container = $context->getContainer();
if (!$container || !$context->getContainer() instanceof ListBlock || !$data->equals($container->getListData())) {
$context->addBlock(new ListBlock($data));
}
// add the list item
$context->addBlock(new ListItem($data));
return true;
}
示例15: testParse
/**
* @param $string
* @param $expected
*
* @dataProvider dataForTestParse
*/
public function testParse($string, $expected)
{
$cursor = new Cursor($string);
// Move to just before the first tilde pair
$first_tilde_pos = mb_strpos($string, '~~', null, 'utf-8');
$cursor->advanceBy($first_tilde_pos);
$inline_context = new InlineParserContext($cursor);
$context_stub = $this->getMock('League\\CommonMark\\ContextInterface');
$parser = new StrikethroughParser();
$parser->parse($context_stub, $inline_context);
$inlines = $inline_context->getInlines();
$this->assertCount(1, $inlines);
$this->assertTrue($inlines->first() instanceof Strikethrough);
/** @var Strikethrough $text */
$text = $inlines->first();
$this->assertEquals($expected, $text->getContent());
}