prettify(): order of attributes inside meta elements
Bug #1812422 reported by
Greg Burek
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Beautiful Soup |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
prettify() seems to sort the attributes alphabetically.
This causes problems in MadCap Flare as it expects <meta name="..." content="..." />, not <meta content="..." description="" />.
Also, it is probably easier for humans to read when "name" attribute is the first one.
prettify() should probably have special handling of meta elements to ensure this order.
BS4 version: 4.6.3
Changed in beautifulsoup: | |
status: | Confirmed → Fix Released |
To post a comment you must log in.
Thanks for filing this ticket.
I'm reluctant to answer bug reports with "you shouldn't be doing that", but I think there's a chunk of that here. The job of prettify() is to make the structure of a parsed document obvious to the human eye. It's not intended to produce a document that means the same thing as the original, and I don't recommend using it as the input into another program. The discussion of bug #1697296 shows a case where there's a significant difference between what the human eye expects to see and what's actually going on in a document.
But even if you stop using prettify(), the attributes are going to be output in a particular order, and it probably won't be the order that MadCap Flare can handle as input.
I agree that (name, content) is easier to read than (content, name), but that's a subjective opinion about one pair of attributes in one tag, and there's no necessary connection to what a given product can parse. In this particular case, MadCap Flare can only process the "more readable" order, but maybe some other product can only process the "less readable" order.
So this is a general problem, and a full solution would require giving the programmer the ability to define a sort order for attributes within a given tag. The Formatter class would be the place to put this.