private static function countWords($text)
    {
        // Remove markdown images from text
        $words = trim(preg_replace('/!\[([^\[]+)\]\(([^\)]+)\)/i', ' ', $text));
        // Remove image tags from text
        $words = trim(preg_replace('/<img[^>]*>/i', ' ', $words));
        // Remove picture tags from text (counted already due to mandatory img tag)
        $words = trim(preg_replace('/<picture[^>]*>([\s\S]*?)<\/picture>/i', ' ', $words));
        // Remove code markdown
        $words = trim(preg_replace('/(?<=(?<!`))`[^`\n\r]+`(?=(?!`))|```[\w+]?[^`]*```/i', ' ', $words));
        // Remove code html
        $words = trim(preg_replace('/<code>([\s\S]*?)<\/code>/i', ' ', $words));
        $words = strip_tags($words);
        // Explode on spaces to separate words
        $words = explode(' ', $words);

        return count($words);
    }