-
Notifications
You must be signed in to change notification settings - Fork 8
fix: Fix CSS rules captured in Safari #86
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,6 +68,18 @@ function getCssRuleString(rule: CSSRule): string { | |
| // ignore | ||
| } | ||
| } | ||
|
|
||
| return validateStringifiedCssRule(cssStringified); | ||
| } | ||
|
|
||
| export function validateStringifiedCssRule(cssStringified: string): string { | ||
| // Safari does not escape selectors with : properly | ||
| if (cssStringified.indexOf(':') > -1) { | ||
| // Replace e.g. [aa:bb] with [aa\\:bb] | ||
| const regex = /(\[(?:[\w-]+)[^\\])(:(?:[\w-]+)\])/gm; | ||
| return cssStringified.replace(regex, '$1\\$2'); | ||
| } | ||
|
|
||
| return cssStringified; | ||
| } | ||
|
|
||
|
|
@@ -78,7 +90,7 @@ function isCSSImportRule(rule: CSSRule): rule is CSSImportRule { | |
| function stringifyStyleSheet(sheet: CSSStyleSheet): string { | ||
| return sheet.cssRules | ||
| ? Array.from(sheet.cssRules) | ||
| .map((rule) => rule.cssText || '') | ||
| .map((rule) => rule.cssText ? validateStringifiedCssRule(rule.cssText) : '') | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should work now for inline css
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice, could you verify this with an actual example app?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mydea Tested this out and it seems to work
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice, feel free to merge then! |
||
| .join('') | ||
| : ''; | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.