From 81ebd01b3a790def106fb4ff7a363b379db8222b Mon Sep 17 00:00:00 2001 From: adrianmarinwork Date: Thu, 8 Dec 2022 19:48:16 +0100 Subject: [PATCH 1/2] easier fix for issue #2 - fixes lists, texts and codeblocks --- src/content_script.js | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/content_script.js b/src/content_script.js index 045ef49..388d3fe 100644 --- a/src/content_script.js +++ b/src/content_script.js @@ -70,22 +70,12 @@ function downloadThread({ as = Format.PNG } = {}) { const pixelRatio = window.devicePixelRatio; const minRatio = as === Format.PDF ? 2 : 2.5; window.devicePixelRatio = Math.max(pixelRatio, minRatio); + + //Fix to the text shifting down when generating the canvas + document.body.style.lineHeight = '0.5'; + html2canvas(elements.thread, { letterRendering: true, - onclone: function (cloneDoc) { - //Make small fix of position to all the text containers - let listOfTexts = cloneDoc.getElementsByClassName("min-h-[20px]"); - Array.from(listOfTexts).forEach((text) => { - text.style.position = "relative"; - text.style.top = "-8px"; - }); - - //Delete copy button from code blocks - let listOfCopyBtns = cloneDoc.querySelectorAll("button.flex"); - Array.from(listOfCopyBtns).forEach( - (btn) => (btn.style.visibility = "hidden") - ); - }, }).then(async function (canvas) { elements.restoreLocation(); window.devicePixelRatio = pixelRatio; From 9619589f3f1d9c84d2854781ed78c03eb4c15fba Mon Sep 17 00:00:00 2001 From: adrianmarinwork Date: Thu, 8 Dec 2022 20:22:47 +0100 Subject: [PATCH 2/2] Restored lineHeight of body as requested in PR #13 --- src/content_script.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/content_script.js b/src/content_script.js index 388d3fe..77fe171 100644 --- a/src/content_script.js +++ b/src/content_script.js @@ -78,6 +78,10 @@ function downloadThread({ as = Format.PNG } = {}) { letterRendering: true, }).then(async function (canvas) { elements.restoreLocation(); + + //Restore style + document.body.style.lineHeight = null; + window.devicePixelRatio = pixelRatio; const imgData = canvas.toDataURL("image/png"); requestAnimationFrame(() => {