public function handleRemainingContents(ContextInterface $context, Cursor $cursor) { /** @var FencedCode $container */ $container = $context->getContainer(); // check for closing code fence if ($cursor->getIndent() <= 3 && $cursor->getFirstNonSpaceCharacter() === $container->getChar()) { $match = RegexHelper::matchAll('/^(?:`{3,}|~{3,})(?= *$)/', $cursor->getLine(), $cursor->getFirstNonSpacePosition()); if (strlen($match[0]) >= $container->getLength()) { // don't add closing fence to container; instead, close it: $this->setLength(-1); // -1 means we've passed closer return; } } $context->getTip()->addLine($cursor->getRemainder()); }