protected function whitespaceInInlineElements($contents, PlaceholderContainer $placeholderContainer)
    {
        $elementsRegex = $this->getInlineElementsRegex();

        return preg_replace_callback(
            '/
                (
                    <('.$elementsRegex.')   # Match an inline element
                    (?:(?!<\/\2>).*)        # Match everything except its end tag
                    <\/\2>                  # Match the end tag
                    \s+
                )
                <('.$elementsRegex.')       # Match starting tag
            /xis',
            function ($match) use ($placeholderContainer) {
                return $this->replaceWhitespacesInInlineElements($match[1], $placeholderContainer).'<'.$match[3];
            }, $contents);
    }