rstacruz/sparkup

Stop sorting attributes

Opened this issue · 1 comments

When I do:

link[rel=import][href=../foo/bar.html]

It expands to

<link href="../foo/bar.html" rel="import">

While that's normally fine, it would be great if sparkup kept the order of the attributes as they are written instead of sorting them. Looking at the Python code, it's not immediately obvious where the order of attributes would be controlled though.

Maybe have an option that would respect the attribute order?

Without deeper knowledge, I can only take a guess: The attributes are stored in a dictionary, and dictionaries in python are unordered. So when you get the attributes back out, it will always give them in alphabetical order.

You could try opening sparkup.py and change the line

self.attributes = {}

into

self.attributes = OrderedDict()

with

from collections import OrderedDict

at the top of the file.

That might help with populating the object, but I don't see where that attributes dictionary is being consumed.