I think it would make sense to pass the current indent level in the arguments. Calling 'ancestors' for every element seems to be unnecessarily expensive.