本文整理汇总了PHP中League\CommonMark\Cursor::isIndented方法的典型用法代码示例。如果您正苦于以下问题:PHP Cursor::isIndented方法的具体用法?PHP Cursor::isIndented怎么用?PHP Cursor::isIndented使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类League\CommonMark\Cursor
的用法示例。
在下文中一共展示了Cursor::isIndented方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parse
/**
* @param ContextInterface $context
* @param Cursor $cursor
*
* @return bool
*/
public function parse(ContextInterface $context, Cursor $cursor)
{
if (!$cursor->isIndented()) {
return false;
}
$context->setBlocksParsed(true);
return true;
}
示例2: matchesNextLine
public function matchesNextLine(Cursor $cursor)
{
if (!$cursor->isIndented() && $cursor->getFirstNonSpaceCharacter() === '>') {
$cursor->advanceToFirstNonSpace();
$cursor->advance();
$cursor->advanceBySpaceOrTab();
return true;
}
return false;
}
示例3: 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;
}
示例4: 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()->getHtmlBlockOpenRegex(), $cursor->getLine(), $cursor->getFirstNonSpacePosition());
if ($match === null) {
return false;
}
$context->addBlock(new HtmlBlock());
$context->setBlocksParsed(true);
return true;
}
示例5: parse
/**
* @param ContextInterface $context
* @param Cursor $cursor
*
* @return bool
*/
public function parse(ContextInterface $context, Cursor $cursor)
{
if ($cursor->isIndented()) {
return false;
}
if ($cursor->getFirstNonSpaceCharacter() !== '>') {
return false;
}
$cursor->advanceToFirstNonSpace();
$cursor->advance();
$cursor->advanceBySpaceOrTab();
$context->addBlock(new BlockQuote());
return true;
}
示例6: 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;
}
示例7: 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;
}
示例8: parse
/**
* @param ContextInterface $context
* @param Cursor $cursor
*
* @return bool
*/
public function parse(ContextInterface $context, Cursor $cursor)
{
if ($cursor->isIndented()) {
return false;
}
$previousState = $cursor->saveState();
$cursor->advanceToFirstNonSpace();
$fence = $cursor->match('/^\\[TOC\\]/');
if (is_null($fence)) {
$cursor->restoreState($previousState);
return false;
}
$context->addBlock(new TableOfContents());
return true;
}
示例9: 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;
}
示例10: parse
/**
* @param ContextInterface $context
* @param Cursor $cursor
*
* @return bool
*/
public function parse(ContextInterface $context, Cursor $cursor)
{
if ($cursor->isIndented()) {
return false;
}
if (!$context->getContainer() instanceof Paragraph) {
return false;
}
$match = RegexHelper::matchAll('/^(?:=+|-+)[ \\t]*$/', $cursor->getLine(), $cursor->getFirstNonSpacePosition());
if ($match === null) {
return false;
}
$level = $match[0][0] === '=' ? 1 : 2;
$strings = $context->getContainer()->getStrings();
$context->replaceContainerBlock(new Heading($level, $strings));
return true;
}
示例11: parse
/**
* @param ContextInterface $context
* @param Cursor $cursor
*
* @return bool
*/
public function parse(ContextInterface $context, Cursor $cursor)
{
if ($cursor->isIndented()) {
return false;
}
$previousState = $cursor->saveState();
$indent = $cursor->advanceToFirstNonSpace();
$fence = $cursor->match('/^`{3,}(?!.*`)|^~{3,}(?!.*~)/');
if (is_null($fence)) {
$cursor->restoreState($previousState);
return false;
}
// fenced code block
$fenceLength = strlen($fence);
$context->addBlock(new FencedCode($fenceLength, $fence[0], $indent));
return true;
}
示例12: parse
/**
* @param ContextInterface $context
* @param Cursor $cursor
*
* @return bool
*/
public function parse(ContextInterface $context, Cursor $cursor)
{
if ($cursor->isIndented()) {
return false;
}
$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 Heading($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 ($cursor->isIndented()) {
return false;
}
if ($cursor->getFirstNonSpaceCharacter() !== '<') {
return false;
}
$savedState = $cursor->saveState();
$cursor->advanceToFirstNonSpace();
$line = $cursor->getRemainder();
for ($blockType = 1; $blockType <= 7; $blockType++) {
$match = RegexHelper::matchAt(RegexHelper::getHtmlBlockOpenRegex($blockType), $line);
if ($match !== null && ($blockType < 7 || !$context->getContainer() instanceof Paragraph)) {
$cursor->restoreState($savedState);
$context->addBlock(new HtmlBlock($blockType));
$context->setBlocksParsed(true);
return true;
}
}
$cursor->restoreState($savedState);
return false;
}
示例14: parse
/**
* @param ContextInterface $context
* @param Cursor $cursor
*
* @return bool
*/
public function parse(ContextInterface $context, Cursor $cursor)
{
$tmpCursor = clone $cursor;
$indent = $tmpCursor->advanceToFirstNonSpace();
$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{1,9})([.)])( +|$)/', $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);
if ($cursor->isIndented() && !$context->getContainer() instanceof ListBlock) {
return false;
}
$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;
}