Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for converting style attributes to HTML attributes #138

Open
yisibl opened this issue Jan 17, 2022 · 5 comments · May be fixed by #139
Open

Support for converting style attributes to HTML attributes #138

yisibl opened this issue Jan 17, 2022 · 5 comments · May be fixed by #139

Comments

@yisibl
Copy link

yisibl commented Jan 17, 2022

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 128 128">
  <path d="M2,2 v6 h6 v-6 h-6 z" style="stroke:#FF0000;stroke-width:0.5;fill:none;"/>
</svg>

To

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 128 128">
  <path d="M2,2 v6 h6 v-6 h-6 z" stroke="#FF0000" stroke-width="0.5" fill="none"/>
</svg>

This is useful for font tools, e.g. googlefonts/picosvg#60

@Stranger6667
Copy link
Owner

Hi! Thank you for reporting! :)

Interesting feature - implementation-wise it should be relatively straightforward:

  • Config flag
  • If enabled, then insert collected styles as attributes

Though the underlying library does not provide a way to attach an XML parser / serializer, therefore I am concerned about the use case you provided would not be supported out of the box. However, implementing such a thing is feasible even without kuchiki-rs as there is a standalone XML parser available for Rust.

@yisibl
Copy link
Author

yisibl commented Mar 4, 2024

Any plans to implement this feature this year?

@Stranger6667
Copy link
Owner

I'd like to have it in css-inline and this year sounds realistic to me :) Non-blocking resolving is at the top of my to-do list, but after that, I'd be able to work on this.

@caseyjhol, as you commented on #139 - are you still interested in moving this forward? I'd be glad to assist in the implementation or provide a more detailed plan.

@Stranger6667
Copy link
Owner

Forgot about the XML part :(

Maybe a better way to solve the task described in the original message would be:

  • A way to configure the underlying parser, currently, we only have HTML via html5ever
  • Add an XML parser that will parse input into the same Document struct
  • Bind different serializers for each parser, the current one is for HTML only.
  • Add a different method on CSSInliner which will look for "style" attributes, parse them, and insert individual styles as separate attributes. Some inline_styles_as_attributes or something better

I think that it also will be much faster & simpler as there is no need for selectors at all, just check the nodes for the style attributes.

@Stranger6667
Copy link
Owner

So, for HTML it would be a different thing that should be integrated into the current inlining process

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants