mirror of
https://github.com/NohamR/pdfy.git
synced 2026-10-10 18:29:55 +00:00
Hightlight js + CSP fix
This commit is contained in:
17
index.js
17
index.js
@@ -36,7 +36,8 @@ async function discoverExtensionId(browser) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function extractArticle(page, readabilityPath) {
|
async function extractArticle(page, readabilityPath) {
|
||||||
await page.addScriptTag({ path: readabilityPath });
|
const readabilitySource = fs.readFileSync(readabilityPath, "utf-8");
|
||||||
|
await page.evaluate(readabilitySource);
|
||||||
const article = await page.evaluate(() => {
|
const article = await page.evaluate(() => {
|
||||||
const doc = document.cloneNode(true);
|
const doc = document.cloneNode(true);
|
||||||
const reader = new Readability(doc);
|
const reader = new Readability(doc);
|
||||||
@@ -202,8 +203,12 @@ async function main() {
|
|||||||
const contentHtml = await extractRenderedContent(readerPage, `chrome-extension://${extId}/data/reader/`);
|
const contentHtml = await extractRenderedContent(readerPage, `chrome-extension://${extId}/data/reader/`);
|
||||||
await readerPage.close();
|
await readerPage.close();
|
||||||
|
|
||||||
|
const highlightCss = '<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.1/styles/default.min.css">';
|
||||||
|
const highlightJs = '<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.1/highlight.min.js"><\/script><script>hljs.highlightAll();<\/script>';
|
||||||
|
const enhancedHtml = contentHtml.replace("</head>", `${highlightCss}${highlightJs}</head>`);
|
||||||
|
|
||||||
const pdfPage = await browser.newPage();
|
const pdfPage = await browser.newPage();
|
||||||
await pdfPage.setContent(contentHtml, { waitUntil: "networkidle0" });
|
await pdfPage.setContent(enhancedHtml, { waitUntil: "networkidle0" });
|
||||||
|
|
||||||
console.log(`Generating PDF: ${outputFile}`);
|
console.log(`Generating PDF: ${outputFile}`);
|
||||||
await pdfPage.pdf({
|
await pdfPage.pdf({
|
||||||
@@ -211,10 +216,10 @@ async function main() {
|
|||||||
format: "A4",
|
format: "A4",
|
||||||
printBackground: true,
|
printBackground: true,
|
||||||
margin: {
|
margin: {
|
||||||
top: "15mm",
|
top: "10mm",
|
||||||
bottom: "15mm",
|
bottom: "10mm",
|
||||||
left: "15mm",
|
left: "0mm",
|
||||||
right: "15mm",
|
right: "0mm",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user