/**
* @param Cursor $cursor
* @param int $markerLength
*
* @return int
*/
private function calculateListMarkerPadding(Cursor $cursor, $markerLength)
{
$start = $cursor->saveState();
$spacesStartCol = $cursor->getColumn();
$spacesStartOffset = $cursor->getPosition();
do {
$cursor->advanceBy(1, true);
$nextChar = $cursor->getCharacter();
} while ($cursor->getColumn() - $spacesStartCol < 5 && ($nextChar === ' ' || $nextChar === "\t"));
$blankItem = $cursor->peek() === null;
$spacesAfterMarker = $cursor->getColumn() - $spacesStartCol;
if ($spacesAfterMarker >= 5 || $spacesAfterMarker < 1 || $blankItem) {
$cursor->restoreState($start);
if ($cursor->peek() === ' ') {
$cursor->advanceBy(1, true);
}
return $markerLength + 1;
} else {
return $markerLength + $spacesAfterMarker;
}
}