kuchiki-rs / kuchiki

(朽木) HTML/XML tree manipulation library for Rust
MIT License
470 stars 54 forks source link

Add optional feature "preserve_order" to use IndexMap instead of BTreeMap #83

Closed forbjok closed 2 years ago

forbjok commented 3 years ago

I noticed that when serializing a DOM back to HTML from kuchiki, attribute order changed from the original HTML document. After some investiation, I found out that this is caused by the BTreeMap used to store attributes automatically sorting keys alphabetically.

This pull request adds an optional feature "preserve_order" (inspired by the feature of the same name in serde_json, that does exactly the same thing) that swaps BTreeMap with IndexMap (also used by serde_json), which preserves the order of its keys.

jdm commented 3 years ago

I don't think it's worth making this a build-time feature. Replacing the BTreeMap with IndexMap seems reasonable.

forbjok commented 3 years ago

I don't think it's worth making this a build-time feature. Replacing the BTreeMap with IndexMap seems reasonable.

Changed the commit into directly replacing BTreeMap with IndexMap.

mitsuhiko commented 2 years ago

I think this is a sensible change that should be made. Are there any objections to merging this?

Ygg01 commented 2 years ago

I'm fine merging this.

But would like more votes of confidence.

Ygg01 commented 2 years ago

@SimonSapin thoughts on PR?

Ygg01 commented 2 years ago

Ok, since 3 days passed, and no one responded. I'm going to merge this.