Commit 60e74d06 authored by Fred Chasen's avatar Fred Chasen

Get inline stylesheet for viewer.html

parent 0c1bac76
Pipeline #78 passed with stage
in 4 minutes and 20 seconds
......@@ -42,10 +42,7 @@
.then(str => (new DOMParser()).parseFromString(str, "text/html"))
// Gather all stylesheets from html document
let stylesheets = Array.from(html.querySelectorAll("link[rel='stylesheet']"));
let hrefs = stylesheets.map((sheet) => {
return sheet.href;
});
let hrefs = previewer.removeStyles(html);
// Add a stylesheet url in params
let stylesheet = params && params.get("stylesheet") && decodeURIComponent(params.get("stylesheet"));
......@@ -74,7 +71,7 @@
.pagedjs_page {
background-color: #fdfdfd;
margin-bottom: 20px;
margin: 10px auto;
flex: none;
box-shadow: 0 0 0 1px rgba(0, 0,0,0.2);
}
......
......@@ -5,7 +5,7 @@
"author": "Fred Chasen",
"license": "MIT",
"homepage": "https://pagedmedia.org",
"main": "lib/paged.js",
"main": "lib/index.js",
"module": "src/index.js",
"browser": "dist/paged.js",
"dependencies": {
......
......@@ -93,16 +93,16 @@ class Previewer {
return template.content;
}
removeStyles() {
removeStyles(doc=document) {
// Get all stylesheets
let stylesheets = Array.from(document.querySelectorAll("link[rel='stylesheet']"));
let stylesheets = Array.from(doc.querySelectorAll("link[rel='stylesheet']"));
let hrefs = stylesheets.map((sheet) => {
sheet.remove();
return sheet.href;
});
// Get inline styles
let inlineStyles = Array.from(document.querySelectorAll("style:not([data-pagedjs-inserted-styles])"));
let inlineStyles = Array.from(doc.querySelectorAll("style:not([data-pagedjs-inserted-styles])"));
inlineStyles.forEach((inlineStyle) => {
let obj = {};
obj[window.location.href] = inlineStyle.textContent;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment