当前位置: 首页>>代码示例>>PHP>>正文


PHP CommonMark\Cursor类代码示例

本文整理汇总了PHP中League\CommonMark\Cursor的典型用法代码示例。如果您正苦于以下问题:PHP Cursor类的具体用法?PHP Cursor怎么用?PHP Cursor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Cursor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: parse

 public function parse(ContextInterface $context, Cursor $cursor)
 {
     $inlineParserContext = new InlineParserContext($cursor);
     while (($character = $cursor->getCharacter()) !== null) {
         if ($matchingParsers = $this->environment->getInlineParsersForCharacter($character)) {
             foreach ($matchingParsers as $parser) {
                 if ($parser->parse($context, $inlineParserContext)) {
                     continue 2;
                 }
             }
         }
         // We reach here if none of the parsers can handle the input
         // Attempt to match multiple non-special characters at once
         $text = $cursor->match($this->environment->getInlineParserCharacterRegex());
         // This might fail if we're currently at a special character which wasn't parsed; if so, just add that character
         if ($text === null) {
             $cursor->advance();
             $text = $character;
         }
         $lastInline = $inlineParserContext->getInlines()->last();
         if ($lastInline instanceof Text && !isset($lastInline->data['delim'])) {
             $lastInline->append($text);
         } else {
             $inlineParserContext->getInlines()->add(new Text($text));
         }
     }
     foreach ($this->environment->getInlineProcessors() as $inlineProcessor) {
         $inlineProcessor->processInlines($inlineParserContext->getInlines(), $inlineParserContext->getDelimiterStack());
     }
     return $inlineParserContext->getInlines();
 }
开发者ID:R3alflash,项目名称:BFAdminCP,代码行数:31,代码来源:InlineParserEngine.php

示例2: parse

 public function parse(ContextInterface $context, Cursor $cursor)
 {
     $document = $context->getDocument();
     $tip = $context->getTip();
     if (!$document->getLastChild() instanceof AttributesDocument) {
         $attributesDocument = new AttributesDocument();
         foreach ($document->getChildren() as $child) {
             $document->removeChild($child);
             $attributesDocument->addChild($child);
         }
         $document->addChild($attributesDocument);
         if ($tip instanceof Document) {
             $context->setTip($attributesDocument);
         }
     }
     $state = $cursor->saveState();
     $attributes = AttributesUtils::parse($cursor);
     if (empty($attributes)) {
         return false;
     }
     if (null !== $cursor->getFirstNonSpaceCharacter()) {
         $cursor->restoreState($state);
         return false;
     }
     $prepend = $tip instanceof Document || !$tip->getParent() instanceof Document && $context->getBlockCloser()->areAllClosed();
     $context->addBlock(new Attributes($attributes, $prepend ? Attributes::PREPEND : Attributes::APPEND));
     $context->setBlocksParsed(true);
     return true;
 }
开发者ID:unicorn-fail,项目名称:commonmark.unicorn.fail,代码行数:29,代码来源:AttributesBlockParser.php

示例3: parseLinkTitle

 /**
  * Attempt to parse link title (sans quotes)
  *
  * @param Cursor $cursor
  *
  * @return null|string The string, or null if no match
  */
 public static function parseLinkTitle(Cursor $cursor)
 {
     if ($title = $cursor->match(RegexHelper::getInstance()->getLinkTitleRegex())) {
         // Chop off quotes from title and unescape
         return RegexHelper::unescape(substr($title, 1, strlen($title) - 2));
     }
 }
开发者ID:colinodell,项目名称:commonmark-php,代码行数:14,代码来源:LinkParserHelper.php

示例4: 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;
 }
开发者ID:alvarobfdev,项目名称:LaravelCore,代码行数:40,代码来源:ListParser.php

示例5: parse

 /**
  * @param ContextInterface $context
  * @param Cursor $cursor
  *
  * @return bool
  */
 public function parse(ContextInterface $context, Cursor $cursor)
 {
     if ($cursor->getIndent() < IndentedCodeParser::CODE_INDENT_LEVEL) {
         return false;
     }
     $context->setBlocksParsed(true);
     return true;
 }
开发者ID:alvarobfdev,项目名称:LaravelCore,代码行数:14,代码来源:LazyParagraphParser.php

示例6: 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;
 }
