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 @@ ...@@ -42,10 +42,7 @@
.then(str => (new DOMParser()).parseFromString(str, "text/html")) .then(str => (new DOMParser()).parseFromString(str, "text/html"))
// Gather all stylesheets from html document // Gather all stylesheets from html document
let stylesheets = Array.from(html.querySelectorAll("link[rel='stylesheet']")); let hrefs = previewer.removeStyles(html);
let hrefs = stylesheets.map((sheet) => {
return sheet.href;
});
// Add a stylesheet url in params // Add a stylesheet url in params
let stylesheet = params && params.get("stylesheet") && decodeURIComponent(params.get("stylesheet")); let stylesheet = params && params.get("stylesheet") && decodeURIComponent(params.get("stylesheet"));
...@@ -74,7 +71,7 @@ ...@@ -74,7 +71,7 @@
.pagedjs_page { .pagedjs_page {
background-color: #fdfdfd; background-color: #fdfdfd;
margin-bottom: 20px; margin: 10px auto;
flex: none; flex: none;
box-shadow: 0 0 0 1px rgba(0, 0,0,0.2); box-shadow: 0 0 0 1px rgba(0, 0,0,0.2);
} }
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
"author": "Fred Chasen", "author": "Fred Chasen",
"license": "MIT", "license": "MIT",
"homepage": "https://pagedmedia.org", "homepage": "https://pagedmedia.org",
"main": "lib/paged.js", "main": "lib/index.js",
"module": "src/index.js", "module": "src/index.js",
"browser": "dist/paged.js", "browser": "dist/paged.js",
"dependencies": { "dependencies": {
......
...@@ -93,16 +93,16 @@ class Previewer { ...@@ -93,16 +93,16 @@ class Previewer {
return template.content; return template.content;
} }
removeStyles() { removeStyles(doc=document) {
// Get all stylesheets // 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) => { let hrefs = stylesheets.map((sheet) => {
sheet.remove(); sheet.remove();
return sheet.href; return sheet.href;
}); });
// Get inline styles // 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) => { inlineStyles.forEach((inlineStyle) => {
let obj = {}; let obj = {};
obj[window.location.href] = inlineStyle.textContent; 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