-
-
Notifications
You must be signed in to change notification settings - Fork 17
Fix/fail parse base64 in style attr #12
Fix/fail parse base64 in style attr #12
Conversation
…dd them back in after the style string has parsed into an object
This will work for As this whole string parsing only happens if
|
@wooorm I'm curious why aren't you using |
Because it’s has a big footprint in file-size: it contains a full blown CSS parser! |
It seems like the perfect tool for the job. I just tried it and it works flawlessly. I understand the footprint portion, but it would seem that if you need to parse CSS, a full parser is needed.
Alternatively, I could add a case for
Yeah, that is the case.
I can definitely traverse the tree and convert style strings into objects, but that would be solving just my use case. Wouldn't it be better if we can at least consider the use cases where this fails for people with no control over the tree? |
But that’s not a viable options in the browser
Doesn’t account for comments
In that case you can write
We could create a utility that does it, so other people can benefit from this? |
Do you think there is value in trying to list out the edge cases and try to patch the parser in the same way this PR is doing or should we call it a day and close this one? |
I don’t think it’s possible to fix all the potential problems like this.
From the top of my head, a project like that could look as follows: var parse = require('css-declarations').parse;
var visit = require('unist-util-visit');
module.exports = transform;
function transform(tree) {
visit(tree, 'element', visitor);
}
function visitor(node) {
var props = node.properties;
if (typeof props.style === 'string') {
props.style = parse(props.style);
}
} |
Closing this in favor of transforming string style attributes before passing the tree to hast-to-hyperscript to keep this library slim. |
Fixes issue #11