开发者ID:alvarobfdev,项目名称:applog,代码行数:14,代码来源:LazyParagraphParser.php

示例7: handleRemainingContents

 /**
  * @param ContextInterface $context
  * @param Cursor           $cursor
  */
 public function handleRemainingContents(ContextInterface $context, Cursor $cursor)
 {
     if ($cursor->isBlank()) {
         return;
     }
     $context->addBlock(new Paragraph());
     $cursor->advanceToFirstNonSpace();
     $context->getTip()->addLine($cursor->getRemainder());
 }
开发者ID:austinvernsonger,项目名称:markua,代码行数:13,代码来源:Aside.php

示例8: matchesNextLine

 public function matchesNextLine(Cursor $cursor)
 {
     if ($cursor->isBlank()) {
         $this->setLastLineBlank(true);
     } else {
         $this->setLastLineBlank(false);
     }
     return false;
 }
开发者ID:webuni,项目名称:commonmark-attributes-extension,代码行数:9,代码来源:Attributes.php

示例9: parse

 /**
  * @param ContextInterface $context
  * @param Cursor $cursor
  *
  * @return bool
  */
 public function parse(ContextInterface $context, Cursor $cursor)
 {
     $match = RegexHelper::matchAt(RegexHelper::getInstance()->getHtmlBlockOpenRegex(), $cursor->getLine(), $cursor->getFirstNonSpacePosition());
     if ($match === null) {
         return false;
     }
     $context->addBlock(new HtmlBlock());
     $context->setBlocksParsed(true);
     return true;
 }
开发者ID:alvarobfdev,项目名称:LaravelCore,代码行数:16,代码来源:HtmlBlockParser.php

示例10: parse

 /**
  * @param ContextInterface $context
  * @param Cursor $cursor
  *
  * @return ArrayCollection
  */
 public function parse(ContextInterface $context, Cursor $cursor)
 {
     $inlineParserContext = new InlineParserContext($cursor);
     while (($character = $cursor->getCharacter()) !== null) {
         if (!$this->parseCharacter($character, $context, $inlineParserContext)) {
             $this->addPlainText($character, $inlineParserContext);
         }
     }
     $this->processInlines($inlineParserContext);
     return $inlineParserContext->getInlines();
 }
开发者ID:alvarobfdev,项目名称:applog,代码行数:17,代码来源:InlineParserEngine.php

示例11: parse

 /**
  * @param ContextInterface $context
  * @param Cursor $cursor
  *
  * @return bool
  */
 public function parse(ContextInterface $context, Cursor $cursor)
 {
     $previousState = $cursor->saveState();
     $indent = $cursor->advanceToFirstNonSpace();
     $fence = $cursor->match('/^`{3,}(?!.*`)|^~{3,}(?!.*~)/');
     if (!$fence) {
         $cursor->restoreState($previousState);
         return false;
     }
     // fenced code block
     $fenceLength = strlen($fence);
     $context->addBlock(new FencedCode($fenceLength, $fence[0], $indent));
     return true;
 }
开发者ID:R3alflash,项目名称:BFAdminCP,代码行数:20,代码来源:FencedCodeParser.php

示例12: 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->advanceToEnd();
     $context->addBlock(new ThematicBreak());
     $context->setBlocksParsed(true);
     return true;
 }
开发者ID:colinodell,项目名称:commonmark-php,代码行数:21,代码来源:ThematicBreakParser.php

示例13: 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;
 }
开发者ID:ayiemba,项目名称:Quickstarts,代码行数:21,代码来源:ExampleParser.php

示例14: 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;
 }
开发者ID:LyricFinancial,项目名称:integration-guides,代码行数:21,代码来源:IndentedCodeParser.php

示例15: parse

 public function parse(ContextInterface $context, Cursor $cursor)
 {
     $state = $cursor->saveState();
     $attributes = AttributesUtils::parse($cursor);
     if (empty($attributes)) {
         return false;
     }
     if (null !== $cursor->getFirstNonSpaceCharacter()) {
         $cursor->restoreState($state);
         return false;
     }
     $context->addBlock(new Attributes($attributes));
     $context->setBlocksParsed(true);
     return true;
 }
开发者ID:webuni,项目名称:commonmark-attributes-extension,代码行数:15,代码来源:AttributesBlockParser.php


注:本文中的League\CommonMark\Cursor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。