Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

clipper: inline styles if cssRules.length > 0 Signed-off-by: 01zulfi <[email protected]>

01zulfi5e5930e9e8bb
diff --git a/packages/clipper/src/styles.ts b/packages/clipper/src/styles.ts
index 747a34725..20ae8bb58 100644
--- a/packages/clipper/src/styles.ts
+++ b/packages/clipper/src/styles.ts
@@ -97,8 +97,26 @@ export async function addStylesToHead(
if (styleNode) {
head.appendChild(styleNode);
}
- } else if (node instanceof HTMLStyleElement) {
+ continue;
+ }
+
+ if (sheet.cssRules.length) {
+ const styleNode = rulesToStyleNode(sheet.cssRules);
+ head.appendChild(styleNode);
+ continue;
+ }
+
+ if (node instanceof HTMLStyleElement) {
head.appendChild(node.cloneNode(true));
}
}
}
+
+function rulesToStyleNode(cssRules: CSSRuleList) {
+ const cssText = Array.from(cssRules)
+ .map((r) => r.cssText)
+ .reduce((acc, text) => acc + text);
+ const style = document.createElement("style");
+ style.innerHTML = cssText;
+ return style;
+}