Downcase tags and attribute names in Floki?

Parsing HTML pages with Floki, sometimes I get headaches because attributes are in ALL CAPS, so selectors fail, or I must do something like Floki.find(tree, "meta[name=\"ROBOTS\"]")

I understand case insensitive selectors are not yet a feature, but I am wondering can Floki convert all tags and attribute to lower case? I think I can write a reduce function to do this myself, but maybe Floki already has this somewhere that I cannot see?

More important question: would this break a page? For example, would CSS or Javascript break if you change <TABLE ID="SOMETHING"> to <table id="something">. Even though we are not caring about CSS and JS when parsing the HTML, I don’t actually know how capitalization affects rendering or Javascript.

Thank you for any inputs!

1 Like

Not per the spec and IMO you should be quite safe for your own case because you don’t utilize some 20-year old buggy HTML parsers. So you can easily just downcase the markup.

I’d say just do Floki.find(tree, "meta") and use Elixir code to downcase the desired attribute key (or value) and then look for it.