0; if (! $isList) { return false; } $offset = strlen($m[0]); $normalizedMarker = preg_replace('/\d+/', 'd', $m[1]); if ( // validate if next line can be considered part of a list for enumerated lists $normalizedMarker !== $m[1] && $nextLine !== null && trim($nextLine) !== '' && ! $this->isBlockLine($nextLine, $offset) && ! $this->isListLine($nextLine, $normalizedMarker) ) { return false; } if ($listMarker !== null) { $isList = $normalizedMarker === $listMarker; } if ($isList) { $listOffset = $offset; $listMarker = $normalizedMarker; } return $isList; } /** * Is this line "indented"? * * A blank line also counts as a "block" line, as it * may be the empty line between, for example, a * ".. note::" directive and the indented content on the * next lines. * * @param int $minIndent can be used to require a specific level of * indentation for non-blank lines (number of spaces) */ public function isBlockLine(string $line, int $minIndent = 1): bool { return (trim($line) === '' || $this->isIndented($line, $minIndent)) && ! $this->isComment($line); } public function isComment(string $line): bool { return preg_match('/^\.\.(?: [^_]((?:(?!::).)*))?$/mUsi', $line) > 0; } public function isDirective(string $line): bool { return preg_match('/^\.\. (\|(.+)\| |)([^\s]+)::( (.*)|)$/mUsi', $line) > 0; } /** * Check if line is an indented one. * * This does *not* include blank lines, use {@see isBlockLine()} to check * for blank or indented lines. * * @param int $minIndent can be used to require a specific level of indentation (number of spaces) */ public function isIndented(string $line, int $minIndent = 1): bool { return strpos($line, str_repeat(' ', $minIndent)) === 0; } /** * Checks if the current line can be considered part of the definition list. * * Either the current line, or the next line must be indented to be considered * definition. * * @see https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#definition-lists */ public function isDefinitionListEnded(string $line, string $nextLine): bool { if (trim($line) === '') { return false; } if ($this->isIndented($line)) { return false; } return ! $this->isIndented($nextLine); } }