Comments (9)
Yes exactly. And yes, it will be problematic for a number of areas, such as Floki.raw_html
and Floki.text
needing to become map aware (which shouldn't be a massive lift). I'm sure there are other implications as well, but I think it's essential going forward to test HTML output without relying on attribute ordering.
from floki.
Correct me if I'm misunderstanding your proposal, but parsing attributes into a map would lose data (the attribute ordering).
The loss of this data might manifest in ways such as the output of rendering parsed HTML being different than the originally parsed HTML. Is the benefit of equality matching AST really worth losing potentially useful data in the process?
In regards to changes to the order of rendered attributes in Phoenix or LiveView, shouldn't attributes be rendered in a consistent fashion to avoid continuously altering the produced HTML (helping cacheability, etc)?
Confirm, this would lose attribute ordering, but if it's an option would be opt-in. HTML wise, I can say that the order of attributes rarely (if ever?) matters. They can technically be duped as well, but are ignored by browser engines afaik.
As far as caching, I'm not convinced caching HTML fragments is really desirable, and we have dynamic attribute generation in LiveView, so we'd need to explicitly sort attributes every time, which wouldn't be ideal.
from floki.
@chrismccord So the idea is to add an option to Floki.parse_document/2
and Floki.parse_fragment!/2
, right?
I think this is tough because it would require the change of some functions, but I think it's possible, and it's a good addition!
PS: I think we will not have this problem once we implement #457, but that would be a bigger change. cc @wojtekmach
from floki.
Correct me if I'm misunderstanding your proposal, but parsing attributes into a map would lose data (the attribute ordering).
The loss of this data might manifest in ways such as the output of rendering parsed HTML being different than the originally parsed HTML. Is the benefit of equality matching AST really worth losing potentially useful data in the process?
In regards to changes to the order of rendered attributes in Phoenix or LiveView, shouldn't attributes be rendered in a consistent fashion to avoid continuously altering the produced HTML (helping cacheability, etc)?
from floki.
@bennelsonweiss if you want to do some measurements it could be helpful. The LiveView heex engine could maintain a user defined order + sorted order of dynamic attributes (say alphabetically), but I would need to know the cost. We use a lot of dynamic attributes, like in the <.form>
helper and all over the place really, so sorting would be happening for quite a few tags in each template in a standard app I'd guess. Maybe it's negligible, but one of the issues even with deterministically sorted attrs is that if I want to test a given attribute exists in a node in the document as part of a match, I still need to express that with the entire attribute. #457 solves this kind of stuff in a really nice way tho, so maybe none of this matters if #457 lands.
from floki.
Opt-in seems good- I could see it causing some confusion if it was the default behavior but if somebody needs to turn it on then hopefully they'll understand the implications.
That said, if there is some alternate solution that provides the testing behavior you want without changing the format of Floki - provided by #457 or through some other helper / dsl - I could see that being even better.
from floki.
@chrismccord I implemented the bases for this feature in #467. Please let me know what you think.
After merging this, I should implement the feature in https://github.com/rusterlium/html5ever_elixir
cc @josevalim
from floki.
To clarify, the "issue" is that Phoenix generates HTML attributes in random order, which means assertions on Phoenix apps want to be order independent too. :)
from floki.
This feature has landed on main - you can pass the :attributes_as_maps
option to parse_document/2
and parse_fragment/2
. I should release a new version soon.
Thanks everyone! :)
from floki.
Related Issues (20)
- Unhandled error for Floki.parse_fragment/2 HOT 1
- CDATA inside a title tag is not handled in Mochiweb parser
- Is there a way to replace paragraph tags by newlines in Floki.text()? HOT 1
- Proposal: Add Floki.Doc HOT 10
- Drop support for Elixir 1.11
- Floki is extremely noisy in logs
- Support for :has pseudo selector
- Error after upgrading to 0.35.0 HOT 6
- Buttons in Header Section Lacks Transition!!
- Floki attribute example is ambiguous
- Proposal: optimized find for simple cases HOT 6
- Is it possible to get line/column number of a tag? HOT 4
- Unexpected order using `find` with comma separated selectors in v0.35.3 HOT 2
- nth-child selector not working as expected HOT 7
- Floki.raw_html/2 no longer respects `config :floki, :encode_raw_html, false` HOT 1
- Add functionality to escape values in selectors
- Issue with an archive uploaded to hex HOT 3
- Empty tag attributes are not parsed correctly HOT 1
- issues with fetching floki as dependeny
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from floki.